check SAML versions on requests
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Sun, 10 Jun 2007 16:26:59 +0000 (16:26 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Sun, 10 Jun 2007 16:26:59 +0000 (16:26 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2240 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/idp/profile/saml1/AbstractSAML1ProfileHandler.java
src/edu/internet2/middleware/shibboleth/idp/profile/saml2/AbstractSAML2ProfileHandler.java
src/edu/internet2/middleware/shibboleth/idp/profile/saml2/AttributeQueryProfileHandler.java
src/edu/internet2/middleware/shibboleth/idp/profile/saml2/ProfileResponseContext.java [deleted file]
src/edu/internet2/middleware/shibboleth/idp/profile/saml2/SSOProfileHandler.java

index 1974f1b..edb0b32 100644 (file)
@@ -40,6 +40,7 @@ import org.opensaml.saml1.core.AudienceRestrictionCondition;
 import org.opensaml.saml1.core.Conditions;
 import org.opensaml.saml1.core.ConfirmationMethod;
 import org.opensaml.saml1.core.NameIdentifier;
+import org.opensaml.saml1.core.Query;
 import org.opensaml.saml1.core.RequestAbstractType;
 import org.opensaml.saml1.core.Response;
 import org.opensaml.saml1.core.ResponseAbstractType;
@@ -264,6 +265,30 @@ public abstract class AbstractSAML1ProfileHandler extends AbstractSAMLProfileHan
     }
 
     /**
+     * Checks that the SAML major version for a request is 1.
+     * 
+     * @param requestContext current request context containing the SAML message
+     * 
+     * @throws ProfileException thrown if the major version of the SAML request is not 1
+     */
+    protected void checkSamlVersion(SAML1ProfileRequestContext requestContext) throws ProfileException {
+        SAMLObject samlObject = requestContext.getSamlRequest();
+
+        if (samlObject instanceof RequestAbstractType) {
+            RequestAbstractType request = (RequestAbstractType) samlObject;
+            if (request.getMajorVersion() < 1) {
+                requestContext.setFailureStatus(buildStatus(StatusCode.REQUESTER, StatusCode.REQUEST_VERSION_TOO_LOW,
+                        null));
+                throw new ProfileException("SAML request major version too low");
+            } else if (request.getMajorVersion() > 1) {
+                requestContext.setFailureStatus(buildStatus(StatusCode.REQUESTER, StatusCode.REQUEST_VERSION_TOO_HIGH,
+                        null));
+                throw new ProfileException("SAML request major version too low");
+            }
+        }
+    }
+
+    /**
      * Builds a response to the attribute query within the request context.
      * 
      * @param requestContext current request context
@@ -577,8 +602,8 @@ public abstract class AbstractSAML1ProfileHandler extends AbstractSAMLProfileHan
      * 
      * @throws ProfileException thrown if there is a problem making the query
      */
-    protected AttributeStatement buildAttributeStatement(SAML1ProfileRequestContext requestContext, String subjectConfMethod)
-            throws ProfileException {
+    protected AttributeStatement buildAttributeStatement(SAML1ProfileRequestContext requestContext,
+            String subjectConfMethod) throws ProfileException {
 
         if (log.isDebugEnabled()) {
             log.debug("Creating attribute statement in response to SAML request from relying party "
index 33ee424..d22c5ef 100644 (file)
@@ -286,6 +286,26 @@ public abstract class AbstractSAML2ProfileHandler extends AbstractSAMLProfileHan
     }
 
     /**
+     * Checks that the SAML major version for a request is 2.
+     * 
+     * @param requestContext current request context containing the SAML message
+     * 
+     * @throws ProfileException thrown if the major version of the SAML request is not 2
+     */
+    protected void checkSamlVersion(SAML2ProfileRequestContext requestContext) throws ProfileException {
+        SAMLVersion version = requestContext.getSamlRequest().getVersion();
+        if (version.getMajorVersion() < 2) {
+            requestContext.setFailureStatus(buildStatus(StatusCode.VERSION_MISMATCH_URI,
+                    StatusCode.REQUEST_VERSION_TOO_LOW_URI, null));
+            throw new ProfileException("SAML request version too low");
+        } else if (version.getMajorVersion() > 2) {
+            requestContext.setFailureStatus(buildStatus(StatusCode.VERSION_MISMATCH_URI,
+                    StatusCode.REQUEST_VERSION_TOO_HIGH_URI, null));
+            throw new ProfileException("SAML request version too high");
+        }
+    }
+
+    /**
      * Builds a response to the attribute query within the request context.
      * 
      * @param requestContext current request context
index 7a0dd8f..4f681bd 100644 (file)
@@ -66,6 +66,8 @@ public class AttributeQueryProfileHandler extends AbstractSAML2ProfileHandler {
         try {
             decodeRequest(requestContext);
             
+            checkSamlVersion(requestContext);
+            
             // Resolve attribute query name id to principal name and place in context
             resolvePrincipal(requestContext);
 
diff --git a/src/edu/internet2/middleware/shibboleth/idp/profile/saml2/ProfileResponseContext.java b/src/edu/internet2/middleware/shibboleth/idp/profile/saml2/ProfileResponseContext.java
deleted file mode 100644 (file)
index 3bf35d8..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.internet2.middleware.shibboleth.idp.profile.saml2;
-
-import org.joda.time.DateTime;
-import org.opensaml.saml2.core.AttributeStatement;
-import org.opensaml.saml2.core.Issuer;
-import org.opensaml.saml2.core.SubjectQuery;
-
-import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
-
-/**
- * Contains contextual information used in processing profile responses.
- */
-public class ProfileResponseContext {
-
-    /** Profile request. */
-    private ProfileRequest request;
-
-    /** Profile request message. */
-    private SubjectQuery message;
-
-    /** Response issuer. */
-    private Issuer issuer;
-
-    /** Response destination. */
-    private String destination;
-
-    /** Provider id to retrieve relying party configuration. */
-    private String providerId;
-
-    /** Issue instant for the response. */
-    private DateTime issueInstant;
-
-    /** Response statement. */
-    private AttributeStatement attributeStatement;
-
-    /**
-     * Constructor.
-     * 
-     * @param r serlvet request
-     * @param m decoded profile request message
-     */
-    public ProfileResponseContext(ProfileRequest r, SubjectQuery m) {
-        request = r;
-        message = m;
-        providerId = m.getIssuer().getSPProvidedID();
-        issueInstant = new DateTime();
-    }
-
-    /**
-     * Gets the initiating profile request.
-     * 
-     * @return profile request
-     */
-    public ProfileRequest getRequest() {
-        return request;
-    }
-
-    /**
-     * Gets the decoded profile request message.
-     * 
-     * @return profile request message
-     */
-    public SubjectQuery getMessage() {
-        return message;
-    }
-
-    /**
-     * Gets the provider id.
-     * 
-     * @return provider id
-     */
-    public String getProviderId() {
-        return providerId;
-    }
-
-    /**
-     * Gets the issue instant for the response.
-     * 
-     * @return issue instant
-     */
-    public DateTime getIssueInstant() {
-        return issueInstant;
-    }
-
-    /**
-     * Sets an issuer associated with this response.
-     * 
-     * @param i to set
-     */
-    public void setIssuer(Issuer i) {
-        issuer = i;
-    }
-
-    /**
-     * Gets the issuer associated with this response.
-     * 
-     * @return issuer
-     */
-    public Issuer getIssuer() {
-        return issuer;
-    }
-
-    /**
-     * Sets a destination associated with this response.
-     * 
-     * @param d to set
-     */
-    public void setDestination(String d) {
-        destination = d;
-    }
-
-    /**
-     * Gets the destination associated with this response.
-     * 
-     * @return destination
-     */
-    public String getDestination() {
-        return destination;
-    }
-
-    /**
-     * Sets a attribute statement associated with this response.
-     * 
-     * @param s to sets
-     */
-    public void setAttributeStatement(AttributeStatement s) {
-        attributeStatement = s;
-    }
-
-    /**
-     * Gets the statement associated with this response.
-     * 
-     * @return response statement
-     */
-    public AttributeStatement getAttributeStatement() {
-        return attributeStatement;
-    }
-}
index 1e7dd1d..a83d6a5 100644 (file)
@@ -227,6 +227,8 @@ public class SSOProfileHandler extends AbstractSAML2ProfileHandler {
         httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
 
         SSORequestContext requestContext = buildRequestContext(loginContext, request, response);
+        
+        checkSamlVersion(requestContext);
 
         Response samlResponse;
         try {