我想在 .antmatchers.access(): 中使用 AuthoritiesConstants.java 中的一些常量:

.antMatchers("/first/**").access("hasAuthority('ROLE_ALL') and hasAuthority('ROLE_ME')")

它有效,但我想使用常量 ALL:

public static final String ALL = "ROLE_ALL";

我试过:

.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')");

但这行不通。

请帮忙

请您参考如下方法:

这行不通,因为它实际上并没有引用常量。它假设 'AuthoritiesConstants.ALL' 只是一个 String 文字,并且是这样计算的。

.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')"); 

你可以尝试使用类似的东西:

.antMatchers("/first/**").hasAuthority(AuthoritiesConstants.ALL); 

或者如果您需要在访问表达式中引用常量,您可以使用以下语法:access("hasAuthority(T(com.example.AuthoritiesConstants).ALL) and ...") ,其中 com.example. 是包含 AuthoritiesConstants 类的包。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!