[java-opensaml] branch master updated: IDP-1168 - Collapse duplicated scripted implementations

Scott Cantor cantor.2 at osu.edu
Thu May 4 21:29:21 EDT 2017


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=a2db2085b862074b382a7723400cafaca2278990

The following commit(s) were added to refs/heads/master by this push:
       new  a2db208   IDP-1168 -  Collapse duplicated scripted implementations
a2db208 is described below

commit a2db2085b862074b382a7723400cafaca2278990
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu May 4 21:29:17 2017 -0400

    IDP-1168 -  Collapse duplicated scripted implementations
    
    https://issues.shibboleth.net/jira/browse/IDP-1168
    
    Re-base trusted names function.
---
 .../filter/impl/ScriptedTrustedNamesFunction.java  | 72 ++++++----------------
 1 file changed, 20 insertions(+), 52 deletions(-)

diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java
index e3f3159..65e0ea9 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/ScriptedTrustedNamesFunction.java
@@ -25,40 +25,21 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.script.ScriptContext;
 import javax.script.ScriptException;
-import javax.script.SimpleScriptContext;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.resource.Resource;
+import net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator;
 import net.shibboleth.utilities.java.support.scripting.EvaluableScript;
 
 import org.opensaml.core.xml.XMLObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Function;
 
 /**
  * A scripted {@link Function} which can be injected into
  * {@link SignatureValidationFilter#setDynamicTrustedNamesStrategy(Function)}.
- * 
  */
-public class ScriptedTrustedNamesFunction implements Function<XMLObject, Set<String>> {
-
-    /** The default language is JavaScript. */
-    @Nonnull @NotEmpty public static final String DEFAULT_ENGINE = "JavaScript";
-
-    /** Class logger. */
-    @Nonnull private final Logger log = LoggerFactory.getLogger(ScriptedTrustedNamesFunction.class);
-
-    /** 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;
+public class ScriptedTrustedNamesFunction extends AbstractScriptEvaluator implements Function<XMLObject, Set<String>> {
 
     /**
      * Constructor.
@@ -67,8 +48,10 @@ public class ScriptedTrustedNamesFunction implements Function<XMLObject, Set<Str
      * @param extraInfo debugging information.
      */
     protected ScriptedTrustedNamesFunction(@Nonnull final EvaluableScript theScript, @Nullable final String extraInfo) {
-        script = Constraint.isNotNull(theScript, "Supplied script cannot be null");
-        logPrefix = "Scripted Function from " + extraInfo + " :";
+        super(theScript);
+        setOutputType(Set.class);
+        setHideExceptions(true);
+        setLogPrefix("Scripted Function from " + extraInfo + ":");
     }
 
     /**
@@ -77,43 +60,28 @@ public class ScriptedTrustedNamesFunction implements Function<XMLObject, Set<Str
      * @param theScript the script we will evaluate.
      */
     protected ScriptedTrustedNamesFunction(@Nonnull final EvaluableScript theScript) {
-        script = Constraint.isNotNull(theScript, "Supplied script should not be null");
-        logPrefix = "Anonymous Scripted Function :";
+        super(theScript);
+        setOutputType(Set.class);
+        setHideExceptions(true);
+        setLogPrefix("Anonymous Scripted Function:");
     }
 
-    /**
-     * Return the custom (externally provided) object.
-     * 
-     * @return the custom object
-     */
+    /** {@inheritDoc} */
+    @Override
     @Nullable public Object getCustomObject() {
-        return customObject;
+        return super.getCustomObject();
     }
 
-    /**
-     * Set the custom (externally provided) object.
-     * 
-     * @param object the custom object
-     */
-    @Nullable public void setCustomObject(final Object object) {
-        customObject = object;
+    /** {@inheritDoc} */
+    @Override
+    @Nullable public Set<String> apply(@Nullable final XMLObject context) {
+        return (Set<String>) evaluate(context);
     }
-
+    
     /** {@inheritDoc} */
-    @Override public Set<String> apply(@Nullable final XMLObject context) {
-
-        final SimpleScriptContext scriptContext = new SimpleScriptContext();
+    protected void prepareContext(@Nonnull final ScriptContext scriptContext, @Nullable final Object... input) {
         scriptContext.setAttribute("custom", getCustomObject(), ScriptContext.ENGINE_SCOPE);
-        scriptContext.setAttribute("profileContext", context, ScriptContext.ENGINE_SCOPE);
-
-        try {
-            final Object output = script.eval(scriptContext);
-            return (Set<String>) output;
-
-        } catch (final ScriptException e) {
-            log.error("{} Error while executing Function script", logPrefix, e);
-            return null;
-        }
+        scriptContext.setAttribute("profileContext", input[0], ScriptContext.ENGINE_SCOPE);
     }
 
     /**

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list