Improve login mechanism, based on JAAS
[lgpl/argeo-commons.git] / org.argeo.security.ui.rap / src / org / argeo / security / ui / rap / SecureEntryPoint.java
index d78cdd15dd945179a974f47ea61f8d44c4c24d86..65657dc66204a4642d890e04dd6939aa3dd75a64 100644 (file)
@@ -26,7 +26,9 @@ import javax.servlet.http.HttpSession;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
+import org.argeo.cms.KernelHeader;
 import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.security.login.LoginCanceledException;
 import org.argeo.security.ui.dialogs.DefaultLoginDialog;
 import org.argeo.util.LocaleUtils;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -92,21 +94,16 @@ public class SecureEntryPoint implements EntryPoint {
                Subject subject = new Subject();
 
                // log in
-               // BundleContext bc =
-               // SecureRapActivator.getActivator().getBundleContext();
                Thread.currentThread().setContextClassLoader(
                                getClass().getClassLoader());
                final LoginContext loginContext;
                try {
-                       loginContext = new LoginContext(SPRING_SECURITY_CONTEXT_KEY,
+                       loginContext = new LoginContext(KernelHeader.LOGIN_CONTEXT_USER,
                                        subject, new DefaultLoginDialog(display.getActiveShell()));
                } catch (LoginException e1) {
                        throw new ArgeoException("Cannot initialize login context", e1);
                }
-               // final LoginModule loginModule = bc.getService(bc
-               // .getServiceReference(LoginModule.class));
-               // loginModule.initialize(subject,
-               // new DefaultLoginDialog(display.getActiveShell()), null, null);
+
                tryLogin: while (subject.getPrincipals(Authentication.class).size() == 0) {
                        try {
                                loginContext.login();
@@ -204,6 +201,9 @@ public class SecureEntryPoint implements EntryPoint {
                if (t instanceof BadCredentialsException)
                        return (BadCredentialsException) t;
 
+               if (t instanceof LoginCanceledException)
+                       return new BadCredentialsException("Login canceled");
+
                if (t.getCause() != null)
                        return wasCausedByBadCredentials(t.getCause());
                else