Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何在.antmatchers.access()中使用常量_Spring_Spring Security - Fatal编程技术网

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”。