[java-shib-profile] branch main updated: IDP-2044 Scripted object constructors and initialization

Rod Widdowson rdw at steadingsoftware.com
Wed Jun 21 15:43:20 UTC 2023


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

rdw pushed a commit to branch main
in repository java-shib-profile.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-profile.git;a=commit;h=6e02b669091b27b6b312cf4ce5c3aa4b64b3e663

The following commit(s) were added to refs/heads/main by this push:
     new 6e02b66  IDP-2044 Scripted object constructors and initialization
6e02b66 is described below

commit 6e02b669091b27b6b312cf4ce5c3aa4b64b3e663
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Jun 21 15:59:28 2023 +0100

    IDP-2044 Scripted object constructors and initialization
    
    https://shibboleth.atlassian.net/browse/IDP-2044
    
    Having removed the deprecated (initializeWithScriptException) method
    make the factory methods throw ComponentInitalizationException
    as well.
    
    These are only used as beans and in tests.
---
 .../profile/context/logic/ScriptedPredicate.java   | 17 +++---
 .../navigate/ScriptedContextLookupFunction.java    | 61 ++++++++++++++--------
 .../context/logic/ScriptedPredicateTest.java       |  5 +-
 .../ScriptedContextLookupFunctionTest.java         |  8 +--
 4 files changed, 58 insertions(+), 33 deletions(-)

diff --git a/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/ScriptedPredicate.java b/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/ScriptedPredicate.java
index fbd4ba5..8c15267 100644
--- a/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/ScriptedPredicate.java
+++ b/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/ScriptedPredicate.java
@@ -28,6 +28,7 @@ import org.opensaml.profile.context.ProfileRequestContext;
 
 import net.shibboleth.shared.annotation.ParameterName;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.resource.Resource;
 import net.shibboleth.shared.scripting.EvaluableScript;
 
@@ -74,13 +75,14 @@ public class ScriptedPredicate
      * @return the predicate
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull public static ScriptedPredicate resourceScript(@Nonnull @NotEmpty final String engineName,
-            @Nonnull final Resource resource) throws ScriptException, IOException {
+            @Nonnull final Resource resource) throws ScriptException, IOException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(resource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedPredicate(script, resource.getDescription());
     }
 
@@ -91,9 +93,10 @@ public class ScriptedPredicate
      * @return the predicate
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull public static ScriptedPredicate resourceScript(@Nonnull final Resource resource)
-            throws ScriptException, IOException {
+            throws ScriptException, IOException, ComponentInitializationException {
         return resourceScript(DEFAULT_ENGINE, resource);
     }
 
@@ -104,13 +107,14 @@ public class ScriptedPredicate
      * @param engineName the language
      * @return the predicate
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull public static ScriptedPredicate inlineScript(@Nonnull @NotEmpty final String engineName,
-            @Nonnull @NotEmpty final String scriptSource) throws ScriptException {
+            @Nonnull @NotEmpty final String scriptSource) throws ScriptException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(scriptSource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedPredicate(script, "Inline");
     }
 
@@ -120,9 +124,10 @@ public class ScriptedPredicate
      * @param scriptSource the script, as a string
      * @return the predicate
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull public static ScriptedPredicate inlineScript(@Nonnull @NotEmpty final String scriptSource)
-            throws ScriptException {
+            throws ScriptException, ComponentInitializationException {
         return inlineScript(DEFAULT_ENGINE, scriptSource);
     }
 
diff --git a/shib-profile-api/src/main/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunction.java b/shib-profile-api/src/main/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunction.java
index 8b86f3d..38e3c4a 100644
--- a/shib-profile-api/src/main/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunction.java
+++ b/shib-profile-api/src/main/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunction.java
@@ -25,6 +25,7 @@ import javax.script.ScriptContext;
 import javax.script.ScriptException;
 
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.resource.Resource;
 import net.shibboleth.shared.scripting.AbstractScriptEvaluator;
@@ -122,11 +123,12 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> resourceScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull final Resource resource) throws ScriptException,
-            IOException {
+            IOException, ComponentInitializationException {
         return resourceScript(engineName, resource, null);
     }
 
@@ -140,15 +142,16 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> resourceScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull final Resource resource,
-            @Nullable final Class<?> outputType) throws ScriptException, IOException {
+            @Nullable final Class<?> outputType) throws ScriptException, IOException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(resource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedContextLookupFunction<>(ProfileRequestContext.class, script, resource.getDescription(),
             outputType);
     }
@@ -160,10 +163,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> resourceScript(@Nonnull final Resource resource)
-            throws ScriptException, IOException {
+            throws ScriptException, IOException, ComponentInitializationException {
         return resourceScript(DEFAULT_ENGINE, resource, null);
     }
 
@@ -176,10 +180,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> resourceScript(@Nonnull final Resource resource,
-            @Nullable final Class<?> outputType) throws ScriptException, IOException {
+            @Nullable final Class<?> outputType) throws ScriptException, IOException, ComponentInitializationException {
         return resourceScript(DEFAULT_ENGINE, resource, outputType);
     }
 
@@ -190,15 +195,16 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param engineName the language
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> inlineScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull @NotEmpty final String scriptSource)
-            throws ScriptException {
+            throws ScriptException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(scriptSource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedContextLookupFunction<>(ProfileRequestContext.class, script, "Inline");
     }
 
@@ -210,15 +216,16 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param outputType the type to test against.
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> inlineScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull @NotEmpty final String scriptSource,
-            @Nullable final Class<?> outputType) throws ScriptException {
+            @Nullable final Class<?> outputType) throws ScriptException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(scriptSource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedContextLookupFunction<>(ProfileRequestContext.class, script, "Inline", outputType);
     }
 
@@ -228,10 +235,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param scriptSource the script, as a string
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> inlineScript(
-            @Nonnull @NotEmpty final String scriptSource) throws ScriptException {
+            @Nonnull @NotEmpty final String scriptSource) throws ScriptException, ComponentInitializationException {
         return inlineScript(DEFAULT_ENGINE, scriptSource);
     }
 
@@ -242,10 +250,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param outputType the type to test against.
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<ProfileRequestContext> inlineScript(
-            @Nonnull @NotEmpty final String scriptSource, @Nullable final Class<?> outputType) throws ScriptException {
+            @Nonnull @NotEmpty final String scriptSource, @Nullable final Class<?> outputType) throws ScriptException, ComponentInitializationException {
         return inlineScript(DEFAULT_ENGINE, scriptSource, outputType);
     }
 
@@ -257,11 +266,12 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> resourceMessageContextScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull final Resource resource) throws ScriptException,
-            IOException {
+            IOException, ComponentInitializationException {
         return resourceMessageContextScript(engineName, resource, null);
     }
 
@@ -274,15 +284,16 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> resourceMessageContextScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull final Resource resource,
-            @Nullable final Class<?> outputType) throws ScriptException, IOException {
+            @Nullable final Class<?> outputType) throws ScriptException, IOException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(resource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedContextLookupFunction<>(MessageContext.class, script, resource.getDescription(),
                 outputType);
     }
@@ -294,10 +305,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> resourceMessageContextScript(
-            @Nonnull final Resource resource) throws ScriptException, IOException {
+            @Nonnull final Resource resource) throws ScriptException, IOException, ComponentInitializationException {
         return resourceMessageContextScript(DEFAULT_ENGINE, resource, null);
     }
 
@@ -309,10 +321,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @return the function
      * @throws ScriptException if the compile fails
      * @throws IOException if the file doesn't exist.
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> resourceMessageContextScript(
-            @Nonnull final Resource resource, @Nullable final Class<?> outputType) throws ScriptException, IOException {
+            @Nonnull final Resource resource, @Nullable final Class<?> outputType) throws ScriptException, IOException, ComponentInitializationException {
         return resourceMessageContextScript(DEFAULT_ENGINE, resource, outputType);
     }
 
@@ -323,15 +336,16 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param engineName the language
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> inlineMessageContextScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull @NotEmpty final String scriptSource)
-            throws ScriptException {
+            throws ScriptException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(scriptSource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedContextLookupFunction<>(MessageContext.class, script, "Inline");
     }
 
@@ -343,15 +357,16 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param outputType the type to test against.
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> inlineMessageContextScript(
             @Nonnull @NotEmpty final String engineName, @Nonnull @NotEmpty final String scriptSource,
-            @Nullable final Class<?> outputType) throws ScriptException {
+            @Nullable final Class<?> outputType) throws ScriptException, ComponentInitializationException {
         final EvaluableScript script = new EvaluableScript();
         script.setEngineName(engineName);
         script.setScript(scriptSource);
-        script.initializeWithScriptException();
+        script.initialize();
         return new ScriptedContextLookupFunction<>(MessageContext.class, script, "Inline", outputType);
     }
 
@@ -361,10 +376,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param scriptSource the script, aMessageContexts a string
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> inlineMessageContextScript(
-            @Nonnull @NotEmpty final String scriptSource) throws ScriptException {
+            @Nonnull @NotEmpty final String scriptSource) throws ScriptException, ComponentInitializationException {
         return inlineMessageContextScript(DEFAULT_ENGINE, scriptSource);
     }
 
@@ -375,10 +391,11 @@ public class ScriptedContextLookupFunction<T extends BaseContext> extends Abstra
      * @param outputType the type to test against.
      * @return the function
      * @throws ScriptException if the compile fails
+     * @throws ComponentInitializationException if the scripting initialization fails
      */
     @Nonnull
     public static ScriptedContextLookupFunction<MessageContext> inlineMessageContextScript(
-            @Nonnull @NotEmpty final String scriptSource, @Nullable final Class<?> outputType) throws ScriptException {
+            @Nonnull @NotEmpty final String scriptSource, @Nullable final Class<?> outputType) throws ScriptException, ComponentInitializationException {
         return inlineMessageContextScript(DEFAULT_ENGINE, scriptSource, outputType);
     }
 
diff --git a/shib-profile-api/src/test/java/net/shibboleth/profile/context/logic/ScriptedPredicateTest.java b/shib-profile-api/src/test/java/net/shibboleth/profile/context/logic/ScriptedPredicateTest.java
index d05a134..1f811c2 100644
--- a/shib-profile-api/src/test/java/net/shibboleth/profile/context/logic/ScriptedPredicateTest.java
+++ b/shib-profile-api/src/test/java/net/shibboleth/profile/context/logic/ScriptedPredicateTest.java
@@ -21,6 +21,7 @@ import javax.script.ScriptException;
 
 import net.shibboleth.profile.context.RelyingPartyContext;
 import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.spring.util.ApplicationContextBuilder;
 
 import org.opensaml.profile.context.ProfileRequestContext;
@@ -45,7 +46,7 @@ public class ScriptedPredicateTest {
         noChild = new ProfileRequestContext();
     }
 
-    @Test public void simple() throws ScriptException {
+    @Test public void simple() throws ScriptException, ComponentInitializationException {
         ScriptedPredicate test = ScriptedPredicate.inlineScript("new java.lang.Boolean(true);");
         Assert.assertTrue(test.test(withChild));
 
@@ -59,7 +60,7 @@ public class ScriptedPredicateTest {
         Assert.assertFalse(test.test(withChild));
     }
     
-    @Test public void custom() throws ScriptException {
+    @Test public void custom() throws ScriptException, ComponentInitializationException {
         ScriptedPredicate test = ScriptedPredicate.inlineScript("custom;");
         test.setCustomObject(Boolean.valueOf(true));
         Assert.assertTrue(test.test(withChild));
diff --git a/shib-profile-api/src/test/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunctionTest.java b/shib-profile-api/src/test/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunctionTest.java
index ec4e446..b5e26d3 100644
--- a/shib-profile-api/src/test/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunctionTest.java
+++ b/shib-profile-api/src/test/java/net/shibboleth/profile/context/navigate/ScriptedContextLookupFunctionTest.java
@@ -24,6 +24,8 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import net.shibboleth.shared.component.ComponentInitializationException;
+
 /**
  * Unit test for {@link ScriptedContextLookupFunction}.
  */
@@ -33,7 +35,7 @@ public class ScriptedContextLookupFunctionTest {
     static final String STRING_RETURN = "JavaString=Java.type(\"java.lang.String\"); new JavaString(\"String\");";
     static final String INTEGER_RETURN = "JavaInteger=Java.type(\"java.lang.Integer\"); new JavaInteger(37);";
        
-    @Test public void simpleScript() throws ScriptException {
+    @Test public void simpleScript() throws ScriptException, ComponentInitializationException {
         final ProfileRequestContext prc = new ProfileRequestContext();
         
         final Object string = ScriptedContextLookupFunction.inlineScript(STRING_RETURN).apply(prc);
@@ -45,7 +47,7 @@ public class ScriptedContextLookupFunctionTest {
         Assert.assertEquals(integer.intValue(), 37);
     }
     
-    @Test public void custom() throws ScriptException {
+    @Test public void custom() throws ScriptException, ComponentInitializationException {
         final ProfileRequestContext prc = new ProfileRequestContext();
         
         final ScriptedContextLookupFunction<ProfileRequestContext> script =
@@ -76,7 +78,7 @@ public class ScriptedContextLookupFunctionTest {
         
     }
 
-    @Test public void messageContext() throws ScriptException {
+    @Test public void messageContext() throws ScriptException, ComponentInitializationException {
         final ScriptedContextLookupFunction<MessageContext> script1 =
                 ScriptedContextLookupFunction.inlineMessageContextScript(STRING_RETURN, Object.class);
         

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


More information about the commits mailing list