SpringBoot整合SpringSecurity角色名称不匹配

异常报错

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")); 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值