Jhipster 4中的角色

时间:2018-04-07 23:00:50

标签: java spring-security jhipster

我正在使用 jhipster 4 ,我有一个疑问,我尝试设置一个没有模式 ROLE _ * 的新角色,当我使用它时它不起作用java注释 @Secured

public final class AuthoritiesConstants {   
  public static final String SUPERVISED = "SUPERVISED";
  ...

我在许多网站上查看了这个问题,我找不到任何建议。我需要设置一个名为 SUPERVISED 的角色,因为我的应用需要与其他人集成。

@Secured({AuthoritiesConstants.SUPERVISED)
public class GreatResource {
...

当webclient执行具有SUPERVISED角色的请求时,拒绝该操作

为什么会这样?

1 个答案:

答案 0 :(得分:1)

使用@Secured注释时,默认情况下,如果提供的角色不以ROLE_开头,则会添加该注释。过滤器正在检查ROLE_SUPERVISED而不是SUPERVISED,这就是为什么它无法正常工作。

使用Expression-Based Access Control,您可以检查用户的权限,包括那些没有ROLE_前缀的权限。使用@PreAuthorize注释与hasAuthority表达式结合使用:

@PreAuthorize("hasAuthority('SUPERVISED')")