根据权限更改Jhipster登录页
我已经看到有人可以通过包含这个来改变Jhipster的登录页根据权限更改Jhipster登录页,jhipster,Jhipster,我已经看到有人可以通过包含这个来改变Jhipster的登录页 registerAuthenticationSuccess() { this.eventManager.subscribe('authenticationSuccess', (message) => { this.principal.identity().then((account) => { if (account.authorities.indexOf('ROLE_CONTRA
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中,一旦我们登录,默认情况下它会转到HomeComponent。在您的情况下,它会失败,因为只有角色_ADMIN可以访问HomeComponent。因此,很明显,它将不允许角色为_CONTRACTOR的用户登录,它将在调用您编写路由器导航代码的方法之前被重定向到未经授权的页面
因此,请尝试从路由路径中删除权限:['ROLE\u ADMIN'],这样它将允许所有用户访问HomeComponent,如果用户使用ROLE\u CONTRACTOR,它将重定向到属性页。如果我允许home.component中的所有角色,它将加载主页而不重定向。我想根据角色重定向,然后再转到主页。我尝试在登录页面中执行此操作,但不起作用。