2
pom.xml
2
pom.xml
@@ -41,7 +41,7 @@
|
|||||||
<netty.version>4.1.121.Final</netty.version>
|
<netty.version>4.1.121.Final</netty.version>
|
||||||
<okhttp3.version>3.14.9</okhttp3.version>
|
<okhttp3.version>3.14.9</okhttp3.version>
|
||||||
<spring.version>6.2.6</spring.version>
|
<spring.version>6.2.6</spring.version>
|
||||||
<spring-data-bom.version>2023.1.2</spring-data-bom.version>
|
<spring-data-bom.version>2025.0.0-RC1</spring-data-bom.version>
|
||||||
<spring-security-bom.version>6.4.5</spring-security-bom.version>
|
<spring-security-bom.version>6.4.5</spring-security-bom.version>
|
||||||
<reactor.version>2024.0.5</reactor.version>
|
<reactor.version>2024.0.5</reactor.version>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.vault.repository.mapping;
|
package org.springframework.vault.repository.mapping;
|
||||||
|
|
||||||
|
import org.springframework.data.expression.ValueExpression;
|
||||||
|
import org.springframework.data.expression.ValueExpressionParser;
|
||||||
import org.springframework.data.keyvalue.core.mapping.AnnotationBasedKeySpaceResolver;
|
import org.springframework.data.keyvalue.core.mapping.AnnotationBasedKeySpaceResolver;
|
||||||
import org.springframework.data.keyvalue.core.mapping.BasicKeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.BasicKeyValuePersistentEntity;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
|
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
|
||||||
@@ -24,6 +26,7 @@ import org.springframework.expression.ParserContext;
|
|||||||
import org.springframework.expression.common.LiteralExpression;
|
import org.springframework.expression.common.LiteralExpression;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,11 +38,11 @@ import org.springframework.util.StringUtils;
|
|||||||
public class BasicVaultPersistentEntity<T> extends BasicKeyValuePersistentEntity<T, VaultPersistentProperty>
|
public class BasicVaultPersistentEntity<T> extends BasicKeyValuePersistentEntity<T, VaultPersistentProperty>
|
||||||
implements VaultPersistentEntity<T> {
|
implements VaultPersistentEntity<T> {
|
||||||
|
|
||||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
private static final ValueExpressionParser PARSER = ValueExpressionParser.create();
|
||||||
|
|
||||||
private final String backend;
|
private final String backend;
|
||||||
|
|
||||||
private final @Nullable Expression backendExpression;
|
private final @Nullable ValueExpression backendExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new {@link BasicVaultPersistentEntity}.
|
* Creates new {@link BasicVaultPersistentEntity}.
|
||||||
@@ -86,10 +89,9 @@ public class BasicVaultPersistentEntity<T> extends BasicKeyValuePersistentEntity
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Expression detectExpression(String potentialExpression) {
|
private static ValueExpression detectExpression(String potentialExpression) {
|
||||||
|
ValueExpression expression = PARSER.parse(potentialExpression);
|
||||||
Expression expression = PARSER.parseExpression(potentialExpression, ParserContext.TEMPLATE_EXPRESSION);
|
return expression.isLiteral() ? null : expression;
|
||||||
return expression instanceof LiteralExpression ? null : expression;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,7 +104,8 @@ public class BasicVaultPersistentEntity<T> extends BasicKeyValuePersistentEntity
|
|||||||
|
|
||||||
return this.backendExpression == null //
|
return this.backendExpression == null //
|
||||||
? this.backend //
|
? this.backend //
|
||||||
: this.backendExpression.getValue(getEvaluationContext(null), String.class);
|
: ObjectUtils.nullSafeToString(this.backendExpression
|
||||||
|
.evaluate(getValueEvaluationContext(null, backendExpression.getExpressionDependencies())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.data.repository.query.DefaultParameters;
|
import org.springframework.data.repository.query.DefaultParameters;
|
||||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
||||||
|
import org.springframework.data.repository.query.ParametersSource;
|
||||||
import org.springframework.data.repository.query.parser.PartTree;
|
import org.springframework.data.repository.query.parser.PartTree;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.vault.repository.mapping.VaultMappingContext;
|
import org.springframework.vault.repository.mapping.VaultMappingContext;
|
||||||
@@ -191,7 +192,7 @@ class VaultQueryCreatorUnitTests {
|
|||||||
VaultQuery createQuery(String methodName, String value) {
|
VaultQuery createQuery(String methodName, String value) {
|
||||||
|
|
||||||
DefaultParameters defaultParameters = new DefaultParameters(
|
DefaultParameters defaultParameters = new DefaultParameters(
|
||||||
ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", String.class));
|
ParametersSource.of(ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", String.class)));
|
||||||
|
|
||||||
PartTree partTree = new PartTree(methodName, Credentials.class);
|
PartTree partTree = new PartTree(methodName, Credentials.class);
|
||||||
VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
|
VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
|
||||||
@@ -203,7 +204,7 @@ class VaultQueryCreatorUnitTests {
|
|||||||
VaultQuery createQuery(String methodName, List<String> value) {
|
VaultQuery createQuery(String methodName, List<String> value) {
|
||||||
|
|
||||||
DefaultParameters defaultParameters = new DefaultParameters(
|
DefaultParameters defaultParameters = new DefaultParameters(
|
||||||
ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", List.class));
|
ParametersSource.of(ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", List.class)));
|
||||||
|
|
||||||
PartTree partTree = new PartTree(methodName, Credentials.class);
|
PartTree partTree = new PartTree(methodName, Credentials.class);
|
||||||
VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
|
VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
|
||||||
@@ -214,8 +215,8 @@ class VaultQueryCreatorUnitTests {
|
|||||||
|
|
||||||
VaultQuery createQuery(String methodName, String value, String anotherValue) {
|
VaultQuery createQuery(String methodName, String value, String anotherValue) {
|
||||||
|
|
||||||
DefaultParameters defaultParameters = new DefaultParameters(
|
DefaultParameters defaultParameters = new DefaultParameters(ParametersSource
|
||||||
ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", String.class, String.class));
|
.of(ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", String.class, String.class)));
|
||||||
|
|
||||||
PartTree partTree = new PartTree(methodName, Credentials.class);
|
PartTree partTree = new PartTree(methodName, Credentials.class);
|
||||||
VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
|
VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
|
||||||
|
|||||||
Reference in New Issue
Block a user