https://bugs.internet2.edu/jira/browse/SIDP-265
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 1 Jul 2009 08:57:09 +0000 (08:57 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 1 Jul 2009 08:57:09 +0000 (08:57 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@2857 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/main/java/edu/internet2/middleware/shibboleth/idp/authn/AuthenticationEngine.java
src/main/java/edu/internet2/middleware/shibboleth/idp/authn/LoginContext.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml1/ShibbolethSSOProfileHandler.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml2/SSOProfileHandler.java

index c0fc08a..a84537a 100644 (file)
@@ -353,9 +353,16 @@ public class AuthenticationEngine extends HttpServlet {
                             .getRelyingPartyId());
                     throw new AuthenticationException();
                 }
-                Entry<String, LoginHandler> chosenLoginHandler = possibleLoginHandlers.entrySet().iterator().next();
-                loginContext.setAttemptedAuthnMethod(chosenLoginHandler.getKey());
-                loginHandler = chosenLoginHandler.getValue();
+
+                if (loginContext.getDefaultAuthenticationMethod() != null
+                        && possibleLoginHandlers.containsKey(loginContext.getDefaultAuthenticationMethod())) {
+                    loginHandler = possibleLoginHandlers.get(loginContext.getDefaultAuthenticationMethod());
+                    loginContext.setAttemptedAuthnMethod(loginContext.getDefaultAuthenticationMethod());
+                } else {
+                    Entry<String, LoginHandler> chosenLoginHandler = possibleLoginHandlers.entrySet().iterator().next();
+                    loginContext.setAttemptedAuthnMethod(chosenLoginHandler.getKey());
+                    loginHandler = chosenLoginHandler.getValue();
+                }
             }
 
             // Send the request to the login handler
index 18ea7bb..a1078d5 100644 (file)
@@ -86,6 +86,9 @@ public class LoginContext implements Serializable {
     /** The session id. */
     private String sessionID;
 
+    /** Default authentication method to use if no other method is requested. */
+    private String defaultAuthenticationMethod;
+
     /** List of request authentication methods. */
     private List<String> requestAuthenticationMethods;
 
@@ -183,6 +186,15 @@ public class LoginContext implements Serializable {
     }
 
     /**
+     * Gets the authentication method to use if none is requested.
+     * 
+     * @return authentication method to use if none is requested, may be null which indicates any method may be used
+     */
+    public synchronized String getDefaultAuthenticationMethod() {
+        return defaultAuthenticationMethod;
+    }
+
+    /**
      * Returns the ID of the authenticated user.
      * 
      * @return the ID of the user, or <code>null</code> if authentication failed.
@@ -342,6 +354,16 @@ public class LoginContext implements Serializable {
     }
 
     /**
+     * Sets the authentication method to use if none is requested.
+     * 
+     * @param method authentication method to use if none is requested, may be null which indicates any method may be
+     *            used
+     */
+    public synchronized void setDefaultAuthenticationMethod(String method) {
+        defaultAuthenticationMethod = method;
+    }
+
+    /**
      * Sets if authentication must be forced.
      * 
      * @param force if the authentication manager must re-authenticate the user.
index 84d827d..0e90415 100644 (file)
@@ -146,16 +146,13 @@ public class ShibbolethSSOProfileHandler extends AbstractSAML1ProfileHandler {
         ShibbolethSSOLoginContext loginContext = requestContext.getLoginContext();
 
         RelyingPartyConfiguration rpConfig = getRelyingPartyConfiguration(loginContext.getRelyingPartyId());
+        loginContext.setDefaultAuthenticationMethod(rpConfig.getDefaultAuthenticationMethod());
         ProfileConfiguration ssoConfig = rpConfig.getProfileConfiguration(ShibbolethSSOConfiguration.PROFILE_ID);
         if (ssoConfig == null) {
             String msg = MessageFormatter.format("Shibboleth SSO profile is not configured for relying party '{}'", loginContext.getRelyingPartyId());
             log.warn(msg);
             throw new ProfileException(msg);
         }
-        if (loginContext.getRequestedAuthenticationMethods().size() == 0
-                && rpConfig.getDefaultAuthenticationMethod() != null) {
-            loginContext.getRequestedAuthenticationMethods().add(rpConfig.getDefaultAuthenticationMethod());
-        }
 
         httpRequest.setAttribute(LoginContext.LOGIN_CONTEXT_KEY, loginContext);
 
index 6073628..952e17e 100644 (file)
@@ -178,11 +178,8 @@ public class SSOProfileHandler extends AbstractSAML2ProfileHandler {
                     requestContext.getInboundSAMLMessage());
             loginContext.setAuthenticationEngineURL(authenticationManagerPath);
             loginContext.setProfileHandlerURL(HttpHelper.getRequestUriWithoutContext(servletRequest));
-            if (loginContext.getRequestedAuthenticationMethods().size() == 0
-                    && rpConfig.getDefaultAuthenticationMethod() != null) {
-                loginContext.getRequestedAuthenticationMethods().add(rpConfig.getDefaultAuthenticationMethod());
-            }
-
+            loginContext.setDefaultAuthenticationMethod(rpConfig.getDefaultAuthenticationMethod());
+            
             servletRequest.setAttribute(Saml2LoginContext.LOGIN_CONTEXT_KEY, loginContext);
             RequestDispatcher dispatcher = servletRequest.getRequestDispatcher(authenticationManagerPath);
             dispatcher.forward(servletRequest, ((HttpServletResponseAdapter) outTransport).getWrappedResponse());