[java-identity-provider COMMIT] /trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolve...

noreply at shibboleth.net noreply at shibboleth.net
Fri Feb 28 08:54:57 EST 2014


Author: rdw
Date: Fri Feb 28 08:54:56 2014
New Revision: 5493

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=5493&view=rev
Log:
Both getValues and setValues have to provoke the creation of a shadow collection to store values.

Modified:
    trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedIdPAttribute.java

Modified: trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedIdPAttribute.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedIdPAttribute.java?rev=5493&r1=5492&r2=5493&view=diff
==============================================================================
--- trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedIdPAttribute.java (original)
+++ trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedIdPAttribute.java Fri Feb 28 08:54:56 2014
@@ -76,23 +76,15 @@
                 new StringBuilder(prefix).append(" scripted attribute '").append(attribute.getId()).append("':")
                         .toString();
     }
-
-    /**
-     * Return all the values, but with {@link StringAttributeValue} values returned as strings.<br/>
-     * This method is a helper method for V2 compatibility.
-     * 
-     * @return a modifiable collection of the string attributes (not the String
-     * @throws ResolutionException if the script has called {@link #getNativeAttribute()}
-     */
-    @Nullable @NonnullElements public Collection<Object> getValues() throws ResolutionException {
-        if (calledGetNativeAttribute) {
-            throw new ResolutionException(getLogPrefix()
-                    + " cannot call getNativeAttribute() and getValues() on the same attribute()");
-        }
+    
+    /**
+     *  We use an internal list of attribute values to allow the legacy use of 
+     *  getValues().add().
+     */
+    private void setupAttributeValues() {
         if (null != attributeValues) {
-            return attributeValues;
-        }
-
+            return;
+        }
         log.debug("{} values being prepared", getLogPrefix());
 
         // NOTE. This has to be a List - the examples use get(0)
@@ -106,7 +98,25 @@
         }
         attributeValues = newValues;
         log.debug("{} values are : {}", getLogPrefix(), newValues);
-        return newValues;
+    }
+
+    /**
+     * Return all the values, but with {@link StringAttributeValue} values returned as strings.<br/>
+     * This method is a helper method for V2 compatibility.
+     * 
+     * @return a modifiable collection of the string attributes (not the String
+     * @throws ResolutionException if the script has called {@link #getNativeAttribute()}
+     */
+    @Nullable @NonnullElements public Collection<Object> getValues() throws ResolutionException {
+        if (calledGetNativeAttribute) {
+            throw new ResolutionException(getLogPrefix()
+                    + " cannot call getNativeAttribute() and getValues() or addValues() on the same attribute()");
+        }
+        if (null == attributeValues) {
+            setupAttributeValues();
+        }
+
+        return attributeValues;
     }
 
     /**
@@ -118,7 +128,7 @@
     @Nonnull public IdPAttribute getNativeAttribute() throws ResolutionException {
         if (null != attributeValues) {
             throw new ResolutionException(getLogPrefix()
-                    + "': cannot call getNativeAttribute() and getValues() on the same attribute()");
+                    + "': cannot call getNativeAttribute() and getValues()/setValues() on the same attribute()");
         }
         calledGetNativeAttribute = true;
         return encapsulatedAttribute;
@@ -172,12 +182,11 @@
     public void addValue(@Nullable final Object what) throws ResolutionException {
         policeValueType(what);
 
-        if (null != attributeValues) {
-            // We have called getValues - this is what we will keep up to date
-            attributeValues.add(what);
-        } else {
-            addValue(encapsulatedAttribute.getValues(), what);
-        }
+        if (null == attributeValues) {
+            setupAttributeValues();
+        }
+        
+        attributeValues.add(what);
     }
 
     /**



More information about the commits mailing list