我有这样的代码在我的Web安全配置:Spring安全性为所有角色名称添加前缀“ROLE_”?
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/**")
.hasRole("ADMIN")
.and()
.httpBasic().and().csrf().disable();
}
所以我增加了一个用户在我的数据库“ADMIN”的角色,我总是得到403错误,当我tryed洛这个用户,然后我启用日志春天,我发现这条线:
2015-10-18 23:13:24.112 DEBUG 4899 --- [nio-8080-exec-1] o.s.s.w.a.i.FilterSecurityInterceptor : Secure object: FilterInvocation: URL: /api/user/login; Attributes: [hasRole('ROLE_ADMIN')]
为什么春季安全正在寻找“ROLE_ADMIN”,而不是“管理”?
[春季安全角色前缀和自定义用户信息服务(可能的重复http://stackoverflow.com/questions/4951832/spring-security-role-prefix-and-custom -user-details-service) – Bruno