import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.LanguageCallback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.LanguageCallback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.cms.CmsMsg;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.cms.CmsMsg;
import org.argeo.cms.ui.CmsStyles;
import org.argeo.cms.ui.CmsView;
import org.argeo.cms.ui.internal.Activator;
import org.argeo.cms.ui.CmsStyles;
import org.argeo.cms.ui.CmsView;
import org.argeo.cms.ui.internal.Activator;
Locale locale = localeChoice == null ? this.defaultLocale : localeChoice.getSelectedLocale();
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
Locale locale = localeChoice == null ? this.defaultLocale : localeChoice.getSelectedLocale();
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
// We need a composite for the traversal
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
// We need a composite for the traversal
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
// new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
usernameT = new Text(credentialsBlock, SWT.BORDER);
usernameT.setMessage(username.lead(locale));
// new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
usernameT = new Text(credentialsBlock, SWT.BORDER);
usernameT.setMessage(username.lead(locale));
passwordT.addTraverseListener(tl);
parent.setTabList(new Control[] { credentialsBlock });
credentialsBlock.setTabList(new Control[] { usernameT, passwordT });
passwordT.addTraverseListener(tl);
parent.setTabList(new Control[] { credentialsBlock });
credentialsBlock.setTabList(new Control[] { usernameT, passwordT });
- // credentialsBlock.setFocus();
+
+ // Button
+ Button loginButton = new Button(credentialsBlock, SWT.PUSH);
+ loginButton.setText(CmsMsg.login.lead(locale));
+ loginButton.setLayoutData(CmsUtils.fillWidth());
+ loginButton.addSelectionListener(loginSelectionListener);
extendsCredentialsBlock(credentialsBlock, locale, loginSelectionListener);
if (localeChoice != null)
extendsCredentialsBlock(credentialsBlock, locale, loginSelectionListener);
if (localeChoice != null)
*/
protected void extendsCredentialsBlock(Composite credentialsBlock, Locale selectedLocale,
SelectionListener loginSelectionListener) {
*/
protected void extendsCredentialsBlock(Composite credentialsBlock, Locale selectedLocale,
SelectionListener loginSelectionListener) {
protected Composite createLocalesBlock(final Composite parent) {
Composite c = new Composite(parent, SWT.NONE);
protected Composite createLocalesBlock(final Composite parent) {
Composite c = new Composite(parent, SWT.NONE);
for (Integer i = 0; i < locales.size(); i++) {
Locale locale = locales.get(i);
Button button = new Button(c, SWT.RADIO);
for (Integer i = 0; i < locales.size(); i++) {
Locale locale = locales.get(i);
Button button = new Button(c, SWT.RADIO);
button.setData(i);
button.setText(LocaleUtils.lead(locale.getDisplayName(locale), locale) + " (" + locale + ")");
// button.addListener(SWT.Selection, listener);
button.setData(i);
button.setText(LocaleUtils.lead(locale.getDisplayName(locale), locale) + " (" + locale + ")");
// button.addListener(SWT.Selection, listener);
- loginContext.logout();
- loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, this);
+ // loginContext.logout();
+ LoginContext loginContext;
+ if (subject == null)
+ loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, this);
+ else
+ loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, subject, this);
- } catch (FailedLoginException e) {
- log.warn(e.getMessage());
+ cmsView.authChange(loginContext);
+ return true;
+ } catch (LoginException e) {
+ if (log.isTraceEnabled())
+ log.warn("Login failed: " + e.getMessage(), e);
+ else
+ log.warn("Login failed: " + e.getMessage());
+
((NameCallback) callback).setName(usernameT.getText());
else if (callback instanceof PasswordCallback && passwordT != null)
((PasswordCallback) callback).setPassword(passwordT.getTextChars());
((NameCallback) callback).setName(usernameT.getText());
else if (callback instanceof PasswordCallback && passwordT != null)
((PasswordCallback) callback).setPassword(passwordT.getTextChars());
((HttpRequestCallback) callback).setRequest(UiContext.getHttpRequest());
((HttpRequestCallback) callback).setResponse(UiContext.getHttpResponse());
((HttpRequestCallback) callback).setRequest(UiContext.getHttpRequest());
((HttpRequestCallback) callback).setResponse(UiContext.getHttpResponse());
+ } else if (callback instanceof LanguageCallback) {
+ Locale toUse = null;
+ if (localeChoice != null)
+ toUse = localeChoice.getSelectedLocale();
+ else if (defaultLocale != null)
+ toUse = defaultLocale;
+
+ if (toUse != null) {
+ ((LanguageCallback) callback).setLocale(toUse);
+ UiContext.setLocale(toUse);
+ }
+