[java-identity-provider COMMIT] in /trunk/idp-attribute-filter-impl/src: main/java/net/shibboleth/idp/attribute/filte...

noreply at shibboleth.net noreply at shibboleth.net
Sat Jul 13 03:54:24 EDT 2013


Author: rdw
Date: Sat Jul 13 03:54:24 2013
New Revision: 4559

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4559&view=rev
Log:
IDP-287 Scripted matchers and Scripted Policy Rules

Added:
    trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/impl/policyrule/ScriptedPolicyRule.java   (with props)
    trunk/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/impl/policyrule/ScriptedPolicyRuleTest.java   (with props)
Modified:
    trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/impl/matcher/ScriptedMatcher.java
    trunk/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/impl/matcher/ScriptedMatcherTest.java

Modified: trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/impl/matcher/ScriptedMatcher.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/impl/matcher/ScriptedMatcher.java?rev=4559&r1=4558&r2=4559&view=diff
==============================================================================
--- trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/impl/matcher/ScriptedMatcher.java (original)
+++ trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/impl/matcher/ScriptedMatcher.java Sat Jul 13 03:54:24 2013
@@ -31,7 +31,6 @@
 import net.shibboleth.idp.attribute.Attribute;
 import net.shibboleth.idp.attribute.AttributeValue;
 import net.shibboleth.idp.attribute.filter.AttributeFilterContext;
-import net.shibboleth.idp.attribute.filter.AttributeFilterException;
 import net.shibboleth.idp.attribute.filter.Matcher;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
@@ -42,6 +41,9 @@
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.scripting.EvaluableScript;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.common.base.Objects;
 
 /**
@@ -52,6 +54,9 @@
 public class ScriptedMatcher extends AbstractDestructableIdentifiableInitializableComponent implements Matcher,
         UnmodifiableComponent {
 
+    /** Class logger. */
+    private final Logger log = LoggerFactory.getLogger(ScriptedMatcher.class);
+
     /** Script to be evaluated. */
     private EvaluableScript script;
 
@@ -92,43 +97,6 @@
         ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
 
         script = Constraint.isNotNull(matcherScript, "Attribute value matching script can not be null");
-    }
-
-    /**
-     * Calculate the PolicyRule.
-     * <p>
-     * When the script is evaluated, the following property will be available via the {@link ScriptContext}:
-     * <ul>
-     * <li><code>filterContext</code> - the current instance of {@link AttributeFilterContext}</li>
-     * </ul>
-     * The script <strong>MUST</strong> return a {@link java.lang.Boolean}
-     * </p>
-     * {@inheritDoc}
-     */
-    public boolean matches(@Nonnull final AttributeFilterContext filterContext) throws AttributeFilterException {
-        Constraint.isNotNull(filterContext, "Attribute filter context can not be null");
-
-        final EvaluableScript currentScript = script;
-        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
-        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
-
-        final SimpleScriptContext scriptContext = new SimpleScriptContext();
-        scriptContext.setAttribute("filterContext", filterContext, ScriptContext.ENGINE_SCOPE);
-
-        try {
-            final Object result = currentScript.eval(scriptContext);
-            if (null == result) {
-                throw new IllegalArgumentException(getLogPrefix() + " Matcher script did not return a result");
-            }
-
-            if (result instanceof Boolean) {
-                return ((Boolean) result).booleanValue();
-            } else {
-                throw new AttributeFilterException(getLogPrefix() + " Matcher script did not return a Boolean");
-            }
-        } catch (ScriptException e) {
-            throw new AttributeFilterException(getLogPrefix() + "Error while executing value matching script", e);
-        }
     }
 
     /**
@@ -144,9 +112,8 @@
      * </p>
      * {@inheritDoc}
      */
-    @Nonnull @NonnullElements @Unmodifiable public Set<AttributeValue> getMatchingValues(
-            @Nonnull final Attribute attribute, @Nonnull final AttributeFilterContext filterContext)
-            throws AttributeFilterException {
+    @Nullable @NonnullElements @Unmodifiable public Set<AttributeValue> getMatchingValues(
+            @Nonnull final Attribute attribute, @Nonnull final AttributeFilterContext filterContext) {
         Constraint.isNotNull(attribute, "Attribute to be filtered can not be null");

[... 146 lines stripped ...]


More information about the commits mailing list