【问题标题】:Roles in Jhipster 4Jhipster 4 中的角色
【发布时间】:2018-09-17 15:55:54
【问题描述】:

我正在使用 jhipster 4,我有疑问,我尝试放置一个没有模式 ROLE_* 的新角色,但当我使用java 注释 @Secured

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

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

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

当 webclient 使用角色 SUPERVISED 发出请求时,该操作被拒绝

为什么会这样?

【问题讨论】:

  • 你试过什么?这应该只是不特定于 JHipster 的 spring 安全配置。 stackoverflow.com/questions/38134121/…
  • 是的,你是正确的,但环境是这个 jhipster。我谈到 jhipster 是因为它可能会注入一些额外的配置

标签: java spring-security jhipster


【解决方案1】:

当使用@Secured注解时,默认情况下如果提供的角色不以ROLE_开头,那么它将被添加。过滤器正在检查 ROLE_SUPERVISED 而不是 SUPERVISED,这就是它没有按预期工作的原因。

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

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

【讨论】:

    猜你喜欢
    • 2015-12-02
    • 1970-01-01
    • 2020-08-04
    • 1970-01-01
    • 2017-06-19
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多