spring security 5.x去除默認前綴


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM