properly extract authentication methods at context creation time, not per invocation...
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 10 Jul 2007 21:36:31 +0000 (21:36 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 10 Jul 2007 21:36:31 +0000 (21:36 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2301 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/idp/authn/AuthenticationEngine.java
src/edu/internet2/middleware/shibboleth/idp/authn/Saml2LoginContext.java

index 596eabf..d68bd43 100644 (file)
@@ -227,7 +227,7 @@ public class AuthenticationEngine extends HttpServlet {
             loginContext.setPrincipalAuthenticated(false);
             loginContext.setAuthenticationFailureMessage("No AuthenticationHandler satisfys the request from: "
                             + loginContext.getRelyingPartyId());
-            LOG.error("No AuthenticationHandler satisfys the request from relying party: "
+            LOG.error("No AuthenticationHandler satisfies the request from relying party: "
                     + loginContext.getRelyingPartyId());
             returnToProfileHandler(loginContext, httpRequest, httpResponse);
             return;
index 174bf82..b6aaa73 100644 (file)
@@ -68,15 +68,18 @@ public class Saml2LoginContext extends LoginContext implements Serializable {
      * @throws MarshallingException thrown if the given request can not be marshalled and serialized into a string
      */
     public Saml2LoginContext(String relyingParty, AuthnRequest request) throws MarshallingException {
+        super();
+        
         if (relyingParty == null || request == null) {
             throw new IllegalArgumentException("SAML 2 authentication request and relying party ID may not be null");
         }
-
-        serialAuthnRequest = serializeRequest(request);
+        setRelyingParty(relyingParty);
         authnRequest = request;
+        serialAuthnRequest = serializeRequest(request);
+        
         setForceAuth(authnRequest.isForceAuthn());
         setPassiveAuth(authnRequest.isPassive());
-        setRelyingParty(relyingParty);
+        getRequestedAuthenticationMethods().addAll(extractRequestedAuthenticationMethods());
     }
 
     /**
@@ -109,14 +112,50 @@ public class Saml2LoginContext extends LoginContext implements Serializable {
     }
 
     /**
-     * This method evaluates a SAML2 {@link RequestedAuthnContext} and returns the list of requested authentication
-     * method URIs.
+     * Serializes an authentication request into a string.
+     * 
+     * @param request the request to serialize
+     * 
+     * @return the serialized form of the string
+     * 
+     * @throws MarshallingException thrown if the request can not be marshalled and serialized
+     */
+    protected String serializeRequest(AuthnRequest request) throws MarshallingException {
+        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(request);
+        Element requestElem = marshaller.marshall(request);
+        StringWriter writer = new StringWriter();
+        XMLHelper.writeNode(requestElem, writer);
+        return writer.toString();
+    }
+
+    /**
+     * Deserailizes an authentication request from a string.
+     * 
+     * @param request request to deserialize
+     * 
+     * @return the request XMLObject
      * 
-     * If the AuthnQuery did not contain a RequestedAuthnContext, this method will return <code>null</code>.
+     * @throws UnmarshallingException thrown if the request can no be deserialized and unmarshalled
+     */
+    protected AuthnRequest deserializeRequest(String request) throws UnmarshallingException {
+        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        try {
+            DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
+            InputSource requestInput = new InputSource(new StringReader(request));
+            Element requestElem = docBuilder.parse(requestInput).getDocumentElement();
+            Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(requestElem);
+            return (AuthnRequest) unmarshaller.unmarshall(requestElem);
+        } catch (Exception e) {
+            throw new UnmarshallingException("Unable to read serialized authentication request");
+        }
+    }
+    
+    /**
+     * Extracts the authentication methods requested within the request.
      * 
-     * @return An array of authentication method URIs, or <code>null</code>.
+     * @return requested authentication methods
      */
-    public List<String> getRequestedAuthenticationMethods() {
+    protected List<String> extractRequestedAuthenticationMethods(){
         ArrayList<String> requestedMethods = new ArrayList<String>();
 
         RequestedAuthnContext authnContext = getRequestedAuthenticationContext();
@@ -129,7 +168,7 @@ public class Saml2LoginContext extends LoginContext implements Serializable {
         if (comparator != null && comparator != AuthnContextComparisonTypeEnumeration.EXACT) {
             log.error("Unsupported comparision operator ( " + comparator
                     + ") in RequestedAuthnContext. Only exact comparisions are supported.");
-            return null;
+            return requestedMethods;
         }
 
         // build a list of all requested authn classes and declrefs
@@ -154,43 +193,4 @@ public class Saml2LoginContext extends LoginContext implements Serializable {
 
         return requestedMethods;
     }
-
-    /**
-     * Serializes an authentication request into a string.
-     * 
-     * @param request the request to serialize
-     * 
-     * @return the serialized form of the string
-     * 
-     * @throws MarshallingException thrown if the request can not be marshalled and serialized
-     */
-    protected String serializeRequest(AuthnRequest request) throws MarshallingException {
-        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(request);
-        Element requestElem = marshaller.marshall(request);
-        StringWriter writer = new StringWriter();
-        XMLHelper.writeNode(requestElem, writer);
-        return writer.toString();
-    }
-
-    /**
-     * Deserailizes an authentication request from a string.
-     * 
-     * @param request request to deserialize
-     * 
-     * @return the request XMLObject
-     * 
-     * @throws UnmarshallingException thrown if the request can no be deserialized and unmarshalled
-     */
-    protected AuthnRequest deserializeRequest(String request) throws UnmarshallingException {
-        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-        try {
-            DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
-            InputSource requestInput = new InputSource(new StringReader(request));
-            Element requestElem = docBuilder.parse(requestInput).getDocumentElement();
-            Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(requestElem);
-            return (AuthnRequest) unmarshaller.unmarshall(requestElem);
-        } catch (Exception e) {
-            throw new UnmarshallingException("Unable to read serialized authentication request");
-        }
-    }
 }
\ No newline at end of file