jhipster- how to add a new role
Add it to security/AuthoritiesConstants.java. and webapps/scripts/contstants.js. In the example below, an authority/role of MANAGER was added.
public final class AuthoritiesConstants {
private AuthoritiesConstants() {
}
public static final String ADMIN = "ROLE_ADMIN";
public static final String USER = "ROLE_USER";
public static final String MANAGER = "ROLE_MANAGER";
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
}
And in constants.js:
myApp.constant('USER_ROLES', {
'all': '*',
'admin': 'ROLE_ADMIN',
'user': 'ROLE_USER',
'manager', 'ROLE_MANAGER'
});
The new role must be added to the database. For example, the authorities.csv:
name
ROLE_ADMIN
ROLE_USER
ROLE_MANAGER
Adding the values to the authorities.csv wouldnt add those values to the tables directly ,as this is just a value added to table,so there is not differnce in the Liquibase change we will have to add it manually to DB...
This is will be even easier in 4.5.5
1- Modify AuthoritiesConstants.java
2- Add new role in authorities.csv file
re-Run the application, the new role should appear in the interface (Administration/user management/create a new user) (maybe it can be useful to delete target\h2db\db content in your app)
For Jhipter 4.3 there is this solution:
- Modify AuthoritiesConstants.java
- Add new role in authorities.csv file
- Update the table JHI_AUTHORITY by including the new role
- Modify user-management-dialog-component.ts located here \webapp\app\admin\user-management
Re-run the application. The new role should appear in the interface (Administration/user management/create a new user). (Maybe it can be useful to delete target\h2db\db content in your app.)