异常报错
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Apr 13 10:14:58 CST 2020
There was an unexpected error (type=Forbidden, status=403).
Forbidden
解决方案
原因是定义的角色名称不匹配
路径权限规则匹配中配置的是:ADMIN ,不可以配置ROLE_开头的角色 不然直接报BUG
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
//不能加ROLE_前缀
.antMatchers("/**").hasRole("ADMIN");}
自定义权限验证中就要配置用户的权限:ROLE_ADMIN 需要加上ROLE_开头
List<GrantedAuthority> grantAuths = new ArrayList<>();
//必须加ROLE_前缀
grantAuths.add(new SimpleGrantedAuthority("ROLE_ADMIN"));