根据Authority更改Jhipster登录页面

问题描述 投票:1回答:1

我已经看到可以通过包含这个来改变Jhipster登陆页面,

registerAuthenticationSuccess() {
    this.eventManager.subscribe('authenticationSuccess', (message) => {
        this.principal.identity().then((account) => {
         if (account.authorities.indexOf('ROLE_CONTRACTOR') >=0)
        {
            this.router.navigate(['/property']);
        }
        else
        {
            this.account = account;
        }
        });
    });
}

在home.component.ts中,并在onInit方法中调用它,

this.principal.identity().then((account) => {
        this.account = account;
    });
    this.registerAuthenticationSuccess();

但是,就我而言,这不起作用。在我的主页中,我只定义了管理权限,以便能够访问route.ts文件中的主页,如下所示,

export const HOME_ROUTE: Route = {  path: '',  component: HomeComponent, data: {    authorities: ['ROLE_ADMIN'],    pageTitle: 'home.title'  },  canActivate: [UserRouteAccessService]};

但是当我作为承包商登录时,我被重定向到登录页面,说我没有权限进入主页。它不会被重定向到属性页面。

jhipster
1个回答
1
投票

我想,在Jhipster中我们登录后默认情况下会转到HomeComponent。在您的情况下它失败,因为只有ROLE_ADMIN可以访问HomeComponent。所以很明显它不允许有ROLE_CONTRACTOR的用户登录,在调用编写路由器导航代码的方法之前,它将被重定向到未授权的页面。

因此,尝试从路径路径中删除权限:['ROLE_ADMIN'],因此它将允许所有用户访问HomeComponent,如果用户使用ROLE_CONTRACTOR,它将重定向到属性页。

© www.soinside.com 2019 - 2024. All rights reserved.