Clone SAMLSubject when building Query
authorgilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 29 Mar 2005 18:43:31 +0000 (18:43 +0000)
committergilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 29 Mar 2005 18:43:31 +0000 (18:43 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1345 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/serviceprovider/AttributeRequestor.java

index a80c009..eb93192 100644 (file)
@@ -58,6 +58,7 @@ import java.util.Iterator;
 import org.apache.log4j.Logger;
 import org.opensaml.SAMLAssertion;
 import org.opensaml.SAMLAttributeQuery;
 import org.apache.log4j.Logger;
 import org.opensaml.SAMLAssertion;
 import org.opensaml.SAMLAttributeQuery;
+import org.opensaml.SAMLAuthenticationStatement;
 import org.opensaml.SAMLException;
 import org.opensaml.SAMLRequest;
 import org.opensaml.SAMLResponse;
 import org.opensaml.SAMLException;
 import org.opensaml.SAMLRequest;
 import org.opensaml.SAMLResponse;
@@ -122,20 +123,35 @@ public class AttributeRequestor {
                
                // Build the Attribute Query 
                SAMLAttributeQuery query = null;
                
                // Build the Attribute Query 
                SAMLAttributeQuery query = null;
-               SAMLSubject subject = session.getAuthenticationStatement().getSubject();
+               SAMLSubject subject;
+               try {
+                       SAMLAuthenticationStatement authenticationStatement = session.getAuthenticationStatement();
+                       if (authenticationStatement==null) {
+                           log.error("Session contains no Authentication Statement." );
+                           return false;
+                       }
+                       SAMLSubject subject2 = authenticationStatement.getSubject();
+                       if (subject2==null) {
+                           log.error("Session Authentication Statement contains no Subject." );
+                           return false;
+                       }
+                       subject = (SAMLSubject) subject2.clone();
+               } catch (Exception e) {
+                   log.error("Unable to generate the query SAMLSubject from the Authenticaiton." );
+                   return false;
+               }
                log.debug("Subject (Handle) is "+subject.getName());
                Collection attributeDesignators = appinfo.getAttributeDesignators();
                try {
             query = 
                 new SAMLAttributeQuery(
                log.debug("Subject (Handle) is "+subject.getName());
                Collection attributeDesignators = appinfo.getAttributeDesignators();
                try {
             query = 
                 new SAMLAttributeQuery(
-                       subject,             // Subject (i.e. Handle) from authentication
+                       subject,                 // Subject (i.e. Handle) from authentication
                        entity.getId(),      // ID of user's Entity (i.e. Origin Site)
                        attributeDesignators // Attributes to request, null for everything
                        );
 
             // Wrap the Query in a request
                        entity.getId(),      // ID of user's Entity (i.e. Origin Site)
                        attributeDesignators // Attributes to request, null for everything
                        );
 
             // Wrap the Query in a request
-            request = new SAMLRequest();
-            request.setQuery(query);
+            request = new SAMLRequest(query);
         } catch (SAMLException e) {
             log.error("AttributeRequestor unable to build SAML Query for Session "+session.getKey());
             return false;
         } catch (SAMLException e) {
             log.error("AttributeRequestor unable to build SAML Query for Session "+session.getKey());
             return false;