Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

spring security - Using ROLES in jhipster?

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');
                })
            }]
        })
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Edit the following 6 files to include/exclude code specified in blocks to add/remove a role(ROLE_MANAGER as an example)

  1. AuthoritiesConstants.java (constant to be used in java)

    public static final String MANAGER = "ROLE_MANAGER";

  2. src/main/resources/config/liquibase/authorities.csv (proper liquidbase update)

    ROLE_MANAGER

  3. 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

  4. src/main/resources/config/liquibase/users_authorities.csv (another proper liquidbase update)

    5;ROLE_MANAGER

  5. 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"];

  6. 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'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

2.1m questions

2.1m answers

60 comments

57.0k users

...