AA now properly responds to requests for specific attributes.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 21 May 2003 19:27:28 +0000 (19:27 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 21 May 2003 19:27:28 +0000 (19:27 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@596 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/AASaml.java
src/edu/internet2/middleware/shibboleth/aa/AAServlet.java

index 512790a..f62192e 100755 (executable)
@@ -70,7 +70,6 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.log4j.Logger;
 import org.opensaml.SAMLAssertion;
-import org.opensaml.SAMLAttribute;
 import org.opensaml.SAMLAttributeQuery;
 import org.opensaml.SAMLAttributeStatement;
 import org.opensaml.SAMLAudienceRestrictionCondition;
@@ -123,6 +122,10 @@ public class AASaml {
     public String getShar(){
        return sharName.toString();
     }
+    
+    public Iterator getDesignators() {
+       return aquery.getDesignators();
+    }
 
  
     public void respond(HttpServletResponse resp, Collection attrs, SAMLException exception)
@@ -143,24 +146,6 @@ public class AASaml {
                        Date now = new Date();
                        Date then = null;
                 long min = 0;
-                Iterator i = attrs.iterator();
-                outer_loop:
-                while (i.hasNext())
-                {
-                    SAMLAttribute attr = (SAMLAttribute)i.next();
-                    if (min == 0 || (attr.getLifetime() > 0 && attr.getLifetime() < min))
-                        min = attr.getLifetime();
-                    Iterator filter = aquery.getDesignators();
-                    if (!filter.hasNext())
-                        continue;
-                    while (filter.hasNext())
-                    {
-                        SAMLAttribute desig = (SAMLAttribute)filter.next();
-                        if (attr.getNamespace().equals(desig.getNamespace()) && attr.getName().equals(desig.getName()))
-                            continue outer_loop;
-                    }
-                    i.remove();
-                }
         
                        SAMLSubject rSubject = (SAMLSubject)aquery.getSubject().clone();
                        SAMLCondition condition = new SAMLAudienceRestrictionCondition(Arrays.asList(policies));
index cd70a0e..210c263 100755 (executable)
@@ -53,9 +53,13 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.security.Principal;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 
@@ -68,6 +72,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.log4j.Logger;
 import org.apache.log4j.MDC;
 import org.opensaml.QName;
+import org.opensaml.SAMLAttribute;
 import org.opensaml.SAMLException;
 import org.opensaml.SAMLIdentifier;
 
@@ -247,12 +252,35 @@ public class AAServlet extends HttpServlet {
                                log.info("Request is from SHAR: (" + saml.getShar() + ").");
                        }
 
-                       List attrs =
-                               Arrays.asList(
-                                       responder.getReleaseAttributes(
-                                               principal,
-                                               saml.getShar(),
-                                               resource));
+                       List attrs;
+                       Iterator requestedAttrsIterator = saml.getDesignators();
+                       if (requestedAttrsIterator.hasNext()) {
+                               log.info("Request designates specific attributes, resolving this set.");
+                               ArrayList requestedAttrs = new ArrayList();
+                               while (requestedAttrsIterator.hasNext()) {
+                                       SAMLAttribute attribute = (SAMLAttribute) requestedAttrsIterator.next();
+                                       try {
+                                               log.debug("Designated attribute: (" + attribute.getName() + ")");
+                                               requestedAttrs.add(new URI(attribute.getName()));
+                                       } catch (URISyntaxException use) {
+                                               log.error(
+                                                       "Request designated an attribute name that does not conform to the required URI syntax ("
+                                                               + attribute.getName()
+                                                               + ").  Ignoring this attribute");
+                                       }
+                               }
+                               attrs =
+                                       Arrays.asList(
+                                               responder.getReleaseAttributes(
+                                                       principal,
+                                                       saml.getShar(),
+                                                       resource,
+                                                       (URI[]) requestedAttrs.toArray(new URI[0])));
+                       } else {
+                               log.info("Request does not designate specific attributes, resolving all available.");
+                               attrs = Arrays.asList(responder.getReleaseAttributes(principal, saml.getShar(), resource));
+                       }
+
                        log.info("Found " + attrs.size() + " attribute(s) for " + principal.getName());
                        saml.respond(resp, attrs, null);
                        log.info("Successfully responded about " + principal.getName());