Spring 如何在.antmatchers.access()中使用常量
我想在Spring 如何在.antmatchers.access()中使用常量,spring,spring-security,Spring,Spring Security,我想在.antmatchers.access()中使用authoritiesconts.java中的一些常量: .antMatchers(“/first/**”).access(“hasAuthority('ROLE\u ALL')和hasAuthority('ROLE\u ME')”) 它可以工作,但我希望使用常量ALL: public static final String ALL=“ROLE\u ALL” 我试过: .antMatchers(“/first/**”).access(“has
.antmatchers.access()中使用authoritiesconts.java
中的一些常量:
.antMatchers(“/first/**”).access(“hasAuthority('ROLE\u ALL')和hasAuthority('ROLE\u ME')”)
它可以工作,但我希望使用常量ALL:
public static final String ALL=“ROLE\u ALL”代码>
我试过:
.antMatchers(“/first/**”).access(“hasAuthority('AuthoritiesConstants.ALL')代码>
但这不起作用
请帮助这不起作用,因为它实际上没有引用常量。它假定AuthoritiesConstants.ALL'
只是一个字符串文本,并按此进行计算
.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')");
您可以尝试使用以下方法:
.antMatchers("/first/**").hasAuthority(AuthoritiesConstants.ALL);
或者,如果需要引用access表达式中的常量,可以使用以下语法:access(“hasAuthority(T(com.example.AuthoritiesConstants.ALL)和…”
,其中com.example.
是包含AuthoritiesConstants
类的包。这是可行的,但我想在.access:.antMatchers中添加条件(“/first/**”).access(“hasAuthority('ROLE_ALL')和hasAuthority('ROLE_ME')”)。如何使用”和“是的,这是有效的。非常感谢。我以前试图找到答案,但从未见过使用“T”。