X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.cms.e4.rap%2Fsrc%2Forg%2Fargeo%2Fcms%2Fe4%2Frap%2FCmsE4EntryPointFactory.java;h=a5a32348e43896837bd0908730af7a4aa4fc0dba;hb=21171ced2bce875e64db47d95bf4a00a0e141a9a;hp=05eb7c3d03fb64fddf4366ea186ee67ab42cf077;hpb=06ec86e90b88db589d8928b80cbc236f1ea3b230;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4EntryPointFactory.java b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4EntryPointFactory.java index 05eb7c3d0..a5a32348e 100644 --- a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4EntryPointFactory.java +++ b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4EntryPointFactory.java @@ -3,51 +3,68 @@ package org.argeo.cms.e4.rap; import java.security.PrivilegedAction; import javax.security.auth.Subject; -import javax.security.auth.login.LoginContext; -import javax.security.auth.login.LoginException; -import org.argeo.cms.CmsException; -import org.argeo.cms.auth.CurrentUser; -import org.argeo.cms.ui.CmsImageManager; -import org.argeo.cms.ui.CmsView; -import org.argeo.cms.ui.UxContext; -import org.argeo.cms.util.SimpleUxContext; -import org.argeo.cms.widgets.auth.CmsLoginShell; -import org.argeo.node.NodeConstants; import org.eclipse.rap.e4.E4ApplicationConfig; import org.eclipse.rap.e4.E4EntryPointFactory; +import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.application.EntryPoint; -import org.eclipse.swt.widgets.Display; +import org.eclipse.rap.rwt.client.service.JavaScriptExecutor; public class CmsE4EntryPointFactory extends E4EntryPointFactory { + public final static String DEFAULT_LIFECYCLE_URI = "bundleclass://org.argeo.cms.e4.rap/org.argeo.cms.e4.rap.CmsLoginLifecycle"; public CmsE4EntryPointFactory(E4ApplicationConfig config) { super(config); } + public CmsE4EntryPointFactory(String e4Xmi, String lifeCycleUri) { + super(defaultConfig(e4Xmi, lifeCycleUri)); + } + + public CmsE4EntryPointFactory(String e4Xmi) { + this(e4Xmi, DEFAULT_LIFECYCLE_URI); + } + + public static E4ApplicationConfig defaultConfig(String e4Xmi, String lifeCycleUri) { + E4ApplicationConfig config = new E4ApplicationConfig(e4Xmi, lifeCycleUri, null, null, false, true, true); + return config; + } + @Override public EntryPoint create() { - // Subject subject = new Subject(); EntryPoint ep = createEntryPoint(); EntryPoint authEp = new EntryPoint() { @Override public int createUI() { Subject subject = new Subject(); -// boolean success = login(subject); -// if (success) - return Subject.doAs(subject, new PrivilegedAction() { - - @Override - public Integer run() { -// RWT.setLocale(Locale.FRENCH); - System.out.println("createUI"); - return ep.createUI(); - } - - }); -// else -// return 1; + return Subject.doAs(subject, new PrivilegedAction() { + + @Override + public Integer run() { + // SPNEGO + // HttpServletRequest request = RWT.getRequest(); + // String authorization = request.getHeader(HEADER_AUTHORIZATION); + // if (authorization == null || !authorization.startsWith("Negotiate")) { + // HttpServletResponse response = RWT.getResponse(); + // response.setStatus(401); + // response.setHeader(HEADER_WWW_AUTHENTICATE, "Negotiate"); + // response.setDateHeader("Date", System.currentTimeMillis()); + // response.setDateHeader("Expires", System.currentTimeMillis() + (24 * 60 * 60 + // * 1000)); + // response.setHeader("Accept-Ranges", "bytes"); + // response.setHeader("Connection", "Keep-Alive"); + // response.setHeader("Keep-Alive", "timeout=5, max=97"); + // // response.setContentType("text/html; charset=UTF-8"); + // } + + JavaScriptExecutor jsExecutor = RWT.getClient().getService(JavaScriptExecutor.class); + Integer exitCode = ep.createUI(); + jsExecutor.execute("location.reload()"); + return exitCode; + } + + }); } }; return authEp; @@ -56,99 +73,4 @@ public class CmsE4EntryPointFactory extends E4EntryPointFactory { protected EntryPoint createEntryPoint() { return super.create(); } - - boolean login(Subject subject) { - // Subject subject = Subject.getSubject(AccessController.getContext()); - Display display = new Display(); - CmsView cmsView = new E4CmsView(subject); - CmsLoginShell loginShell = new CmsLoginShell(cmsView); - loginShell.setSubject(subject); - try { - // try pre-auth - LoginContext loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, subject, loginShell); - loginContext.login(); - } catch (LoginException e) { - loginShell.createUi(); - loginShell.open(); - - while (!loginShell.getShell().isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } finally { - display.dispose(); - } - if (CurrentUser.getUsername(subject) == null) - return false; - return true; - } - - class E4CmsView implements CmsView { - private LoginContext loginContext; - private UxContext uxContext; - private Subject subject; - - public E4CmsView(Subject subject) { - this.subject = subject; - uxContext = new SimpleUxContext(); - } - - @Override - public UxContext getUxContext() { - return uxContext; - } - - @Override - public void navigateTo(String state) { - // TODO Auto-generated method stub - - } - - @Override - public void authChange(LoginContext loginContext) { - if (loginContext == null) - throw new CmsException("Login context cannot be null"); - // logout previous login context - // if (this.loginContext != null) - // try { - // this.loginContext.logout(); - // } catch (LoginException e1) { - // System.err.println("Could not log out: " + e1); - // } - this.loginContext = loginContext; - } - - @Override - public void logout() { - if (loginContext == null) - throw new CmsException("Login context should not bet null"); - try { - CurrentUser.logoutCmsSession(loginContext.getSubject()); - loginContext.logout(); - } catch (LoginException e) { - throw new CmsException("Cannot log out", e); - } - } - - @Override - public void exception(Throwable e) { - // TODO Auto-generated method stub - - } - - @Override - public CmsImageManager getImageManager() { - // TODO Auto-generated method stub - return null; - } - - protected Subject getSubject() { - return subject; - } - - @Override - public boolean isAnonymous() { - return CurrentUser.isAnonymous(getSubject()); - } - } }