.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 }
}