SpringScerity的使用

SpringScerity的使用

1.1 加入SpringSecurity依赖

<dependency>
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-web</artifactId>
	<version>4.2.10.RELEASE</version>		
</dependency> 		
<!-- SpringSecurity配置 -->		
<dependency>	
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-config</artifactId>
	<version>4.2.10.RELEASE</version>
</dependency> 		
<!-- SpringSecurity标签库 -->		
<dependency>	
	<groupId>org.springframework.security</groupId>	
	<artifactId>spring-security-taglibs</artifactId>
	<version>4.2.10.RELEASE</version>
</dependency>

1.2
加入SpringSecurity控制权限的FilterSpringSecurity使用的是过滤器Filter而不是拦截器Interceptor,意味着SpringSecurity能够管理的不仅仅是SpringMVC中的handler请求,还包含Web应用中所有请求。比如:项目中的静态资源也会被拦截,从而进行权限控制。
特别注意:springSecurityFilterChain标签中必须是springSecurityFilterChain。因为springSecurityFilterChain在IOC容器中对应真正执行权限控制的二十几个Filter,只有叫这个名字才能够加载到这些Filter。
1.3编写配置类
@Configuration //标记当前类为配置类
@EnableWebSecurity //启用web环境下的权限控制功能
public class WebAppSecurityConfig extends WebSecurityConfigurerAdapter {
//重写WebSecurityConfigurerAdapter 下的configure方法,否则所有都会被拦截
protected void configure(HttpSecurity security) throws Exception { logger.debug(“Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity).”);
}
效果l 所有请求都被SpringSecurity拦截,要求登录才可以访问。l 静态资源也都被拦截,要求登录。l 登录失败有错误提示。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值