在 JHipster v6.4.1 中,我可以在哪里授权新角色访问他们的帐户设置?

In JHipster v6.4.1, where can I put new roles to be authorized to access their account-settings?

虽然我的 ROLE_ROOT 测试用户被允许查看和配置管理任务,并且可以更改密码或在 swagger-[=43 中使用 GET 到 api/account 查看正确的响应正文=],不允许他看到组件 'settings'、'password' 或 'sessions',但可以通过 Angular 导航栏菜单条目获得 Error Page! You are not authorized to access this page.

事实上,我添加了其他角色(ROLE_RUNNER、ROLE_ORGANIZER、ROLE_ROOT)作为 udemy 练习的一部分。我把ROLE_ADMIN的大部分权限改成了ROLE_ROOT。 ROLE_ROOT 不允许查看或更改实体并且 ROLE_ADMIN 不能执行(也看不到)任何管理任务。

我还添加了 ROLE_RUNNER。与 ROLE_USER 一样,不允许他们的成员在后端和前端查看或访问任何内容 - 除了 'home' 和他们的 'account'-menue.

但不知何故,只有 ROLE_ADMIN 和 ROLE_USER,默认的 JHipster 角色,能够通过 Angular 导航栏。我必须在哪里告诉 Spring 也让新角色的成员查看和编辑他们的帐户设置?

代码可以在这里找到:https://github.com/Mesqualito/rfb-loyalty/commit/d3ad5bf3a6a7b0d9926bdcdf99302399faebaf63

对于具有 Angular 前端的 JHipster,授权机制遵循以下模式:

1.) Spring 后端

a.) 在 'SecurityConfiguration.java' 中完全限制对实体的访问,例如.antMatchers("/api/customers").hasAuthority(AuthorityConstants.SELLER) 基于来自 'AuthoritiesConstants.java'

的用户组(角色)

b.) 使用这些 ROLE 和 Spring Secured 注释仅限制对 Controller-Resources 中 Create/Update/Delete-methods 的全部、部分或其中之一的访问,例如在 'UserResource.java'

    @GetMapping("/users/authorities")
    @PreAuthorize("hasRole(\"" + AuthoritiesConstants.ROOT + "\")")
    public List<String> getAuthorities() {...}

c.) 根据后端服务层的用户登录限制对用户数据的访问,例如在 'ProductOrderServiceImpl.java'

    public Page<ProductOrder> findAll(Pageable pageable) {
        if (SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.SELLER))
            { return productOrderRepository.findAll(pageable); }
            else {
              return productOrderRepository.findAllByCustomerUserLogin(
                  SecurityUtils.getCurrentUserLogin().get(), pageable );
             }

2.) Angular 前端

a.) 在 Angular 路由级别,每个组件具有相同的角色,例如在 'settings.route.ts' 和 authorities: ['ROLE_USER','ROLE_ORGANIZER','ROLE_ROOT','ROLE_RUNNER']

b.) 每个 JHipster 指令 *jhiHasAnyAuthority 在任何 html-Element 中具有来自上面的角色,例如在 'navbar.component.html'

    <a *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_ORGANIZER']"
    id="entity-menu">Entities</a>

浏览器控制台显示 401 (Unauthorized),无论 Spring 或 Angular 是否拒绝用户(或 "non-user" ROLE_ANONYMOUS)授权。