SIDP-497 fix for SAML 2 queries
authorscantor <scantor@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 8 Jun 2011 18:30:17 +0000 (18:30 +0000)
committerscantor <scantor@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 8 Jun 2011 18:30:17 +0000 (18:30 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@3037 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml2/AttributeQueryProfileHandler.java

index 879a8c4..b3f994a 100644 (file)
@@ -25,6 +25,7 @@ import org.opensaml.common.binding.decoding.SAMLMessageDecoder;
 import org.opensaml.common.xml.SAMLConstants;
 import org.opensaml.saml2.core.AttributeQuery;
 import org.opensaml.saml2.core.AttributeStatement;
+import org.opensaml.saml2.core.NameID;
 import org.opensaml.saml2.core.Response;
 import org.opensaml.saml2.core.Statement;
 import org.opensaml.saml2.core.StatusCode;
@@ -54,6 +55,9 @@ public class AttributeQueryProfileHandler extends AbstractSAML2ProfileHandler {
     /** Class logger. */
     private static Logger log = LoggerFactory.getLogger(AttributeQueryProfileHandler.class);
 
+    /** Builder of NameID objects. */
+    private SAMLObjectBuilder<NameID> nameIDBuilder;
+
     /** Builder of assertion consumer service endpoints. */
     private SAMLObjectBuilder<AssertionConsumerService> acsEndpointBuilder;
 
@@ -61,6 +65,8 @@ public class AttributeQueryProfileHandler extends AbstractSAML2ProfileHandler {
     public AttributeQueryProfileHandler() {
         super();
 
+        nameIDBuilder = (SAMLObjectBuilder<NameID>) getBuilderFactory().getBuilder(
+                NameID.DEFAULT_ELEMENT_NAME);
         acsEndpointBuilder = (SAMLObjectBuilder<AssertionConsumerService>) getBuilderFactory().getBuilder(
                 AssertionConsumerService.DEFAULT_ELEMENT_NAME);
     }
@@ -275,6 +281,25 @@ public class AttributeQueryProfileHandler extends AbstractSAML2ProfileHandler {
         return endpoint;
     }
 
+    /** {@inheritDoc} */
+    protected NameID buildNameId(BaseSAML2ProfileRequestContext<?, ?, ?> requestContext)
+        throws ProfileException {
+        
+        log.debug("Reusing NameID supplied in query");
+        NameID src = requestContext.getSubjectNameIdentifier();
+        if (src != null) {
+            NameID dest = nameIDBuilder.buildObject();
+            dest.setValue(src.getValue());
+            dest.setNameQualifier(src.getNameQualifier());
+            dest.setSPNameQualifier(src.getSPNameQualifier());
+            dest.setFormat(src.getFormat());
+            dest.setSPProvidedID(src.getSPProvidedID());
+            return dest;
+        }
+        return null;
+    }
+
+    
     /** Basic data structure used to accumulate information as a request is being processed. */
     protected class AttributeQueryContext extends
             BaseSAML2ProfileRequestContext<AttributeQuery, Response, AttributeQueryConfiguration> {