一、SpringSecurity介绍
- 简介
SpringSecurity是一个专注于java应用程序提供身份认证和授权的框架,它的强大之处在于它可以轻松扩展以满足自定义的需求 - 特征
– 对身份的认证和授权提供全面的、可扩展的支持。
– 防止各种攻击,如会话固定攻击、点击劫持、csrf攻击等。
– 支持与Servlet API,Spring MVC等web技术支持 - SpringSecurity底层是通过11钟过滤器进行实现,属于JavaEE层面
SpringSecurity底层详解网站推荐:http://www.spring4all.com/article/428
二、利用SpringSecurity进行权限控制
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
编写config类
对未登录,权限不足以及退出时进行过滤
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter implements CommunityConstant {
//忽略对静态资源的拦截
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
//授权
http.authorizeRequests()
//需要授权的请求
.antMatchers(
"/user/setting",