spring-security安全框架-注意事项——1

Spring Security注意事项

权限优先级:
在SecurityConfig中configure(HttpSecurity http)方法中,如下代码

 http.authorizeRequests()
                .antMatchers("/admin/**").hasRole("admin")
                .antMatchers("/**").permitAll()
                .anyRequest().authenticated()
                ;

由于admin的权限写在 “/** ”之前,所以访问时对于“/admin/** ”路径下的资源是不可读的;

反之,写成如下格式时,“/admin/**”下的路径都可读

 http.authorizeRequests()
                .antMatchers("/**").permitAll()
                .antMatchers("/admin/**").hasRole("admin")
                .anyRequest().authenticated()
                ;
posted @ 2021-06-27 21:19  Alike_zhu  阅读(76)  评论(0)    收藏  举报