@Override
public Void run() {
try {
- createUi(parent);
+ initUi(parent);
} catch (Exception e) {
throw new CmsException("Cannot create entrypoint contents",
e);
}
/** Create UI */
- protected abstract void createUi(Composite parent);
+ protected abstract void initUi(Composite parent);
/** Recreate UI after navigation or auth change */
protected abstract void refresh();
dn: ou=roles,ou=node
objectClass: organizationalUnit
objectClass: top
-ou: system
+ou: roles
dn: cn=admin,ou=roles,ou=node
objectClass: groupOfNames
dn: cn=org.argeo.cms.editor,ou=roles,ou=node
objectClass: groupOfNames
objectClass: top
-cn: editor
+cn: org.argeo.cms.editor
member: cn=admin,ou=roles,ou=node
member: uid=demo,ou=users,dc=example,dc=com
--- /dev/null
+package org.argeo.cms.util;
+
+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.AuthConstants;
+import org.argeo.cms.widgets.auth.CompositeCallbackHandler;
+import org.eclipse.rap.rwt.application.AbstractEntryPoint;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+public class LoginEntryPoint extends AbstractEntryPoint {
+ @Override
+ public void createContents(Composite parent) {
+ parent.setLayout(new GridLayout());
+ // CompositeCallbackHandler cch = new CompositeCallbackHandler(parent,
+ // SWT.NONE);
+ UserMenu userMenu = new UserMenu(parent, false);
+
+// Subject subject = new Subject();
+// try {
+// LoginContext lc = new LoginContext(
+// AuthConstants.LOGIN_CONTEXT_USER, subject, userMenu);
+// lc.login();
+// } catch (LoginException e1) {
+// throw new CmsException("Cannot logint", e1);
+// }
+ }
+
+}
@Override
public void mouseDown(MouseEvent e) {
if (e.button == 1) {
- new UserMenu((Control) e.getSource());
+ new UserMenu((Control) e.getSource(), true);
}
}
}
\ No newline at end of file
}
@Override
- protected void createUi(Composite parent) {
+ protected void initUi(Composite parent) {
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
parent.setLayout(CmsUtils.noSpaceGridLayout());
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/** The site-related user menu */
-public class UserMenu extends Shell implements CmsStyles, CallbackHandler {
- private static final long serialVersionUID = -5788157651532106301L;
- private Text username, password;
+public class UserMenu implements CmsStyles, CallbackHandler {
+ private final CmsView cmsView;
+ private final Shell shell;
- public UserMenu(Control source) {
- super(source.getDisplay(), SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP);
- setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
+ private Text username, password;
- String username = CurrentUser.getUsername(CmsUtils.getCmsView().getSubject());
- if (username.equalsIgnoreCase(AuthConstants.ROLE_ANONYMOUS)) {
- username = null;
- anonymousUi();
+ public UserMenu(Control source, boolean autoclose) {
+ shell = new Shell(source.getDisplay(), SWT.NO_TRIM | SWT.BORDER
+ | SWT.ON_TOP);
+ shell.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
+ // cmsView = (CmsView) shell.getDisplay().getData(CmsView.KEY);
+ cmsView = CmsUtils.getCmsView();
+
+ if (cmsView != null) {
+ String username = CurrentUser.getUsername(CmsUtils.getCmsView()
+ .getSubject());
+ if (username == null
+ || username.equalsIgnoreCase(AuthConstants.ROLE_ANONYMOUS)) {
+ username = null;
+ anonymousUi(shell);
+ } else {
+ userUi(shell);
+ }
} else {
- userUi();
+ anonymousUi(shell);
}
- pack();
- layout();
- setLocation(source.toDisplay(source.getSize().x - getSize().x,
- source.getSize().y));
+ shell.pack();
+ shell.layout();
+ if (autoclose)// popup
+ 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);
- addShellListener(new ShellAdapter() {
- private static final long serialVersionUID = 5178980294808435833L;
+ }
+ if (autoclose)
+ shell.addShellListener(new ShellAdapter() {
+ private static final long serialVersionUID = 5178980294808435833L;
+
+ @Override
+ public void shellDeactivated(ShellEvent e) {
+ closeShell();
+ }
+ });
+ shell.open();
- @Override
- public void shellDeactivated(ShellEvent e) {
- close();
- dispose();
- }
- });
- open();
}
- protected void userUi() {
- setLayout(CmsUtils.noSpaceGridLayout());
- Composite c = new Composite(this, SWT.NONE);
+ protected void closeShell() {
+ shell.close();
+ shell.dispose();
+ }
+
+ protected void userUi(Composite parent) {
+ parent.setLayout(CmsUtils.noSpaceGridLayout());
+ Composite c = new Composite(parent, SWT.NONE);
c.setLayout(new GridLayout());
c.setLayoutData(CmsUtils.fillAll());
}
- protected void anonymousUi() {
- setLayout(CmsUtils.noSpaceGridLayout());
+ protected void anonymousUi(Composite parent) {
+ parent.setLayout(CmsUtils.noSpaceGridLayout());
// We need a composite for the traversal
- Composite c = new Composite(this, SWT.NONE);
+ Composite c = new Composite(parent, SWT.NONE);
c.setLayout(new GridLayout());
c.setLayoutData(CmsUtils.fillAll());
Integer textWidth = 120;
- setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
+ parent.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
// new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
username = new Text(c, SWT.BORDER);
c.addTraverseListener(tl);
username.addTraverseListener(tl);
password.addTraverseListener(tl);
- setTabList(new Control[] { c });
+ parent.setTabList(new Control[] { c });
c.setTabList(new Control[] { username, password });
c.setFocus();
}
protected void login() {
- CmsView cmsSession = (CmsView) getDisplay().getData(CmsView.KEY);
- Subject subject = cmsSession.getSubject();
+ Subject subject = cmsView.getSubject();
try {
//
// LOGIN
}
throw new CmsException("Cannot authenticate", e1);
}
- close();
- dispose();
- cmsSession.authChange();
+ closeShell();
+ cmsView.authChange();
}
protected void logout() {
- final CmsView cmsSession = (CmsView) getDisplay().getData(CmsView.KEY);
- Subject subject = cmsSession.getSubject();
+ Subject subject = cmsView.getSubject();
try {
//
// LOGOUT
} catch (LoginException e1) {
throw new CmsException("Cannot authenticate anonymous", e1);
}
- close();
- dispose();
- cmsSession.navigateTo("~");
- cmsSession.authChange();
+ closeShell();
+ cmsView.navigateTo("~");
+ cmsView.authChange();
}
@Override
((PasswordCallback) callbacks[1]).setPassword(password.getTextChars());
}
+ public Shell getShell() {
+ return shell;
+ }
+
}
}
protected UserMenu createUserMenu(Control source) {
- return new UserMenu(source.getParent());
+ return new UserMenu(source.getParent(), true);
}
private class UserMenuLinkController implements MouseListener,
// avoid to reopen the menu, if one has clicked gain
if (durationSinceLastDispose > 200) {
userMenu = createUserMenu(source);
- userMenu.addDisposeListener(this);
+ userMenu.getShell().addDisposeListener(this);
}
}
}
if (!wasUsedAlready)
wasUsedAlready = true;
- while (!isSubmitted() && !isCanceled()) {
- try {
- wait(1000l);
- } catch (InterruptedException e) {
- // silent
- }
- }
-
- cleanCallbacksAfterCancel(callbacks);
+// while (!isSubmitted() && !isCanceled()) {
+// try {
+// wait(1000l);
+// } catch (InterruptedException e) {
+// // silent
+// }
+// }
+
+// cleanCallbacksAfterCancel(callbacks);
}
public void checkCallbackSupported(Callback callback)
path="/public"
brandingId="org.argeo.security.ui.rap.defaultBranding">
</entrypoint>
+ <entrypoint
+ brandingId="org.argeo.security.ui.rap.defaultBranding"
+ class="org.argeo.security.ui.rap.RapLoginEntryPoint"
+ id="org.argeo.security.ui.rap.secureEntryPoint"
+ path="/login">
+ </entrypoint>
</extension>
<!-- COMMANDS -->
body="branding/empty.html">
</branding>
</extension>
-</plugin>
\ No newline at end of file
+</plugin>
--- /dev/null
+package org.argeo.security.ui.rap;
+
+import org.argeo.security.ui.login.WorkbenchLogin;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+
+public class RapLoginEntryPoint extends WorkbenchLogin {
+
+ @Override
+ protected int createAndRunWorkbench(Display display, String username) {
+ RapWorkbenchAdvisor workbenchAdvisor = createRapWorkbenchAdvisor(username);
+ return PlatformUI.createAndRunWorkbench(display, workbenchAdvisor);
+ }
+
+ /** Override to provide an application specific workbench advisor */
+ protected RapWorkbenchAdvisor createRapWorkbenchAdvisor(String username) {
+ return new RapWorkbenchAdvisor(username);
+ }
+
+}
--- /dev/null
+package org.argeo.security.ui.login;
+
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+
+import org.argeo.cms.CmsImageManager;
+import org.argeo.cms.CmsView;
+import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.util.UserMenu;
+import org.eclipse.rap.rwt.application.EntryPoint;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+public abstract class WorkbenchLogin implements EntryPoint, CmsView {
+ private final Subject subject = new Subject();
+
+ @Override
+ public int createUI() {
+ final Display display = PlatformUI.createDisplay();
+ display.setData(CmsView.KEY, this);
+ Shell shell = new Shell(display, SWT.NO_TRIM);
+ shell.setMaximized(true);
+ UserMenu userMenu = new UserMenu(shell, false);
+ shell.open();
+ while (!userMenu.getShell().isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ //
+ // RUN THE WORKBENCH
+ //
+ Integer returnCode = null;
+ try {
+ returnCode = Subject.doAs(subject, new PrivilegedAction<Integer>() {
+ public Integer run() {
+ int result = createAndRunWorkbench(display,
+ CurrentUser.getUsername(subject));
+ return new Integer(result);
+ }
+ });
+ } finally {
+ display.dispose();
+ }
+ return returnCode;
+ // display.dispose();
+ // return 0;
+ }
+
+ protected abstract int createAndRunWorkbench(Display display,
+ String username);
+
+ @Override
+ public void navigateTo(String state) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void authChange() {
+ }
+
+ @Override
+ public final Subject getSubject() {
+ return subject;
+ }
+
+ @Override
+ public void exception(Throwable e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public CmsImageManager getImageManager() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}