Implement log out
[lgpl/argeo-commons.git] / org.argeo.cms.e4.rap / src / org / argeo / cms / e4 / rap / CmsE4EntryPointFactory.java
index 6b974770eb7d03eabfa4de6d572644e13fac2e22..e3490002dd3976cabe1e4bc0e67075e9856630a1 100644 (file)
@@ -6,29 +6,48 @@ import javax.security.auth.Subject;
 
 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.rap.rwt.client.service.JavaScriptExecutor;
 
 public class CmsE4EntryPointFactory extends E4EntryPointFactory {
-       private Subject subject;
 
-       public CmsE4EntryPointFactory(Subject subject, E4ApplicationConfig config) {
+       public CmsE4EntryPointFactory(E4ApplicationConfig config) {
                super(config);
-               this.subject = subject;
        }
 
        @Override
        public EntryPoint create() {
-               // Subject subject = new Subject();
                EntryPoint ep = createEntryPoint();
                EntryPoint authEp = new EntryPoint() {
 
                        @Override
                        public int createUI() {
+                               Subject subject = new Subject();
                                return Subject.doAs(subject, new PrivilegedAction<Integer>() {
 
                                        @Override
                                        public Integer run() {
-                                               return ep.createUI();
+                                               // 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;
                                        }
 
                                });
@@ -41,4 +60,97 @@ public class CmsE4EntryPointFactory extends E4EntryPointFactory {
                return super.create();
        }
 
+       // private boolean login(Subject subject) {
+       // 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;
+       // }
+       //
+       // private 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) {
+       // log.error("Unexpected exception in Eclipse 4 RAP", e);
+       // }
+       //
+       // @Override
+       // public CmsImageManager getImageManager() {
+       // // TODO Auto-generated method stub
+       // return null;
+       // }
+       //
+       // protected Subject getSubject() {
+       // return subject;
+       // }
+       //
+       // @Override
+       // public boolean isAnonymous() {
+       // return CurrentUser.isAnonymous(getSubject());
+       // }
+       // }
 }