security3.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>

security4.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>

<?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>

secruity的更多相关文章

  1. YII2.0 secruity

    保存密码不能用明文保存,用MD5或者sha1哈希化是安全,但是随着硬件的发展,可能会暴力破解,目前能够对抗暴力破解的哈希算法是 bcrypt,Yii提供了两个帮助函数使用crypt进行安全的哈希加密 ...

  2. 我所了解的 京东、携程、eBay、小米 的 OpenStack 云

    参加过几次 OpenStack meetup 活动,听过这几家公司的Architect 讲他们公司的 OpenStack产品.本文试着凭借影响加网络搜索,按照自己的理解,对这些公司的 OpenStac ...

  3. C#命名空间详解namespace

     命名空间是一个域,这在个域中所有的类型名字必须是唯一的,不同的类型分组归入到层次化的命名空间, 命名空间的好处是:1.避免名字冲突,2.便于查找类型名字. 如:System.secruity.Cry ...

  4. IBM、京东、携程、eBay 的 OpenStack 云

    我所了解的 IBM.京东.携程.eBay 的 OpenStack 云 参加过几次 OpenStack meetup 活动,听过这几家公司的Architect 讲他们公司的 OpenStack产品.本文 ...

  5. spring security 3中的10个典型用法小结

    spring security 3比较庞大,但功能很强,下面小结下spring security 3中值得 注意的10个典型用法 1)多个authentication-provide可以同时使用 &l ...

  6. shiro开发,shiro的环境配置(基于spring+springMVC+redis)

    特别感谢lhacker分享的文章,对我帮助很大 http://www.aiuxian.com/article/p-1913280.html 基本的知识就不在这里讲了,在实战中体会shiro的整体设计理 ...

  7. Java JWT: JSON Web Token

    Java JWT: JSON Web Token for Java and Android JJWT aims to be the easiest to use and understand libr ...

  8. Linux后门权限维持手法

    0x01 Linux 1. 预加载型动态链接库后门 inux操作系统的动态链接库在加载过程中,动态链接器会先读取LD_PRELOAD环境变量和默认配置文件/etc/ld.so.preload,并将读取 ...

  9. 离线提取域控HASH的方法

    1.注册表提取 提取文件,Windows Server 2003或者Win XP 及以前需要提升到system权限,以后只要Administrator权限即可. reg save hklm\sam s ...

随机推荐

  1. Sublime操作

    快速搭建HTML模版:左下角的纯文本编程HTML语言,然后输出!(感叹号)或者html:5,再按Tab键. 快速创建html标签: div#top>(div.top-left>div.li ...

  2. logistic regression评价方法

    1.sensitivity,也叫recall,true positive rate,含义是预测为正向的case中对的(true positive)和所有事实为正向的case的比例. 2.specifi ...

  3. Linux—网络通讯管理命令

    一.ping命令 . ping 主机名 . ping 域名 [root@localhost ~]# ping www.baidu.com . ping IP地址 [root@localhost ~]# ...

  4. 渗透测试学习 二十一、 JSP相关漏洞

    大纲 ST2漏洞  (Struts2) 反序列漏洞              网站容器,中间键 其他漏洞 Struts2漏洞 简介: Struts2是一个基于MVC设计模式的Web应用框架,它本质上相 ...

  5. 『007』MySQL

    『005』索引-Database MySQL [001]- 点我快速打开文章[第一章 MySQL 大纲介绍] [002]- 点我快速打开文章[第二章 MySQL 介绍和安装] 更新中

  6. linux passwd批量修改用户密码

    linux passwd批量修改用户密码 对系统定期修改密码是一个很重要的安全常识,通常,我们修改用户密码都使用 passwd user 这样的命令来修改密码,但是这样会进入交互模式,即使使用脚本也不 ...

  7. destoon模块绑定二级域名出现 File not found解决办法

    昨天晚上帮一个朋友给我说他绑定模块二级域名出现 File not found,所以今天分享关于解决办法. 模块启用二级域名后,首页打开正常,但是点内容页和列表页出现File not found. 解决 ...

  8. linux shell脚本命令

    sort命令 sort #按照字典序排序 sort -n #以数值来排序,避免10比2小的情况 sort -k #如果文件有多列,指定排序的列 sort -r #逆序排列 uniq 命令 sort t ...

  9. [C5/C6] 机器学习诊断和系统设计(Machine learning Diagnostic and System Desig

    机器学习诊断(Machine learning diagnostic) Diagnostic : A test that you can run to gain insight what is / i ...

  10. 详解C++ STL priority_queue 容器

    详解C++ STL priority_queue 容器 本篇随笔简单介绍一下\(C++STL\)中\(priority_queue\)容器的使用方法和常见的使用技巧. priority_queue容器 ...