[java-shib-shared] branch main updated: Clean up some validation logic.

Scott Cantor cantor.2 at osu.edu
Thu Jun 15 16:34:17 UTC 2023


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

scantor pushed a commit to branch main
in repository java-shib-shared.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=0a7ea19d052cf1d46626756a7d004ae17995ec7e

The following commit(s) were added to refs/heads/main by this push:
     new 0a7ea19d Clean up some validation logic.
0a7ea19d is described below

commit 0a7ea19d052cf1d46626756a7d004ae17995ec7e
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jun 15 12:34:14 2023 -0400

    Clean up some validation logic.
---
 .../shared/scripting/EvaluableScript.java           | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/shib-support/src/main/java/net/shibboleth/shared/scripting/EvaluableScript.java b/shib-support/src/main/java/net/shibboleth/shared/scripting/EvaluableScript.java
index 828c6f01..f74b6cfb 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/scripting/EvaluableScript.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/scripting/EvaluableScript.java
@@ -41,7 +41,6 @@ import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.component.AbstractInitializableComponent;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
-import net.shibboleth.shared.logic.ConstraintViolationException;
 import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.resource.Resource;
@@ -50,7 +49,7 @@ import net.shibboleth.shared.resource.Resource;
 public final class EvaluableScript extends AbstractInitializableComponent {
 
     /** The scripting language. */
-    @Nonnull @NotEmpty private String scriptLanguage = "javascript";
+    @Nonnull @NotEmpty private String scriptLanguage;
 
     /** The script to execute. */
     @NonnullAfterInit @NotEmpty private String script;
@@ -68,6 +67,7 @@ public final class EvaluableScript extends AbstractInitializableComponent {
      * Constructor.
      */
     public EvaluableScript() {
+        scriptLanguage = "javascript";
     }
 
     /**
@@ -85,10 +85,7 @@ public final class EvaluableScript extends AbstractInitializableComponent {
      * @param what the script source
      */
     public void setScript(@Nonnull @NotEmpty final String what) {
-        script = Constraint.isNotNull(StringSupport.trimOrNull(what), "Script must not be null");
-        if ("".equals(script)) {
-            throw new ConstraintViolationException("Script must be non-empty");
-        }
+        script = Constraint.isNotNull(StringSupport.trimOrNull(what), "Script must not be null or empty");
     }
 
     /**
@@ -113,7 +110,7 @@ public final class EvaluableScript extends AbstractInitializableComponent {
      */
     public void setScript(@Nonnull final File scriptSource) throws IOException {
 
-        Constraint.isNotNull(scriptSource, "Script source should not be null");
+        Constraint.isNotNull(scriptSource, "Script source cannot be null");
 
         if (!scriptSource.exists()) {
             throw new IOException("Script source file " + scriptSource.getAbsolutePath() + " does not exist");
@@ -158,7 +155,7 @@ public final class EvaluableScript extends AbstractInitializableComponent {
      */
     public void setEngineName(@Nonnull @NotEmpty final String what) {
         scriptLanguage = Constraint.isNotNull(StringSupport.trimOrNull(what),
-                "Language must not be null");
+                "Language must not be null or emoty");
     }
 
     /**
@@ -203,12 +200,8 @@ public final class EvaluableScript extends AbstractInitializableComponent {
      */
     protected void doInitialize() throws ComponentInitializationException {
 
-        if ("".equals(scriptLanguage)) {
-            throw new ComponentInitializationException("Language must be non-empty");
-        }
-
-        if ("".equals(script)) {
-            throw new ComponentInitializationException("Sanguage must be non-empty");
+        if (script == null) {
+            throw new ComponentInitializationException("Script cannot be null or empty");
         }
 
         final ScriptEngineManager engineManager = new ScriptEngineManager();

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


More information about the commits mailing list