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

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

问题描述

我尝试在 jhipster 中添加和更改角色.首先,我只是尝试将一个用例的角色从用户更改为管理员.然后我测试了它,即使角色是 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-table 添加了新角色.我应该做点别的还是这足以让它发挥作用?

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个文件以包含/排除block中指定的代码来添加/删除角色(以ROLE_MANAGER为例)

  1. AuthoritiesConstants.java(在java中使用的常量)

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

public static final String MANAGER = "ROLE_MANAGER";

public static final String MANAGER = "ROLE_MANAGER";

  • src/main/resources/config/liquibase/authorities.csv(正确的liquidbase更新)

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

    ROLE_MANAGER

    ROLE_MANAGER

  • src/main/resources/config/liquibase/users.csv(添加用户名:manager 密码:user)

  • 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(另一个合适的liquidbase更新)

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

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

    $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 中使用角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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