[java-opensaml COMMIT] in /trunk/opensaml-saml-impl/src: main/java/org/opensaml/saml/metadata/resolver/filter/impl/Sc...

noreply at shibboleth.net noreply at shibboleth.net
Mon Sep 14 12:46:05 EDT 2015


Author: rdw
Date: Mon Sep 14 12:46:05 2015
New Revision: 4336

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4336&view=rev
Log:
IDP-774 Custom object injection for scripting contexts: Attributes

https://issues.shibboleth.net/jira/browse/IDP-774

custom Object for ScriptedTrustedNamesFunction

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java
    trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedFunctionTest.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java?rev=4336&r1=4335&r2=4336&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java	(original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java	Mon Sep 14 12:46:05 2015
@@ -53,6 +53,9 @@
     /** The script we care about. */
     @Nonnull private final EvaluableScript script;
 
+    /** The custom object we can get inject into all scripts. */
+    @Nullable private Object customObject;
+
     /** Debugging info. */
     @Nullable private final String logPrefix;
 
@@ -77,11 +80,28 @@
         script = Constraint.isNotNull(theScript, "Supplied script should not be null");
         logPrefix = "Anonymous Scripted Function :";
     }
+    
+    /**
+     * Return the custom (externally provided) object.
+     * @return the custom object
+     */
+    @Nullable public Object getCustomObject() {
+        return customObject;
+    }
+
+    /**
+     * Set the custom (externally provided) object.
+     * @param object the custom object
+     */
+    @Nullable public void setCustomObject(Object object) {
+        customObject = object;
+    }
 
     /** {@inheritDoc} */
     @Override public Set<String> apply(@Nullable final XMLObject context) {
 
         final SimpleScriptContext scriptContext = new SimpleScriptContext();
+        scriptContext.setAttribute("custom", getCustomObject(), ScriptContext.ENGINE_SCOPE);
         scriptContext.setAttribute("profileContext", context, ScriptContext.ENGINE_SCOPE);
 
         try {

Modified: trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedFunctionTest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedFunctionTest.java?rev=4336&r1=4335&r2=4336&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedFunctionTest.java	(original)
+++ trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedFunctionTest.java	Mon Sep 14 12:46:05 2015
@@ -18,6 +18,7 @@
 package org.opensaml.saml.metadata.resolver.filter.impl;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Set;
 
 import javax.script.ScriptException;
@@ -83,4 +84,14 @@
         Assert.assertEquals(result.size(), 1);
         Assert.assertTrue(result.contains("String"));
     }
+    
+    @Test public void customScript() throws ScriptException {
+        
+        final ScriptedTrustedNamesFunction what = ScriptedTrustedNamesFunction.inlineScript("custom;");
+        what.setCustomObject(Collections.singleton("String"));
+        
+        final Set<String> s = what.apply(makeObject());
+        Assert.assertEquals(s.size(), 1);
+        Assert.assertTrue(s.contains("String"));
+   }
 }



More information about the commits mailing list