Spring security 在sec:authorize access实现中指定多个方法参数
我试图通过扩展WebSecurityExpressionRoot来实现一个自定义方法,以便在sec:autorize taglig中使用,如下所示:Spring security 在sec:authorize access实现中指定多个方法参数,spring-security,taglib,Spring Security,Taglib,我试图通过扩展WebSecurityExpressionRoot来实现一个自定义方法,以便在sec:autorize taglig中使用,如下所示: <sec:authorize access="uiAuthz('allevents', 'myVal')"> ... </sec:authorize> 然而,无论我尝试什么,uiAuthZ方法的参数始终被视为单个字符串参数“'allevents,myVal'” 有没有办法让Spring Security framework
<sec:authorize access="uiAuthz('allevents', 'myVal')">
...
</sec:authorize>
然而,无论我尝试什么,uiAuthZ方法的参数始终被视为单个字符串参数“'allevents,myVal'”
有没有办法让Spring Security framework将它们解析为多个参数
似乎我可以使用StringTokenizer等来处理上述示例中的简单情况,但当我必须传递字符串的ArrayList时,事情会继续进行。您如何将CustomWebExpressionRoot与应用程序集成?为此,您需要确保创建一个注册自定义根的自定义WebExpressionHandler。例如: CustomExpressionHandler.java
public class CustomExpressionHandler extends DefaultWebSecurityExpressionHandler {
@Override
protected SecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication, FilterInvocation fi) {
WebSecurityExpressionRoot root = new CustomWebSecurityExpresssionRoot(authentication, fi);
root.setPermissionEvaluator(this.getPermissionEvaluator());
root.setTrustResolver(new AuthenticationTrustResolverImpl());
root.setRoleHierarchy(this.getRoleHierarchy());
return root;
}
}
security.xml
<http ...>
<expression-handler ref="webExpressionHandler"/>
</http>
<b:bean id="webExpressionHandler"
class="sample.CustomExpressionHandler"/>
你可以在找到一个完整的例子,这很奇怪。我发誓上次没用。我过去和现在都在使用您建议的自定义web ExpersionHandler。这一次,我清理了这个项目,它开始工作了!这似乎是一个用户错误,但我将接受@rob winch给出的答案,因为这确实是正确的方法。
<http ...>
<expression-handler ref="webExpressionHandler"/>
</http>
<b:bean id="webExpressionHandler"
class="sample.CustomExpressionHandler"/>