I tried to add and change roles in jhipster. First I just tried to change one use case's role to admin from user. Then I tested it and user can add employee even if the roles is ROLE_ADMIN so it didn't change anything.
I added new role as well, called MANAGER. I edited AuthoritiesConstants.java and added new role to JHI_AUTHORITY-table. Should I do something else or is this enough to get this working?
state('employee.new', {
parent: 'employee',
url: '/new',
data: {
roles: ['ROLE_ADMIN'],
},
onEnter: ['$stateParams', '$state', '$modal', function($stateParams, $state, $modal) {
$modal.open({
templateUrl: 'scripts/app/entities/employee/employee-dialog.html',
controller: 'EmployeeDialogController',
size: 'lg',
resolve: {
entity: function () {
return {nameFirst: null, nameLast: null, taxNumber: null, isFinnish: null, finnishSOTU: null, valtticard: null, birthDate: null, isContactPerson: null, isTiedonantaja: null, cOTARKENNE: null, id: null};
}
}
}).result.then(function(result) {
$state.go('employee', null, { reload: true });
}, function() {
$state.go('employee');
})
}]
})
Edit the following 6 files to include/exclude code specified in blocks to add/remove a role(ROLE_MANAGER as an example)
AuthoritiesConstants.java (constant to be used in java)
public static final String MANAGER = "ROLE_MANAGER";
src/main/resources/config/liquibase/authorities.csv (proper liquidbase update)
ROLE_MANAGER
src/main/resources/config/liquibase/users.csv (add username: manager with password: user)
5;manager;$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K;Manager;Manager;manager@localhost;true;en;system
src/main/resources/config/liquibase/users_authorities.csv (another proper liquidbase update)
5;ROLE_MANAGER
src/main/webapp/app/admin/user-management/user-management.controller.js (for role to be available in JavaScript)
$scope.authorities = ["ROLE_USER", "ROLE_ADMIN", "ROLE_MANAGER"];
src/main/webapp/app/admin/user-management/user-management-dialog.controller.js (for role to be available in JavaScript)
$scope.authorities = ["ROLE_USER", "ROLE_ADMIN", "ROLE_MANAGER"];
Restart the server once everything is in place and double check JHI_AUTHORITY and JHI_USER_AUTHORITY tables after application launch for a new ROLE_MANAGER to be there. Login into system with username: 'manager' and password: 'user'.