Authentication working for workbench, web and data.
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 13 Oct 2015 20:01:01 +0000 (20:01 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 13 Oct 2015 20:01:01 +0000 (20:01 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8478 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.cms/src/org/argeo/cms/util/UserMenu.java
org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLogin.java
org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/RapLoginEntryPoint.java
org.argeo.security.ui/src/org/argeo/security/ui/login/WorkbenchLogin.java

index 40861742f0f90cdfe3e55983a5095dd0bb4353a2..95c7b21597a8b1aed1a9ce8b42132c5ecdad18f1 100644 (file)
@@ -5,8 +5,8 @@ import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ShellAdapter;
 import org.eclipse.swt.events.ShellEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
@@ -17,8 +17,14 @@ public class UserMenu extends CmsLogin {
 
        public UserMenu(Control source, boolean autoclose) {
                super(CmsUtils.getCmsView());
-               shell = new Shell(source.getDisplay(), SWT.NO_TRIM | SWT.BORDER
-                               | SWT.ON_TOP);
+               if (source != null) {
+                       shell = new Shell(Display.getCurrent(), SWT.NO_TRIM | SWT.BORDER
+                                       | SWT.ON_TOP);
+               } else {
+                       shell = new Shell(Display.getCurrent(), SWT.NO_TRIM);
+                       shell.setMaximized(true);
+                       shell.setLayout(CmsUtils.noSpaceGridLayout());
+               }
                shell.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
 
                if (isAnonymous()) {
@@ -27,19 +33,20 @@ public class UserMenu extends CmsLogin {
                        userUi(shell);
                }
 
-               shell.pack();
-               shell.layout();
-               if (autoclose)// popup
+               if (source != null) {// popup
+                       shell.pack();
+                       shell.layout();
                        shell.setLocation(source.toDisplay(
                                        source.getSize().x - shell.getSize().x, source.getSize().y));
-               else // centered
-               {
-                       Rectangle shellBounds = Display.getCurrent().getBounds();// RAP
-                       Point dialogSize = shell.getSize();
-                       int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
-                       int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
-                       shell.setLocation(x, y);
-
+               } else { // centered
+                       Composite parent = getCredentialsBlock();
+                       parent.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
+                                       true));
+                       // Rectangle shellBounds = shell.getBounds();// RAP
+                       // Point dialogSize = parent.getSize();
+                       // int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
+                       // int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
+                       // parent.setLocation(x, y);
                }
                if (autoclose)
                        shell.addShellListener(new ShellAdapter() {
index 9edc2f06c2fbde2e2148c69ec0f34f5fee3c1a4c..d3a14dc8038bd680bbebfb8ff1d1f1b271f64ac9 100644 (file)
@@ -36,6 +36,8 @@ import org.eclipse.swt.widgets.Text;
 
 public class CmsLogin implements CmsStyles, CallbackHandler {
        private Text username, password;
+       private Composite credentialsBlock;
+
        private final CmsView cmsView;
 
        public CmsLogin(CmsView cmsView) {
@@ -46,15 +48,19 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                return CurrentUser.isAnonymous(cmsView.getSubject());
        }
 
+       protected Composite getCredentialsBlock() {
+               return credentialsBlock;
+       }
+
        protected void userUi(Composite parent) {
                parent.setLayout(CmsUtils.noSpaceGridLayout());
-               Composite c = new Composite(parent, SWT.NONE);
-               c.setLayout(new GridLayout());
-               c.setLayoutData(CmsUtils.fillAll());
+               credentialsBlock = new Composite(parent, SWT.NONE);
+               credentialsBlock.setLayout(new GridLayout());
+               credentialsBlock.setLayoutData(CmsUtils.fillAll());
 
-               specificUserUi(c);
+               specificUserUi(credentialsBlock);
 
-               Label l = new Label(c, SWT.NONE);
+               Label l = new Label(credentialsBlock, SWT.NONE);
                l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
                l.setText(CmsMsg.logout.lead());
                GridData lData = CmsUtils.fillWidth();
@@ -79,15 +85,15 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                parent.setLayout(CmsUtils.noSpaceGridLayout());
 
                // We need a composite for the traversal
-               Composite c = new Composite(parent, SWT.NONE);
-               c.setLayout(new GridLayout());
-               c.setLayoutData(CmsUtils.fillAll());
+               credentialsBlock = new Composite(parent, SWT.NONE);
+               credentialsBlock.setLayout(new GridLayout());
+               credentialsBlock.setLayoutData(CmsUtils.fillAll());
 
                Integer textWidth = 120;
                parent.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
 
                // new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
-               username = new Text(c, SWT.BORDER);
+               username = new Text(credentialsBlock, SWT.BORDER);
                username.setMessage(CmsMsg.username.lead());
                username.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_USERNAME);
                GridData gd = CmsUtils.fillWidth();
@@ -95,7 +101,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                username.setLayoutData(gd);
 
                // new Label(this, SWT.NONE).setText(CmsMsg.password.lead());
-               password = new Text(c, SWT.BORDER | SWT.PASSWORD);
+               password = new Text(credentialsBlock, SWT.BORDER | SWT.PASSWORD);
                password.setMessage(CmsMsg.password.lead());
                password.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_PASSWORD);
                gd = CmsUtils.fillWidth();
@@ -110,12 +116,12 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                                        login();
                        }
                };
-               c.addTraverseListener(tl);
+               credentialsBlock.addTraverseListener(tl);
                username.addTraverseListener(tl);
                password.addTraverseListener(tl);
-               parent.setTabList(new Control[] { c });
-               c.setTabList(new Control[] { username, password });
-               c.setFocus();
+               parent.setTabList(new Control[] { credentialsBlock });
+               credentialsBlock.setTabList(new Control[] { username, password });
+               credentialsBlock.setFocus();
        }
 
        protected void login() {
index bb97b6549ebaf3267289ea207db7a6d3278e4ceb..bc66b164f838876601f5422249a5ef3ee5b3b6bb 100644 (file)
@@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.argeo.security.ui.login.WorkbenchLogin;
 import org.eclipse.rap.rwt.RWT;
+import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 
@@ -23,4 +24,14 @@ public class RapLoginEntryPoint extends WorkbenchLogin {
        protected HttpServletRequest getRequest() {
                return RWT.getRequest();
        }
+
+       @Override
+       public int createUI() {
+               JavaScriptExecutor jsExecutor = RWT.getClient().getService(
+                               JavaScriptExecutor.class);
+               int returnCode = super.createUI();
+               jsExecutor.execute("location.reload()");
+               return returnCode;
+       }
+
 }
index 0eee6745cbd4cf11380e55cb1061d2d1c521fec3..e36d1d1ae85266da4c58fc6c5ce68f0b8d61af80 100644 (file)
@@ -16,9 +16,11 @@ import org.argeo.cms.auth.AuthConstants;
 import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.HttpRequestCallbackHandler;
 import org.argeo.cms.util.UserMenu;
+import org.argeo.cms.widgets.auth.CmsLogin;
 import org.argeo.eclipse.ui.specific.UiContext;
 import org.eclipse.rap.rwt.application.EntryPoint;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PlatformUI;
@@ -37,11 +39,11 @@ public abstract class WorkbenchLogin implements EntryPoint, CmsView {
                                        subject, new HttpRequestCallbackHandler(getRequest()));
                        loginContext.login();
                } catch (CredentialNotFoundException e) {
-                       Shell shell = new Shell(display, SWT.NO_TRIM);
-                       shell.setMaximized(true);
-                       //shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-                       UserMenu userMenu = new UserMenu(shell, false);
-                       shell.open();
+                       // Shell shell = new Shell(display, SWT.NO_TRIM);
+                       // shell.setMaximized(true);
+                       // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+                       UserMenu userMenu = new UserMenu(null, false);
+                       // shell.open();
                        while (!userMenu.getShell().isDisposed()) {
                                if (!display.readAndDispatch()) {
                                        display.sleep();
@@ -62,35 +64,17 @@ public abstract class WorkbenchLogin implements EntryPoint, CmsView {
                                        return new Integer(result);
                                }
                        });
+                       // explicit workbench closing
+                       logout();
                } finally {
                        display.dispose();
                }
-               // explicit workbench closing
-               logout();
                return returnCode;
        }
 
        protected abstract int createAndRunWorkbench(Display display,
                        String username);
 
-       // private void fullLogout() {
-       // String username = CurrentUser.getUsername(subject);
-       // try {
-       // LoginContext loginContext = new LoginContext(
-       // AuthConstants.LOGIN_CONTEXT_USER, subject);
-       // loginContext.logout();
-       // HttpServletRequest httpRequest = getRequest();
-       // httpRequest.setAttribute(HttpContext.AUTHORIZATION, null);
-       // HttpSession httpSession = httpRequest.getSession();
-       // httpSession.setAttribute(HttpContext.AUTHORIZATION, null);
-       // httpSession.setMaxInactiveInterval(1);
-       // log.info("Logged out " + (username != null ? username : "")
-       // + " (THREAD=" + Thread.currentThread().getId() + ")");
-       // } catch (LoginException e) {
-       // log.error("Error when logging out", e);
-       // }
-       // }
-
        protected HttpServletRequest getRequest() {
                return UiContext.getHttpRequest();
        }
@@ -134,4 +118,16 @@ public abstract class WorkbenchLogin implements EntryPoint, CmsView {
                return null;
        }
 
+       // private class WorbenchCmsLogin extends CmsLogin {
+       // private final Shell shell;
+       //
+       // public WorbenchCmsLogin(CmsView cmsView, Shell shell) {
+       // super(cmsView);
+       // this.shell = shell;
+       // shell
+       // Composite parent = new Composite(shell, SWT.NONE);
+       // anonymousUi(parent);
+       // }
+       //
+       // }
 }