CodeMartain 2022-03-25 15:31 采纳率: 76.3%
浏览 14
已结题

想不通的一个问题~权限与角色springsecurity


  if (privilege.equals(user.getBeizhu())) {

//             return new org.springframework.security.core.userdetails.User(username, user.getPwd(), AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_admin,admin"));
             return new org.springframework.security.core.userdetails.User(username,
                     user.getPwd(),
                     AuthorityUtils.commaSeparatedStringToAuthorityList("admin,ROLE_abc"));
        }

配置是这样的,


        .and()
                .authorizeHttpRequests()
                .antMatchers("/img/*","/login.html","/login.html","/fail.html","/showFail").permitAll()
                .antMatchers("/abc")
                .hasAnyRole("abc")
                .antMatchers("/efg")
                .hasAnyRole("abc")
                .antMatchers("/hij")
                .hasRole("abc")
                .anyRequest().authenticated()

这里设置具有abc角色的可以访问/abc,

但是运行后都是403,无权限,想不通,不应该呀,是那里漏了?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 已结题 (查看结题原因) 3月25日
    • 创建了问题 3月25日