spring security xml配置详解
security 3.x
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<global-method-security pre-post-annotations="enabled">
</global-method-security>
<!-- 该路径下的资源不用过滤 -->
<http pattern="/include/js/**" security="none" />
<http pattern="/include/css/**" security="none" />
<http pattern="/include/scripts/**" security="none" />
<http pattern="/include/jsp/**" security="none" />
<http pattern="/images/**" security="none" />
<http pattern="/login.jsp" security="none" />
<!--auto-config = true 则使用from-login. 如果不使用该属性 则默认为http-basic(没有session).-->
<!-- lowercase-comparisons:表示URL比较前先转为小写。-->
<!-- path-type:表示使用Apache Ant的匹配模式。-->
<!--access-denied-page:访问拒绝时转向的页面。-->
<!-- access-decision-manager-ref:指定了自定义的访问策略管理器。--> <http use-expressions="true" auto-config="true"
access-denied-page="/include/jsp/timeout.jsp">
<!--login-page:指定登录页面。 -->
<!-- login-processing-url:指定了客户在登录页面中按下 Sign In 按钮时要访问的 URL。-->
<!-- authentication-failure-url:指定了身份验证失败时跳转到的页面。-->
<!-- default-target-url:指定了成功进行身份验证和授权后默认呈现给用户的页面。-->
<!-- always-use-default-target:指定了是否在身份验证通过后总是跳转到default-target-url属性指定的URL。
--> <form-login login-page="/login.jsp" default-target-url='/system/default.jsp'
always-use-default-target="true" authentication-failure-url="/login.jsp?login_error=1" />
<!--logout-url:指定了用于响应退出系统请求的URL。其默认值为:/j_spring_security_logout。-->
<!-- logout-success-url:退出系统后转向的URL。-->
<!-- invalidate-session:指定在退出系统时是否要销毁Session。-->
<logout invalidate-session="true" logout-success-url="/login.jsp"
logout-url="/j_spring_security_logout" />
<!-- 实现免登陆验证 -->
<remember-me /> <!-- max-sessions:允许用户帐号登录的次数。范例限制用户只能登录一次。-->
<!-- 此值表示:用户第二次登录时,前一次的登录信息都被清空。-->
<!-- exception-if-maximum-exceeded:默认为false,-->
<!-- 当exception-if-maximum-exceeded="true"时系统会拒绝第二次登录。--> <session-management invalid-session-url="/login.jsp"
session-fixation-protection="none">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="false" />
</session-management>
<custom-filter ref="myFilter" before="FILTER_SECURITY_INTERCEPTOR" />
<session-management
session-authentication-strategy-ref="sas" /> </http>
<beans:bean id="sas"
class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
<beans:constructor-arg name="sessionRegistry"
ref="sessionRegistry" />
<beans:property name="maximumSessions" value="1" />
<!-- 防止session攻击 -->
<beans:property name="alwaysCreateSession" value="true" />
<beans:property name="migrateSessionAttributes" value="false" />
<!-- 同一个帐号 同时只能一个人登录 -->
<beans:property name="exceptionIfMaximumExceeded"
value="false" />
</beans:bean>
<beans:bean id="sessionRegistry"
class="org.springframework.security.core.session.SessionRegistryImpl" />
<!--
事件监听:实现了ApplicationListener监听接口,包括AuthenticationCredentialsNotFoundEvent 事件,-->
<!-- AuthorizationFailureEvent事件,AuthorizedEvent事件, PublicInvocationEvent事件-->
<beans:bean
class="org.springframework.security.authentication.event.LoggerListener" />
<!-- 自定义资源文件 提示信息 -->
<beans:bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basenames" value="classpath:message_zh_CN">
</beans:property>
</beans:bean>
<!-- 配置过滤器 -->
<beans:bean id="myFilter"
class="com.taskmanager.web.security.MySecurityFilter">
<!-- 用户拥有的权限 -->
<beans:property name="authenticationManager" ref="myAuthenticationManager" />
<!-- 用户是否拥有所请求资源的权限 -->
<beans:property name="accessDecisionManager" ref="myAccessDecisionManager" />
<!-- 资源与权限对应关系 -->
<beans:property name="securityMetadataSource" ref="mySecurityMetadataSource" />
</beans:bean>
<!-- 实现了UserDetailsService的Bean -->
<authentication-manager alias="myAuthenticationManager">
<authentication-provider user-service-ref="myUserDetailServiceImpl">
<!-- 登入 密码 采用MD5加密 -->
<password-encoder hash="md5" ref="passwordEncoder">
</password-encoder>
</authentication-provider>
</authentication-manager>
<!-- 验证用户请求资源 是否拥有权限 -->
<beans:bean id="myAccessDecisionManager"
class="com.taskmanager.web.security.MyAccessDecisionManager">
</beans:bean>
<!-- 系统运行时加载 系统要拦截的资源 与用户请求时要过滤的资源 -->
<beans:bean id="mySecurityMetadataSource"
class="com.taskmanager.web.security.MySecurityMetadataSource">
<beans:constructor-arg name="powerService" ref="powerService">
</beans:constructor-arg>
</beans:bean>
<!-- 获取用户登入角色信息 -->
<beans:bean id="myUserDetailServiceImpl"
class="com.taskmanager.web.security.MyUserDetailServiceImpl">
<beans:property name="userService" ref="userService"></beans:property>
</beans:bean> <!-- 用户的密码加密或解密 -->
<beans:bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
</beans:beans>
security 4.x
<beans:beans
xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd"> <context:component-scan base-package="com.framework.security"/> <!--<http pattern="/pm/**" security="none" />-->
<http pattern="/login.jsp" security="none" />
<http pattern="/common/**" security="none" />
<http pattern="/*.ico" security="none" /> <http use-expressions="false" >
<!-- IS_AUTHENTICATED_ANONYMOUSLY 匿名登录 -->
<intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/pm/**/*.jsp" access="ROLE_STATIC" />
<form-login login-page="/login" authentication-failure-url="/login?error=1" authentication-success-forward-url="/main.to" />
<logout invalidate-session="true" logout-url="/logout" logout-success-url="/" />
<http-basic/>
<headers >
<frame-options disabled="true"></frame-options>
</headers> <csrf token-repository-ref="csrfTokenRepository" /> <session-management session-authentication-error-url="/frame.expired" >
<!-- max-sessions只容许一个账号登录,error-if-maximum-exceeded 后面账号登录后踢出前一个账号,expired-url session过期跳转界面 -->
<concurrency-control max-sessions="1" error-if-maximum-exceeded="false" expired-url="/frame.expired" session-registry-ref="sessionRegistry" />
</session-management> <expression-handler ref="webexpressionHandler" ></expression-handler>
</http> <beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" /> <beans:bean id="userDetailsService" class="com.framework.security.UserDetailsServiceImpl" /> <!--配置web端使用权限控制-->
<beans:bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" /> <authentication-manager >
<authentication-provider ref="authenticationProvider" />
</authentication-manager> <!-- 自定义userDetailsService, 盐值加密 -->
<beans:bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="hideUserNotFoundExceptions" value="true" />
<beans:property name="userDetailsService" ref="userDetailsService" />
<beans:property name="passwordEncoder" ref="passwordEncoder" />
<beans:property name="saltSource" ref="saltSource" />
</beans:bean> <!-- Md5加密 -->
<beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" /> <!-- 盐值加密 salt对应数据库字段-->
<beans:bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">
<beans:property name="userPropertyToUse" value="salt"/>
</beans:bean> <beans:bean id="csrfTokenRepository" class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository" />
</beans:beans>
spring security xml配置详解的更多相关文章
- Spring 入门 web.xml配置详解
Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...
- java web.xml配置详解(转)
源出处:java web.xml配置详解 1.常规配置:每一个站的WEB-INF下都有一个web.xml的设定文件,它提供了我们站台的配置设定. web.xml定义: .站台的名称和说明 .针对环境参 ...
- SpringBoot—整合log4j2入门和log4j2.xml配置详解
关注微信公众号:CodingTechWork,一起学习进步. 引言 对于一个线上程序或者服务而言,重要的是要有日志输出,这样才能方便运维.而日志的输出需要有一定的规划,如日志命名.日志大小,日志分 ...
- web.xml配置详解之listener
web.xml配置详解之listener 定义 <listener> <listener-class>nc.xyzq.listener.WebServicePublishLis ...
- tomcat中server.xml配置详解(转载)(一)
转载自:https://www.cnblogs.com/starhu/p/5599773.html tomcat中server.xml配置详解 Tomcat Server的结构图如下:(该文件描述了如 ...
- Web.xml配置详解(转)
Web.xml配置详解 Posted on 2010-09-02 14:09 chinaifne 阅读(295105) 评论(16) 编辑 收藏 1 定义头和根元素 部署描述符文件就像所有XML文件一 ...
- Tomcat中的Server.xml配置详解
Tomcat中的Server.xml配置详解 Tomcat Server的结构图如下: 该文件描述了如何启动Tomcat Server <Server> <Listener /> ...
- Log4j2详解——XML配置详解
Log4j2详解--XML配置详解 找到了个很详细的文章链接 https://www.jianshu.com/p/bfc182ee33db
- Java web.xml 配置详解
在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...
随机推荐
- listview 嵌套checkbox响应item点击和button点击事件
参考文档 http://www.eoeandroid.com/forum.php?mod=viewthread&tid=182280 一.主要要点 1. CheckBox的优先级比item高. ...
- java中JDK环境变量的配置
JDK的配置在 window中的配置,我的电脑-->属性-->高级系统设置-->高级-->环境变量中配置,具体下图
- 水池问题的lua语言算法(面试题分析:我的Twitter技术面试失败了)
twitter面试题内容 “看下面这个图片” “在这个图片里我们有不同高度的墙.这个图片由一个整数数组所代表,数组中每个数是墙的高度.上边的图可以表示为数组[2,5,1,2,3,4,7,7,6]” “ ...
- uniGUI 通过SessionList操作另外的登录用户
参照bbs,写了这个方法,检查是否有同名用户已经登录:procedure TUniMainModule.CheckSameUser(aUserLoginCode: string);var ASess ...
- (原创)用c++11打造好用的any
上一篇博文用c++11实现了variant,有童鞋说何不把any也实现一把,我正有此意,它的兄弟variant已经实现了,any也顺便打包实现了吧.其实boost.any已经挺好了,就是转换异常时,看 ...
- 分形之龙形曲线(Dragon Curve)
龙形曲线(Dragon Curve)又叫分形龙,是一种自相似碎形曲线的统称,因形似龙的蜿蜒盘曲而得名. 一种简单的生成分形龙的方式是:拿着一条细长的纸带,把它朝下的一头拿上来,与上面的一头并到一起.用 ...
- JS学习笔记1_基础与常识
1.六种数据类型 5种基础的:Undefined,Null,Boolean,Number,String(其中Undefined派生自Null) 1种复杂的:Object(本质是一组无序键值对) 2.字 ...
- C# winfrom 写的一个搜索助手,可以按照标题和内容搜索,支持doc,xls,ppt,pdf,txt等格式的文件搜索
C# winfrom 写的一个搜索助手,可以按照标题和内容搜索,指定目录后,遍历搜索文件和子目,现在只写了支持.DOC.DOCX.XLS.XLSX.PPT.PPTX.PDF.HTML.HTM.TXT等 ...
- 未能加载文件或程序集,PublicKeyToken=“**********”,或它的某一个依赖项。强名称验证失败。
就是这种错误.这种错误怎么办? 以下步骤: (以上图dll为例) 1.看项目的Debug文件夹下是否有以下三个文件 2.看项目的.csproj文件下引用的报错dll的publickeytoken和版本 ...
- Swift5 语言指南(二十一) 嵌套类型
通常创建枚举以支持特定类或结构的功能.类似地,定义纯粹在更复杂类型的上下文中使用的实用程序类和结构可能是方便的.为此,Swift允许您定义嵌套类型,从而在它们支持的类型定义中嵌套支持枚举,类和结构. ...