fix NPE with name identifier selection when user attribute collection is null
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 27 Apr 2011 13:36:46 +0000 (13:36 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 27 Apr 2011 13:36:46 +0000 (13:36 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@3018 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/main/java/edu/internet2/middleware/shibboleth/idp/profile/AbstractSAMLProfileHandler.java

index 2be9059..ba2cdc6 100644 (file)
@@ -449,8 +449,12 @@ public abstract class AbstractSAMLProfileHandler extends
     protected <T extends SAMLNameIdentifierEncoder> Pair<BaseAttribute, T> selectNameIDAttributeAndEncoder(
             Class<T> nameIdEncoderType, BaseSAMLProfileRequestContext requestContext) throws ProfileException {
 
-        Collection<BaseAttribute<?>> principalAttributes = new ArrayList<BaseAttribute<?>>(requestContext
-                .getAttributes().values());
+        Collection<BaseAttribute<?>> principalAttributes;
+        if (requestContext.getAttributes() == null) {
+            principalAttributes = Collections.emptyList();
+        } else {
+            principalAttributes = new ArrayList<BaseAttribute<?>>(requestContext.getAttributes().values());
+        }
 
         filterNameIDAttributesByProtocol(principalAttributes, nameIdEncoderType);
 
@@ -496,6 +500,10 @@ public abstract class AbstractSAMLProfileHandler extends
      */
     protected <T extends SAMLNameIdentifierEncoder> void filterNameIDAttributesByProtocol(
             Collection<BaseAttribute<?>> attributes, Class<T> nameIdEncoderType) {
+        if(attributes.isEmpty()){
+            return;
+        }
+        
         log.debug("Filtering out potential name identifier attributes which can not be encoded by {}",
                 nameIdEncoderType.getName());
 
@@ -531,7 +539,7 @@ public abstract class AbstractSAMLProfileHandler extends
      */
     protected void filterNameIDAttributesByFormats(Collection<BaseAttribute<?>> attributes,
             Collection<String> acceptableFormats) {
-        if (acceptableFormats == null || acceptableFormats.isEmpty()) {
+        if (attributes.isEmpty() || acceptableFormats == null || acceptableFormats.isEmpty()) {
             return;
         }