我已经使用mongo数据库的generator-jhipster创建了一个项目。@Secured(“<new_role>”)显示access_denied
我想添加在JHI_AUTHORITY
一个新的角色,所以我已经在蒙戈{"_id" : "ROLE_MANAGER"}
插入一个新的纪录JHI_AUTHORITY
文件现在我想,只有用两种ROLE_ADMIN
或ROLE_MANAGER
用户被授权的API之一。 所以我在API中添加以下LOC:
@secured({"ROLE_ADMIN", "ROLE_MANAGER"})
但是,当我试图与具有角色的用户访问API:ROLE_ADMIN
它的伟大工程,但与用户有角色:ROLE_MANAGER
,它显示我的错误:
{ "error": "access_denied", "error_description": "Access is denied" }
请让我知道是否有任何遗漏的步骤?
安全配置类别如下:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Inject
private UserDetailsService userDetailsService;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Inject
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/scripts/**/*.{js,html}")
.antMatchers("/bower_components/**")
.antMatchers("/i18n/**")
.antMatchers("/assets/**")
.antMatchers("/swagger-ui.html")
.antMatchers("/api/register")
.antMatchers("/api/activate")
.antMatchers("/api/account/reset_password/init")
.antMatchers("/api/account/reset_password/finish")
.antMatchers("/test/**");
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
return new SecurityEvaluationContextExtension();
}
}
请显示您的安全配置类 –
@GaëlMarziou我在我的问题中添加了安全配置类。请参阅更新。 –