0

I have a jhipster microservice named as blog and a jhipster gateway. I have created a entity named "Farmer". I have Created below two users in keycloak.

Users: Pradeep and Rahul

1) FOR ROLE_ADMIN

enter image description here

2) For ROLE_USER enter image description here

While Accessing enitity in Admin panel in jhipster gateway, I am getting unauthorized error for admin (Pradeep), whereas for user (rahul) I am able to access entity.

PFB screenshots.

i) Admin Panel Home Page

enter image description here

ii) Admin Entity Page

When admin tries to click on farmer entity below is the error I am getting.

enter image description here

iii) User Home Page

enter image description here

iv) User Entity Page

When user (rahul) tries to access farmer entity he is able to access it.

enter image description here

Please let me know what could be the issue.

Rahul
  • 493
  • 3
  • 7
  • 25

1 Answers1

3

Admin users should also have the ROLE_USER role in order to access entity page. This is because the entity routes are secured by default to the ROLE_USER role.

For example, notice the authorities array in the bank-account.route.ts from the sample app:

  {
    path: '',
    component: BankAccountComponent,
    data: {
      authorities: ['ROLE_USER'],
      pageTitle: 'jhipsterSampleApplicationApp.bankAccount.home.title'
    },
    canActivate: [UserRouteAccessService]
  }, 
Spevacus
  • 584
  • 2
  • 13
  • 23
Jon Ruddell
  • 6,244
  • 1
  • 22
  • 40
  • Instead of giving providing ROLE_USER to the admin users, can we add ROLE_ADMIN along with ROLE_USER in authorities as mentioned in above route.ts file. If yes then how we can achieve it, as I tried but it is not working.Please help me out – Rahul Sep 19 '19 at 18:00
  • If you pass two authorities to the `authorities` array, the user is required to have at least one of the authorities. https://github.com/jhipster/jhipster-sample-app/blob/master/src/main/webapp/app/core/auth/user-route-access-service.ts#L32 – Jon Ruddell Sep 20 '19 at 15:50