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;
parent.setLayout(new GridLayout());
// CompositeCallbackHandler cch = new CompositeCallbackHandler(parent,
// SWT.NONE);
- UserMenu userMenu = new UserMenu(parent, false);
+ // UserMenu userMenu = new UserMenu(null);
-// 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);
-// }
+ // 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(), true);
+ new UserMenu((Control) e.getSource());
}
}
}
\ No newline at end of file
package org.argeo.cms.util;
-import org.argeo.cms.widgets.auth.CmsLogin;
-import org.eclipse.rap.rwt.RWT;
+import org.argeo.cms.CmsException;
+import org.argeo.cms.widgets.auth.CmsLoginShell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
-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;
/** The site-related user menu */
-public class UserMenu extends CmsLogin {
- private final Shell shell;
+public class UserMenu extends CmsLoginShell {
+ private final Control source;
- public UserMenu(Control source, boolean autoclose) {
+ public UserMenu(Control source) {
super(CmsUtils.getCmsView());
- 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()) {
- anonymousUi(shell);
- } else {
- userUi(shell);
- }
-
- if (source != null) {// popup
- shell.pack();
- shell.layout();
- shell.setLocation(source.toDisplay(
- source.getSize().x - shell.getSize().x, source.getSize().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() {
- private static final long serialVersionUID = 5178980294808435833L;
-
- @Override
- public void shellDeactivated(ShellEvent e) {
- closeShell();
- }
- });
- shell.open();
-
+ if (source == null)
+ throw new CmsException("Source control cannot be null.");
+ this.source = source;
+ open();
}
@Override
- protected void login() {
- super.login();
- closeShell();
+ protected Shell createShell() {
+ return new Shell(Display.getCurrent(), SWT.NO_TRIM | SWT.BORDER
+ | SWT.ON_TOP);
}
@Override
- protected void logout() {
- closeShell();
- super.logout();
+ public void open() {
+ Shell shell = getShell();
+ shell.pack();
+ shell.layout();
+ shell.setLocation(source.toDisplay(source.getSize().x
+ - shell.getSize().x, source.getSize().y));
+ shell.addShellListener(new ShellAdapter() {
+ private static final long serialVersionUID = 5178980294808435833L;
+
+ @Override
+ public void shellDeactivated(ShellEvent e) {
+ closeShell();
+ }
+ });
+ super.open();
}
- protected void closeShell() {
- shell.close();
- shell.dispose();
- }
-
- public Shell getShell() {
- return shell;
- }
}
}
protected UserMenu createUserMenu(Control source) {
- return new UserMenu(source.getParent(), true);
+ return new UserMenu(source.getParent());
}
private class UserMenuLinkController implements MouseListener,
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class CmsLogin implements CmsStyles, CallbackHandler {
return CurrentUser.isAnonymous(cmsView.getSubject());
}
+ protected void createContents(Composite parent) {
+ parent.setLayout(CmsUtils.noSpaceGridLayout());
+ Composite credentialsBlock = createCredentialsBlock(parent);
+ if (parent instanceof Shell) {
+ credentialsBlock.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
+ true, true));
+ }
+ }
+
+ protected final Composite createCredentialsBlock(Composite parent) {
+ if (isAnonymous()) {
+ return anonymousUi(parent);
+ } else {
+ return userUi(parent);
+ }
+ }
+
protected Composite getCredentialsBlock() {
return credentialsBlock;
}
- protected void userUi(Composite parent) {
- parent.setLayout(CmsUtils.noSpaceGridLayout());
+ protected Composite userUi(Composite parent) {
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
credentialsBlock.setLayoutData(CmsUtils.fillAll());
logout();
}
});
+ return credentialsBlock;
}
/** To be overridden */
}
- protected void anonymousUi(Composite parent) {
- parent.setLayout(CmsUtils.noSpaceGridLayout());
-
+ protected Composite anonymousUi(Composite parent) {
// We need a composite for the traversal
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
parent.setTabList(new Control[] { credentialsBlock });
credentialsBlock.setTabList(new Control[] { username, password });
credentialsBlock.setFocus();
+ return credentialsBlock;
}
protected void login() {
--- /dev/null
+package org.argeo.cms.widgets.auth;
+
+import org.argeo.cms.CmsView;
+import org.eclipse.rap.rwt.RWT;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/** The site-related user menu */
+public class CmsLoginShell extends CmsLogin {
+ private final Shell shell;
+
+ public CmsLoginShell(CmsView cmsView) {
+ super(cmsView);
+ shell = createShell();
+ shell.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
+ createContents(shell);
+ }
+
+ /** To be overridden. */
+ protected Shell createShell() {
+ Shell shell = new Shell(Display.getCurrent(), SWT.NO_TRIM);
+ shell.setMaximized(true);
+ return shell;
+ }
+
+ /** To be overridden. */
+ public void open() {
+ shell.open();
+ }
+
+ @Override
+ protected void login() {
+ super.login();
+ closeShell();
+ }
+
+ @Override
+ protected void logout() {
+ closeShell();
+ super.logout();
+ }
+
+ protected void closeShell() {
+ shell.close();
+ shell.dispose();
+ }
+
+ public Shell getShell() {
+ return shell;
+ }
+}
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.cms.widgets.auth.CmsLoginShell;
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;
public abstract class WorkbenchLogin implements EntryPoint, CmsView {
final Display display = PlatformUI.createDisplay();
UiContext.setData(CmsView.KEY, this);
try {
+ // try pre-auth
loginContext = new LoginContext(AuthConstants.LOGIN_CONTEXT_USER,
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(null, false);
- // shell.open();
- while (!userMenu.getShell().isDisposed()) {
+ CmsLoginShell loginShell = createCmsLoginShell();
+ loginShell.open();
+ while (!loginShell.getShell().isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
return UiContext.getHttpRequest();
}
+ protected CmsLoginShell createCmsLoginShell() {
+ return new CmsLoginShell(this);
+ }
+
@Override
public void navigateTo(String state) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
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);
- // }
- //
- // }
}