将自定义 SecurityExpressionOperations 中的方法注册为 Spring SpEL 函数
Registering method in custom SecurityExpressionOperations as Spring SpEL function
我有以下 MethodSecurityExpressionOperations
的实现
public class CustomMethodSecurityExpressionRoot extends SecurityExpressionRoot implements MethodSecurityExpressionOperations {
private Object filterObject;
private Object returnObject;
CustomMethodSecurityExpressionRoot(Authentication authentication) {
super(authentication);
}
public boolean isTeamMember(Job job) {
//very interesting logic
}
@Override
public Object getFilterObject() {
return this.filterObject;
}
@Override
public Object getReturnObject() {
return this.returnObject;
}
@Override
public Object getThis() {
return this;
}
@Override
public void setFilterObject(Object obj) {
this.filterObject = obj;
}
@Override
public void setReturnObject(Object obj) {
this.returnObject = obj;
}
}
如您所见,我有一个名为 isTeamMember
的自定义方法。此方法已通过以下预授权注释成功评估:@PreAuthorize("isTeamMember(#job)")
但不幸的是,它未解析为 Spring SpEL 函数。
see the warning
是否有任何 Spring Bootish automagic 方法可以将 isTeamMember
注册为 SPeL 函数?
我想说这是 IntelliJ IDEA 的问题,与 SpEL 中的 Function 支持完全无关:
You can extend SpEL by registering user defined functions that can be called within the expression string.
SpEL、Spring 框架或 Spring 引导端无事可做,因为您所需要的已经通过 CustomMethodSecurityExpressionRoot
.
提供了
您在 WARN 中所拥有的只是一个指针,表明关于 SpEL 评估上下文的根对象的 IDEA 知识超出了您的自定义 CustomMethodSecurityExpressionRoot
范围。
您可能会这样做 #this.isTeamMember(#obj)
或 #root.isTeamMember(#obj)
以获得相同的结果,但同样:函数无关。不要混淆自己。
我有以下 MethodSecurityExpressionOperations
public class CustomMethodSecurityExpressionRoot extends SecurityExpressionRoot implements MethodSecurityExpressionOperations {
private Object filterObject;
private Object returnObject;
CustomMethodSecurityExpressionRoot(Authentication authentication) {
super(authentication);
}
public boolean isTeamMember(Job job) {
//very interesting logic
}
@Override
public Object getFilterObject() {
return this.filterObject;
}
@Override
public Object getReturnObject() {
return this.returnObject;
}
@Override
public Object getThis() {
return this;
}
@Override
public void setFilterObject(Object obj) {
this.filterObject = obj;
}
@Override
public void setReturnObject(Object obj) {
this.returnObject = obj;
}
}
如您所见,我有一个名为 isTeamMember
的自定义方法。此方法已通过以下预授权注释成功评估:@PreAuthorize("isTeamMember(#job)")
但不幸的是,它未解析为 Spring SpEL 函数。
see the warning
是否有任何 Spring Bootish automagic 方法可以将 isTeamMember
注册为 SPeL 函数?
我想说这是 IntelliJ IDEA 的问题,与 SpEL 中的 Function 支持完全无关:
You can extend SpEL by registering user defined functions that can be called within the expression string.
SpEL、Spring 框架或 Spring 引导端无事可做,因为您所需要的已经通过 CustomMethodSecurityExpressionRoot
.
您在 WARN 中所拥有的只是一个指针,表明关于 SpEL 评估上下文的根对象的 IDEA 知识超出了您的自定义 CustomMethodSecurityExpressionRoot
范围。
您可能会这样做 #this.isTeamMember(#obj)
或 #root.isTeamMember(#obj)
以获得相同的结果,但同样:函数无关。不要混淆自己。