Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jhipster- how to add a new role

Tags:

java

jhipster

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.

like image 259
user1880957 Avatar asked Dec 02 '14 03:12

user1880957


People also ask

What is spring boot JHipster?

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.


2 Answers

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 
like image 105
Rori Stumpf Avatar answered Sep 19 '22 00:09

Rori Stumpf


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)

like image 28
krish Avatar answered Sep 20 '22 00:09

krish