spring security 详解
spring-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd "> <http pattern="/login" security="none"/> <http auto-config="true"> <headers> <frame-options policy="SAMEORIGIN"/> </headers> <http-basic /> <csrf request-matcher-ref="csrfSecurityRequestMatcher"/> </http> <beans:bean id="csrfSecurityRequestMatcher" class="com.curiousby.csrf.CsrfSecurityRequestMatcher"> <beans:property name="execludeUrls"> <beans:list> <beans:value>/test/</beans:value> <beans:value>/index/</beans:value> </beans:list> </beans:property> </beans:bean> <authentication-manager> </authentication-manager> </beans:beans>
/* * Project: .web * * File Created at 2017年3月15日 * * Copyright 2016 Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * curiousby Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license. */ package com.curiousby.csrf; import java.util.List; import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import org.springframework.security.web.util.matcher.RequestMatcher; /** * @see com.curiousby.csrf.CsrfSecurityRequestMatcher * @Type CsrfSecurityRequestMatcher.java * @Desc * @author baoyou curiousby@163.com * @date 2017年3月15日 下午3:44:57 * @version */ public class CsrfSecurityRequestMatcher implements RequestMatcher { private Pattern allowedMethods = Pattern.compile("^(GET|HEAD|TRACE|OPTIONS)$"); @Override public boolean matches(HttpServletRequest request) { if (execludeUrls != null && execludeUrls.size() > 0) { String servletPath = request.getServletPath(); for (String url : execludeUrls) { if ("POST".equals(request.getMethod())) { if (servletPath.contains(url)) { System.out.println("---------排除掉的post方法--------" + servletPath); return false; } } } } return !allowedMethods.matcher(request.getMethod()).matches(); } /** * 需要排除的url列表 */ private List<String> execludeUrls; public List<String> getExecludeUrls() { return execludeUrls; } public void setExecludeUrls(List<String> execludeUrls) { this.execludeUrls = execludeUrls; } } /** * Revision history * ------------------------------------------------------------------------- * * Date Author Note * ------------------------------------------------------------------------- * 2017年3月15日 baoyou curiousby@163.com creat */
web.xml
<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和微信捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
JSP 开发之Spring Security详解 前言: spring Security是一个能够为基于Spring的企业应用系统提供描述性安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC...
主要讲解如何配置spring security,这个是www.family168.com上的关于spring security讲解的网页版作成一个pdf版的.
SpringSecurity课程文档下载 pdf 教学
springsecurity使用配置详解,压缩包里包含主要的代码和详细的word文件说明。
主要介绍了Spring Security UserDetails实现原理详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
主要介绍了Spring Security OAuth2认证授权示例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Spring_Security详解,讲解Spring_Security常用的过滤器及配置。
spring security 3.0.5中文详解 跟着解说一步一步的做,你将有很大的收获
Spring Security 基本使用和配置代码,学习之后自己练习,
主要介绍了详解spring security 配置多个AuthenticationProvider ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了详解SpringBoot+SpringSecurity+jwt整合及初体验,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了详解springSecurity之java配置篇,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
主要介绍了详解spring security之httpSecurity使用示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了SpringBoot + Spring Security 基本使用及个性化登录配置详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了Spring Security 过滤器链的机制和特性,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
主要介绍了Spring security实现记住我下次自动登录功能过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
主要介绍了Spring Security实现不同接口安全策略方法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
主要介绍了Spring Security基于JWT实现SSO单点登录详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
主要介绍了详解spring security安全防护,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧