在jhipster中使用ROLES? [英] Using ROLES in jhipster?

查看:62
本文介绍了在jhipster中使用ROLES?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在jhipster中添加和更改角色.首先,我只是尝试将一个用例的角色从用户更改为admin.然后,我对其进行了测试,即使角色是ROLE_ADMIN,用户也可以添加员工,因此它没有任何更改.

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.

我还添加了一个新角色,称为MANAGER.我编辑了AuthoritiesConstants.java,并向JHI_AUTHORITY表添加了新角色.我应该做些其他事情还是足以使它正常工作?

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');
                })
            }]
        })

推荐答案

编辑以下6个文件以包括/排除块中指定的代码以添加/删除角色(以ROLE_MANAGER为例)

  1. AuthoritiesConstants.java(常量,将在Java中使用)

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

公共静态最终字符串MANAGER ="ROLE_MANAGER";

public static final String MANAGER = "ROLE_MANAGER";

  • src/main/resources/config/liquibase/authorities.csv(适当的液基更新)

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

    ROLE_MANAGER

    ROLE_MANAGER

  • src/main/resources/config/liquibase/users.csv(添加用户名:管理员,密码:用户)

  • 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

    5;manager;$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K;Manager;Manager;manager@localhost;true;en;system

  • src/main/resources/config/liquibase/users_authorities.csv(另一种适当的液基更新)

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

    5; ROLE_MANAGER

    5;ROLE_MANAGER

  • src/main/webapp/app/admin/user-management/user-management.controller.js(以使角色在JavaScript中可用)

  • 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(以使角色在JavaScript中可用)

  • 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" ];

  • 一切就绪后,重新启动服务器,并在应用程序启动后再次检查JHI_AUTHORITY和JHI_USER_AUTHORITY表,以找到新的ROLE_MANAGER.使用用户名:"manager"和密码:"user"登录系统.

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

    这篇关于在jhipster中使用ROLES?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆