[英]Jhipster: hide entities from non-admin
Greetings java hipsters! 问候java赶时髦的人!
I just generated a jhipster project and created some entities. 我刚刚创建了一个jhipster项目并创建了一些实体。 I'd like to hide some entities by restricting them to only the admin user.
我想通过将它们限制为仅限管理员用户来隐藏某些实体。 How do I achieve this ?
我该如何实现这一目标?
Thanks! 谢谢!
First read Spring Security doc then look at your project source code that was generated by JHipster: it's full of such examples, pay attention to: 首先阅读Spring Security doc然后看看你的项目源代码是由JHipster生成的:它充满了这样的例子,注意:
SecurityConfiguration.java
@Secured(AuthoritiesConstants.ADMIN)
in UserResource.java
@Secured(AuthoritiesConstants.ADMIN)
在UserResource.java
Then for the angular part, you can add a requirement for admin role in a state's definition like in src/main/webapp/app/admin/configuration/configuration.state.js
(search for authorities: ['ROLE_ADMIN']
). 然后对于角度部分,您可以在状态定义中添加管理角色的要求,例如在
src/main/webapp/app/admin/configuration/configuration.state.js
(搜索for authorities: ['ROLE_ADMIN']
)。 So for a bank-account
entity, main state would be defined in src/main/webapp/app/entities/bank-account/bank-account.state.js
. 因此,对于
bank-account
实体,主要状态将在src/main/webapp/app/entities/bank-account/bank-account.state.js
。
This is for JHipster 3.x 这是针对JHipster 3.x的
I just describe how i blocked new entity("folder") on a bit more fresh version (JHipster 4.7.0): 我只是描述了我如何在一个更新鲜的版本(JHipster 4.7.0)上阻止新实体(“文件夹”):
to block access to endpoint I added new line in a file: src/main/java/package path/config/SecurityConfiguration.java : 阻止访问端点我在文件中添加了新行: src / main / java / package path / config / SecurityConfiguration.java :
.antMatchers("/api/profile-info").permitAll()
.antMatchers("/api/folders").hasAuthority(AuthoritiesConstants.ADMIN) //new line
.antMatchers("/api/**").authenticated()
change src/main/webapp/app/entities/folder/folder.route.ts : 更改src / main / webapp / app / entities / folder / folder.route.ts :
data: {
authorities: ['ROLE_USER'], // old
authorities: ['ROLE_ADMIN'],// new
pageTitle: 'jmediaApp.folder.home.title'
},
and to hide item from navbar you need to add *jhiHasAnyAuthority="'ROLE_ADMIN'"
in <li>
tag in /src/main/webapp/app/layouts/navbar/navbar.component.html : 并从导航栏隐藏的项目,你需要添加
*jhiHasAnyAuthority="'ROLE_ADMIN'"
在<li>
标记中/src/main/webapp/app/layouts/navbar/navbar.component.html:
<li *jhiHasAnyAuthority="'ROLE_ADMIN'">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.