.antMatchers("/**/users/admin/**").access("hasAnyRole('ADMIN')")
.antMatchers("/**/users/test/**").access("hasAnyRole('USER')")

.antMatchers("/**/users/test/**").hasRole('USER')

 
@EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true)//启用方法级的权限认证
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

/** * 干掉默认的授权前缀 * 工作方式.access("hasRole('USER')")而不是 hasRole('USER') */ @Bean GrantedAuthorityDefaults grantedAuthorityDefaults() { return new GrantedAuthorityDefaults(""); // Remove the ROLE_ prefix }
}

 

相关文章:

  • 2021-11-21
  • 2021-08-11
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-11-18
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案