[java-shib-shared] branch main updated: Remove a deprecated base class and rename Ex version back.
Scott Cantor
cantor.2 at osu.edu
Wed Sep 14 16:41:30 UTC 2022
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=af8adc89e2ddf50eabaca78b25bf02f8e33991f2
The following commit(s) were added to refs/heads/main by this push:
new af8adc89 Remove a deprecated base class and rename Ex version back.
af8adc89 is described below
commit af8adc89e2ddf50eabaca78b25bf02f8e33991f2
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Sep 14 12:40:13 2022 -0400
Remove a deprecated base class and rename Ex version back.
---
.../util/AbstractSpringExpressionEvaluator.java | 101 ++++--------
.../util/AbstractSpringExpressionEvaluatorEx.java | 182 ---------------------
.../spring/util/SpringExpressionBiConsumer.java | 2 +-
.../spring/util/SpringExpressionBiFunction.java | 2 +-
.../spring/util/SpringExpressionBiPredicate.java | 2 +-
.../ext/spring/util/SpringExpressionConsumer.java | 2 +-
.../ext/spring/util/SpringExpressionFunction.java | 2 +-
.../ext/spring/util/SpringExpressionPredicate.java | 2 +-
8 files changed, 42 insertions(+), 253 deletions(-)
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluator.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluator.java
index b241928b..6faede85 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluator.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluator.java
@@ -36,14 +36,9 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
* A component that evaluates a Spring EL expression against a set of inputs
* and returns the result.
*
- * @param <T> type of input
- * @param <U> type of output
- *
- * @since 5.4.0
- * @deprecated
+ * @since 6.1.0
*/
- at Deprecated(forRemoval=true, since="6.1.0")
-public abstract class AbstractSpringExpressionEvaluator<T, U> {
+public abstract class AbstractSpringExpressionEvaluator {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractSpringExpressionEvaluator.class);
@@ -55,17 +50,13 @@ public abstract class AbstractSpringExpressionEvaluator<T, U> {
@Nullable private Object customObject;
/** The output type. */
- @Nullable private Class<U> outputType;
-
- /** The input type. */
- @Nullable private Class<T> inputType;
-
+ @Nullable private Class<?> outputType;
/** Whether to raise runtime exceptions if expression fails. */
private boolean hideExceptions;
/** Value to return from predicate when an error occurs. */
- @Nullable private U returnOnError;
+ @Nullable private Object returnOnError;
/**
* Constructor.
@@ -78,40 +69,31 @@ public abstract class AbstractSpringExpressionEvaluator<T, U> {
"Expression cannot be null or empty");
}
- /**
- * Set the output type to be enforced.
- *
- * @param type output type
- */
- public void setOutputType(@Nullable final Class<U> type) {
- outputType = type;
- }
-
/**
* Get the output type to be enforced.
*
* @return output type
*/
- @Nullable protected Class<U> getOutputType() {
+ @Nullable protected Class<?> getOutputType() {
return outputType;
}
/**
- * Get the input type to be enforced.
- *
- * @return input type
+ * Set the output type to be enforced.
+ *
+ * @param type output type
*/
- @Nullable public Class<T> getInputType() {
- return inputType;
+ protected void setOutputType(@Nullable final Class<?> type) {
+ outputType = type;
}
/**
- * Set the input type to be enforced.
+ * Get the custom (externally provided) object.
*
- * @param type input type
+ * @return the custom object
*/
- public void setInputType(@Nullable final Class<T> type) {
- inputType = type;
+ @Nullable protected Object getCustomObject() {
+ return customObject;
}
/**
@@ -123,16 +105,6 @@ public abstract class AbstractSpringExpressionEvaluator<T, U> {
customObject = object;
}
- /**
- * Get the custom (externally provided) object.
- *
- * @return the custom object
- */
- public Object getCustomObject() {
- return customObject;
- }
-
-
/**
* Set whether to hide exceptions in expression execution (default is false).
*
@@ -143,35 +115,36 @@ public abstract class AbstractSpringExpressionEvaluator<T, U> {
}
/**
- * Set value to return if an error occurs (default is false).
+ * Get value to return if an error occurs.
*
- * @param what value to set
+ * @return value to return
*/
- public void setReturnOnError(final U what) {
- returnOnError = what;
+ @Nullable protected Object getReturnOnError() {
+ return returnOnError;
+ }
+
+ /**
+ * Set value to return if an error occurs.
+ *
+ * @param value value to return
+ */
+ protected void setReturnOnError(@Nullable final Object value) {
+ returnOnError = value;
}
/**
* Evaluate the Spring expression on the provided input.
*
- * @param input input over which to evaluate the expression
- * @return result of applying the expression to the provided input
+ * @param input input arguments
+ *
+ * @return result of applying the expression to the provided inputs
*/
- @SuppressWarnings("unchecked")
- protected U evaluate(@Nullable final T input) {
-
- // Try outside the try so as to preserve derived semantics
- if (null != input && null != getInputType() && !getInputType().isInstance(input)) {
- log.error("Input was type {} which is not an instance of {}", input.getClass(), getInputType());
- throw new ClassCastException("Input was type " + input.getClass() + " which is not an instance of "
- + getInputType());
- }
+ @Nullable protected Object evaluate(@Nullable final Object... input) {
try {
final ExpressionParser parser = new SpelExpressionParser();
final StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("custom", customObject);
- context.setVariable("input", input);
prepareContext(context, input);
final Object output = parser.parseExpression(springExpression).getValue(context);
@@ -188,7 +161,7 @@ public abstract class AbstractSpringExpressionEvaluator<T, U> {
return getOutputType().cast(output);
}
- return (U) output;
+ return output;
} catch (final Exception e) {
log.error("Error evaluating Spring expression", e);
if (hideExceptions) {
@@ -199,13 +172,11 @@ public abstract class AbstractSpringExpressionEvaluator<T, U> {
}
/**
- * Decorate the expression context with any additional content.
+ * Pre-process the script context before execution.
*
- * @param context expression context
- * @param input to predicate
+ * @param context the expression context
+ * @param input the inputs
*/
- protected void prepareContext(@Nonnull final EvaluationContext context, @Nullable final T input) {
-
- }
+ protected abstract void prepareContext(@Nonnull final EvaluationContext context, @Nullable final Object... input);
}
\ No newline at end of file
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluatorEx.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluatorEx.java
deleted file mode 100644
index e7ddf74a..00000000
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/AbstractSpringExpressionEvaluatorEx.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.ext.spring.util;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.expression.EvaluationContext;
-import org.springframework.expression.ExpressionParser;
-import org.springframework.expression.spel.standard.SpelExpressionParser;
-import org.springframework.expression.spel.support.StandardEvaluationContext;
-
-import net.shibboleth.utilities.java.support.annotation.ParameterName;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-
-/**
- * A component that evaluates a Spring EL expression against a set of inputs
- * and returns the result.
- *
- * @since 6.1.0
- */
-public abstract class AbstractSpringExpressionEvaluatorEx {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(AbstractSpringExpressionEvaluatorEx.class);
-
- /** SpEL expression to evaluate. */
- @Nullable private String springExpression;
-
- /** A custom object to inject into the expression context. */
- @Nullable private Object customObject;
-
- /** The output type. */
- @Nullable private Class<?> outputType;
-
- /** Whether to raise runtime exceptions if expression fails. */
- private boolean hideExceptions;
-
- /** Value to return from predicate when an error occurs. */
- @Nullable private Object returnOnError;
-
- /**
- * Constructor.
- *
- * @param expression the expression to evaluate
- */
- public AbstractSpringExpressionEvaluatorEx(
- final @Nonnull @NotEmpty @ParameterName(name="expression") String expression) {
- springExpression = Constraint.isNotNull(StringSupport.trimOrNull(expression),
- "Expression cannot be null or empty");
- }
-
- /**
- * Get the output type to be enforced.
- *
- * @return output type
- */
- @Nullable protected Class<?> getOutputType() {
- return outputType;
- }
-
- /**
- * Set the output type to be enforced.
- *
- * @param type output type
- */
- protected void setOutputType(@Nullable final Class<?> type) {
- outputType = type;
- }
-
- /**
- * Get the custom (externally provided) object.
- *
- * @return the custom object
- */
- @Nullable protected Object getCustomObject() {
- return customObject;
- }
-
- /**
- * Set a custom (externally provided) object.
- *
- * @param object the custom object
- */
- public void setCustomObject(@Nullable final Object object) {
- customObject = object;
- }
-
- /**
- * Set whether to hide exceptions in expression execution (default is false).
- *
- * @param flag flag to set
- */
- public void setHideExceptions(final boolean flag) {
- hideExceptions = flag;
- }
-
- /**
- * Get value to return if an error occurs.
- *
- * @return value to return
- */
- @Nullable protected Object getReturnOnError() {
- return returnOnError;
- }
-
- /**
- * Set value to return if an error occurs.
- *
- * @param value value to return
- */
- protected void setReturnOnError(@Nullable final Object value) {
- returnOnError = value;
- }
-
- /**
- * Evaluate the Spring expression on the provided input.
- *
- * @param input input arguments
- *
- * @return result of applying the expression to the provided inputs
- */
- @Nullable protected Object evaluate(@Nullable final Object... input) {
-
- try {
- final ExpressionParser parser = new SpelExpressionParser();
- final StandardEvaluationContext context = new StandardEvaluationContext();
- context.setVariable("custom", customObject);
- prepareContext(context, input);
- final Object output = parser.parseExpression(springExpression).getValue(context);
-
- if (output == null) {
- return null;
- }
-
- if (null != getOutputType()) {
- if (!getOutputType().isInstance(output)) {
- log.error("Output of type {} was not of type {}", output.getClass(), getOutputType());
- return returnOnError;
- }
-
- return getOutputType().cast(output);
- }
-
- return output;
- } catch (final Exception e) {
- log.error("Error evaluating Spring expression", e);
- if (hideExceptions) {
- return returnOnError;
- }
- throw e;
- }
- }
-
- /**
- * Pre-process the script context before execution.
- *
- * @param context the expression context
- * @param input the inputs
- */
- protected abstract void prepareContext(@Nonnull final EvaluationContext context, @Nullable final Object... input);
-
-}
\ No newline at end of file
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiConsumer.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiConsumer.java
index 2c6cc2c4..c72a557a 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiConsumer.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiConsumer.java
@@ -38,7 +38,7 @@ import net.shibboleth.utilities.java.support.collection.Pair;
*
* @since 6.1.0
*/
-public class SpringExpressionBiConsumer<T,U> extends AbstractSpringExpressionEvaluatorEx
+public class SpringExpressionBiConsumer<T,U> extends AbstractSpringExpressionEvaluator
implements BiConsumer<T,U> {
/** Class logger. */
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiFunction.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiFunction.java
index ccadcbcf..e41218c1 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiFunction.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiFunction.java
@@ -39,7 +39,7 @@ import net.shibboleth.utilities.java.support.collection.Pair;
*
* @since 6.1.0
*/
-public class SpringExpressionBiFunction<T,U,V> extends AbstractSpringExpressionEvaluatorEx
+public class SpringExpressionBiFunction<T,U,V> extends AbstractSpringExpressionEvaluator
implements BiFunction<T,U,V> {
/** Class logger. */
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiPredicate.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiPredicate.java
index 60a8f16d..70398b77 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiPredicate.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionBiPredicate.java
@@ -38,7 +38,7 @@ import net.shibboleth.utilities.java.support.collection.Pair;
*
* @since 6.1.0
*/
-public class SpringExpressionBiPredicate<T,U> extends AbstractSpringExpressionEvaluatorEx
+public class SpringExpressionBiPredicate<T,U> extends AbstractSpringExpressionEvaluator
implements BiPredicate<T,U> {
/** Class logger. */
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionConsumer.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionConsumer.java
index ce4695cf..894248a3 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionConsumer.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionConsumer.java
@@ -36,7 +36,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
*
* @since 6.1.0
*/
-public class SpringExpressionConsumer<T> extends AbstractSpringExpressionEvaluatorEx
+public class SpringExpressionConsumer<T> extends AbstractSpringExpressionEvaluator
implements Consumer<T> {
/** Class logger. */
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionFunction.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionFunction.java
index 5c841fbd..c20b16f1 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionFunction.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionFunction.java
@@ -37,7 +37,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
*
* @since 5.4.0
*/
-public class SpringExpressionFunction<T,U> extends AbstractSpringExpressionEvaluatorEx
+public class SpringExpressionFunction<T,U> extends AbstractSpringExpressionEvaluator
implements Function<T,U> {
/** Class logger. */
diff --git a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionPredicate.java b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionPredicate.java
index 4eccb0de..8e0a7eb4 100644
--- a/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionPredicate.java
+++ b/shib-spring/src/main/java/net/shibboleth/ext/spring/util/SpringExpressionPredicate.java
@@ -35,7 +35,7 @@ import net.shibboleth.utilities.java.support.logic.Predicate;
*
* @since 5.4.0
*/
-public class SpringExpressionPredicate<T> extends AbstractSpringExpressionEvaluatorEx
+public class SpringExpressionPredicate<T> extends AbstractSpringExpressionEvaluator
implements Predicate<T> {
/** Class logger. */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list