import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
-import org.argeo.cms.CmsException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.cms.CmsMsg;
import org.argeo.cms.CmsStyles;
import org.argeo.cms.CmsView;
import org.argeo.cms.auth.CurrentUser;
import org.argeo.cms.auth.HttpRequestCallback;
-import org.argeo.cms.i18n.Msg;
+import org.argeo.cms.i18n.LocaleUtils;
import org.argeo.cms.util.CmsUtils;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.util.LocaleChoice;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
public class CmsLogin implements CmsStyles, CallbackHandler {
+ private final static Log log = LogFactory.getLog(CmsLogin.class);
+
private Composite parent;
private Text usernameT, passwordT;
private Composite credentialsBlock;
}
protected Composite userUi(Composite parent) {
+ Locale locale = localeChoice == null ? this.defaultLocale
+ : localeChoice.getSelectedLocale();
credentialsBlock = new Composite(parent, SWT.NONE);
credentialsBlock.setLayout(new GridLayout());
credentialsBlock.setLayoutData(CmsUtils.fillAll());
Label l = new Label(credentialsBlock, SWT.NONE);
l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
- l.setText(CmsMsg.logout.lead());
+ l.setText(CmsMsg.logout.lead(locale));
GridData lData = CmsUtils.fillWidth();
lData.widthHint = 120;
l.setLayoutData(lData);
}
protected void updateLocale(Locale selectedLocale) {
- // usernameT.setMessage(username.lead(selectedLocale));
- // passwordT.setMessage(password.lead(selectedLocale));
+ // save already entered values
+ String usernameStr = usernameT.getText();
+ char[] pwd = passwordT.getTextChars();
+
for (Control child : parent.getChildren())
child.dispose();
createContents(parent);
parent.getParent().layout();
else
parent.layout();
+ usernameT.setText(usernameStr);
+ passwordT.setTextChars(pwd);
}
protected Composite createLocalesBlock(final Composite parent) {
Locale locale = locales.get(i);
Button button = new Button(c, SWT.RADIO);
button.setData(i);
- button.setText(Msg.lead(locale.getDisplayName(locale), locale)
- + " (" + locale + ")");
+ button.setText(LocaleUtils.lead(locale.getDisplayName(locale),
+ locale) + " (" + locale + ")");
// button.addListener(SWT.Selection, listener);
button.addSelectionListener(selectionListener);
if (i == localeChoice.getSelectedIndex())
return c;
}
- protected void login() {
+ protected boolean login() {
Subject subject = cmsView.getSubject();
LoginContext loginContext;
try {
new LoginContext(LOGIN_CONTEXT_ANONYMOUS, subject).logout();
loginContext = new LoginContext(LOGIN_CONTEXT_USER, subject, this);
loginContext.login();
- } catch (LoginException e1) {
- throw new CmsException("Cannot authenticate", e1);
+ } catch (FailedLoginException e) {
+ log.warn(e.getMessage());
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e2) {
+ // silent
+ }
+// ErrorFeedback.show("Login failed", e);
+ return false;
+ } catch (LoginException e) {
+ log.error("Cannot login", e);
+ return false;
}
cmsView.authChange(loginContext);
+ return true;
}
protected void logout() {