I am trying to add a new role (ROLE_REPORTS) on a project generated using JHipster. I can see the tables that need to be updated (role, authority and role_authority mapping), but I am not sure how to go about the Java part of it.
There a few bits and pieces I can figure out, but I am concerned that my customisation may break some design philosophies (like the Swagger API, Spring Security, etc.,)
Has anyone already attempted it and if so any help in the right direction will be highly appreciated.
JHipster, or “Java Hipster,” is a handy application generator that will create for you a Spring Boot (that's the Java part) and AngularJS (that's the hipster part) application.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With