From cf9900a96cf24db81909cb737db1d568bfc62361 Mon Sep 17 00:00:00 2001 From: Andrey Titov Date: Thu, 1 Feb 2024 10:06:28 +0100 Subject: [PATCH] Use SimpleEvaluationContext instead of StandardEvaluationContext --- .../plugin/utils/SpelExpressionContext.java | 19 +++++++++++-------- .../plugin/utils/SpelExpressionExecutor.java | 9 +-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionContext.java b/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionContext.java index 2d8acf7..91460a8 100644 --- a/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionContext.java +++ b/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionContext.java @@ -3,17 +3,17 @@ import com.onelogin.saml2.Auth; import lombok.var; import org.springframework.context.expression.MapAccessor; -import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.expression.EvaluationContext; +import org.springframework.expression.spel.support.SimpleEvaluationContext; import java.util.HashMap; -import java.util.List; import java.util.Map; -public class SpelExpressionContext extends StandardEvaluationContext { +public class SpelExpressionContext { + private final EvaluationContext evaluationContext; public SpelExpressionContext(Map attributes) { - setRootObject(attributes); - addPropertyAccessor(new MapAccessor()); + evaluationContext = new SimpleEvaluationContext.Builder(new MapAccessor()).withInstanceMethods().withRootObject(attributes).build(); } public SpelExpressionContext(Auth auth) { @@ -31,11 +31,14 @@ public SpelExpressionContext(Auth auth) { attributes.put("nameid", auth.getNameId()); attributes.put("lastassertionid", auth.getLastAssertionId()); - setRootObject(attributes); - addPropertyAccessor(new MapAccessor()); + evaluationContext = new SimpleEvaluationContext.Builder(new MapAccessor()).withRootObject(attributes).build(); } public Map getRootObjectAsMap() { - return (Map) getRootObject().getValue(); + return (Map) evaluationContext.getRootObject().getValue(); + } + + public EvaluationContext getEvaluationContext() { + return evaluationContext; } } diff --git a/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionExecutor.java b/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionExecutor.java index 700ec9c..02185a9 100644 --- a/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionExecutor.java +++ b/saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/utils/SpelExpressionExecutor.java @@ -1,16 +1,9 @@ package jetbrains.buildServer.auth.saml.plugin.utils; -import com.onelogin.saml2.Auth; import lombok.extern.slf4j.Slf4j; import lombok.var; -import org.springframework.context.expression.MapAccessor; -import org.springframework.expression.EvaluationContext; import org.springframework.expression.ParseException; import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.StandardEvaluationContext; - -import java.util.HashMap; -import java.util.Map; @Slf4j public class SpelExpressionExecutor { @@ -29,7 +22,7 @@ public String validate(String expressionString) { public String evaluate(String expressionString, SpelExpressionContext context) { log.debug(String.format("Evaluating expression: %s", expressionString)); var expression = parser.parseExpression(expressionString); - String result = (String) expression.getValue(context); + String result = (String) expression.getValue(context.getEvaluationContext()); log.debug(String.format("Evaluation result: %s", result)); return result; }