import javax.security.auth.login.LoginException;
import org.argeo.ArgeoException;
-import org.argeo.cms.CmsLogin;
import org.argeo.cms.CmsMsg;
import org.argeo.cms.CmsSession;
import org.argeo.cms.CmsStyles;
/** The site-related user menu */
public class UserMenu extends Shell implements CmsStyles, CallbackHandler {
private static final long serialVersionUID = -5788157651532106301L;
-
- private CmsLogin cmsLogin;
- // private String username = null;
private Text username, password;
- public UserMenu(CmsLogin cmsLogin, Control source) {
+ public UserMenu(Control source) {
super(source.getDisplay(), SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP);
- this.cmsLogin = cmsLogin;
-
setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
String username = SecurityContextHolder.getContext()
close();
dispose();
}
-
});
-
open();
-
}
protected void userUi() {
l.setLayoutData(CmsUtils.fillWidth());
l.setText("<b>" + username + "</b>");
- final CmsSession cmsSession = (CmsSession) getDisplay().getData(
- CmsSession.KEY);
l = new Label(this, SWT.NONE);
l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
l.setText(CmsMsg.logout.lead());
private static final long serialVersionUID = 6444395812777413116L;
public void mouseDown(MouseEvent e) {
- Subject subject = new Subject();
- try {
- new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_USER,
- subject).logout();
- new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_ANONYMOUS,
- subject).login();
- } catch (LoginException e1) {
- throw new ArgeoException("Cannot authenticate anonymous",
- e1);
- }
- // SecurityContextHolder.getContext().setAuthentication(null);
- // HttpSession httpSession = RWT.getRequest().getSession();
- // httpSession.removeAttribute(SPRING_SECURITY_CONTEXT_KEY);
- close();
- dispose();
- cmsSession.authChange();
+ logout();
}
});
}
gd.widthHint = textWidth;
password.setLayoutData(gd);
- // Listeners
TraverseListener tl = new TraverseListener() {
private static final long serialVersionUID = -1158892811534971856L;
protected void login() {
CmsSession cmsSession = (CmsSession) getDisplay().getData(
CmsSession.KEY);
-
Subject subject = new Subject();
try {
+ //
+ // LOGIN
+ //
new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_ANONYMOUS, subject)
.logout();
LoginContext loginContext = new ArgeoLoginContext(
} catch (LoginException e1) {
throw new ArgeoException("Cannot authenticate anonymous", e1);
}
+ close();
+ dispose();
+ cmsSession.authChange();
+ }
- // cmsLogin.logInWithPassword(username, password);
+ protected void logout() {
+ final CmsSession cmsSession = (CmsSession) getDisplay().getData(
+ CmsSession.KEY);
+ Subject subject = new Subject();
+ try {
+ //
+ // LOGOUT
+ //
+ new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_USER, subject)
+ .logout();
+ new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_ANONYMOUS, subject)
+ .login();
+ } catch (LoginException e1) {
+ throw new ArgeoException("Cannot authenticate anonymous", e1);
+ }
close();
dispose();
- // refreshUi(source.getParent());
cmsSession.authChange();
}
UnsupportedCallbackException {
((NameCallback) callbacks[0]).setName(username.getText());
((PasswordCallback) callbacks[1]).setPassword(password.getTextChars());
- // while (!isDisposed())
- // try {
- // Thread.sleep(500);
- // } catch (InterruptedException e) {
- // // silent
- // }
}
}