java jhipster-如何添加新角色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27241323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jhipster- how to add a new role
提问by user1880957
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.
我正在尝试在使用 JHipster 生成的项目上添加新角色 (ROLE_REPORTS)。我可以看到需要更新的表(角色、权限和 role_authority 映射),但我不确定如何处理其中的 Java 部分。
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.,)
我可以弄清楚一些点点滴滴,但我担心我的自定义可能会破坏某些设计理念(例如 Swagger API、Spring Security 等)
Has anyone already attempted it and if so any help in the right direction will be highly appreciated.
有没有人已经尝试过,如果是这样,我们将不胜感激。
回答by Rori Stumpf
Add it to security/AuthoritiesConstants.java. and webapps/scripts/contstants.js. In the example below, an authority/role of MANAGER was added.
将其添加到 security/AuthoritiesConstants.java。和 webapps/scripts/contstants.js。在下面的示例中,添加了 MANAGER 的权限/角色。
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:
在 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:
必须将新角色添加到数据库中。例如,authorities.csv:
name
ROLE_ADMIN
ROLE_USER
ROLE_MANAGER
回答by krish
This is will be even easier in 4.5.5
这在 4.5.5 中会更容易
1- Modify AuthoritiesConstants.java
1- 修改 AuthoritiesConstants.java
2- Add new role in authorities.csv file
2- 在 authority.csv 文件中添加新角色
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)
重新运行应用程序,新角色应该出现在界面中(Administration/user management/create a new user)(也许删除应用程序中的target\h2db\db内容会很有用)
回答by Yannard
For Jhipter 4.3 there is this solution:
对于 Jhipter 4.3,有这个解决方案:
- Modify AuthoritiesConstants.java
- Add new role in authorities.csv file
- Update the table JHI_AUTHORITY by including the new role
- Modify user-management-dialog-component.ts located here \webapp\app\admin\user-management
- 修改 AuthoritiesConstants.java
- 在 authority.csv 文件中添加新角色
- 通过包含新角色更新表 JHI_AUTHORITY
- 修改位于 \webapp\app\admin\user-management 的 user-management-dialog-component.ts
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.)
重新运行应用程序。新角色应出现在界面中(管理/用户管理/创建新用户)。(也许删除应用程序中的 target\h2db\db 内容会很有用。)
回答by faizal khan
Adding the values to the authorities.csv wouldnt add those values to the tables directly ,as this is just a value added to table,so there is not differnce in the Liquibase change we will have to add it manually to DB...
将值添加到 authority.csv 不会直接将这些值添加到表中,因为这只是添加到表中的值,因此 Liquibase 更改没有区别,我们必须手动将其添加到数据库中...
回答by Joe King
After editing security/AuthoritiesConstants.java. You can add a new liquibase changelog and add a new app_authorities.csv. As below
编辑 security/AuthoritiesConstants.java 后。您可以添加新的 liquibase 更改日志并添加新的 app_authorities.csv。如下
My app_authorities.csv looks like this.
我的 app_authorities.csv 看起来像这样。
name
ROLE_VENDOR