2016-07-14 35 views
2

问候java赶时髦的人!Jhipster:隐藏非管理实体

我刚刚生成了一个jhipster项目并创建了一些实体。我想通过限制他们只有管理员用户隐藏一些实体。我如何实现这一目标?

谢谢!

回答

6

首先阅读Spring Security doc再看看,是由JHipster生成项目源代码:它充满了这样的例子,注意:

  • SecurityConfiguration.java
  • @Secured(AuthoritiesConstants.ADMIN)UserResource.java

然后对于角度部分,您可以在状态定义中添加管理角色的要求,如src/main/webapp/app/admin/configuration/configuration.state.js(搜索for authorities: ['ROLE_ADMIN'])。因此对于bank-account实体,主状态将在src/main/webapp/app/entities/bank-account/bank-account.state.js中定义。

这是JHipster 3.X

+0

还有一件事:为了隐藏菜单中的实体,请查看navbar.html - 隐藏非管理员已经实现了一些菜单项。您只需将 has-authority =“ROLE_ADMIN” 添加到菜单元素即可。 – Daddy32

0

我只是描述我如何阻止新的实体(“文件夹”)上多一点新鲜的版本(4.7.0 JHipster):

阻止访问端点我在一个文件中添加新行:的src/main/JAVA /包路径/配置/ SecurityConfiguration.java

.antMatchers("/api/profile-info").permitAll() 
.antMatchers("/api/folders").hasAuthority(AuthoritiesConstants.ADMIN) //new line 
.antMatchers("/api/**").authenticated() 

变化的src /主/ web应用/应用/实体/文件夹/ folder.route。 ts

<li *jhiHasAnyAuthority="'ROLE_ADMIN'"> 
:从您需要添加 *jhiHasAnyAuthority="'ROLE_ADMIN'"<li>标签在 /src/main/webapp/app/layouts/navbar/navbar.component.html导航栏

data: { 
    authorities: ['ROLE_USER'], // old 
    authorities: ['ROLE_ADMIN'],// new 
    pageTitle: 'jmediaApp.folder.home.title' 
}, 

和隐藏项目