每日一博 | Spring Security 中的 hasRole 和 hasAuthority 有区别吗?
松哥原创的 Spring Boot 视频教程已经杀青,感兴趣的小伙伴戳这里-->Spring Boot+Vue+微人事视频教程 我相信很多小伙伴在初次接触 Spring Security 时,一定会被这个问题所困扰,例如如下两段配置: http.authorizeRequests().antMatchers("/admin/**").hasAuthority("admin").antMatchers("/user/**").hasAuthority("user").anyRequest().authenticated() 以及 http.authorizeRequests().antMatchers("/admin/**").hasRole("admin").antMatchers("/user/**").hasRole("user").anyRequest().authenticated() 那么这两种配置有什么区别呢? 今天我们就来和大家聊一聊这个问题。 1.源码分析 单纯从源码上来分析,你会发现这两个东西似乎一样,先来看 hasAuthority。 publicExpres...


