Spring Security
来源:互联网 发布:关键词诊断优化 编辑:程序博客网 时间:2024/05/15 19:45
<?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:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<!-- access-denied-page 自定义拒绝页面 -->
<httpauto-config='true'access-denied-page="/accessDenied.jsp">
<!--
filters='none' spring security不对其进行拦截,任何用户都可以不授权访问 <intercept-url
pattern='/index.jsp' access="ROLE_ADMIN" /> <intercept-url
pattern="/**" access="ROLE_USER" />
-->
<!-- 只有拦截后才能使spring security 标签-->
<intercept-urlpattern="/common/**/*.jsp"filters="none"/>
<intercept-urlpattern="/common/**/index-top.jsp"access="ROLE_ADMIN"/>
<intercept-urlpattern='/login.jsp'filters='none'/>
<!-- 不要过滤图片等静态资源 -->
<intercept-urlpattern="/**/*.jpg"filters="none"/>
<intercept-urlpattern="/**/*.png"filters="none"/>
<intercept-urlpattern="/**/*.gif"filters="none"/>
<intercept-urlpattern="/**/*.css"filters="none"/>
<intercept-urlpattern="/**/*.js"filters="none"/>
<intercept-urlpattern="/**"access="IS_AUTHENTICATED_FULLY"/>
<!--
<form-login> 登录过滤器; login-page 登录页面(必须在以上拦截链中配置其可对任何人访问,否则不停的拦截跳转);
authentication-failure-url 登陆失败页面;default-target-url 默认登录成功后转向的页面
-->
<form-loginlogin-page='/login.jsp'
authentication-failure-url="/login.jsp?error=true"
default-target-url="/index.jsp"/>
<!--
<logout /> 注销过滤器; invalidate-session=true 用户注销,不设置此参数时默认值为true;
logout-success-url 用户注销后跳转的页面/action(可在此处理回收资源等);
logout-url="/j_spring_security_logout"
设置一个特殊的URL以便特定的注销过滤器来捕捉处理,在任何页面中添加一个链接来注销<s:a
href="j_spring_security_logout"></s:a>.
不设置此参数默认值为:"/j_spring_security_logout".
-->
<!--注销用户-->
<logoutinvalidate-session="true"logout-success-url="/login.jsp"
logout-url="/j_spring_security_logout"/>
<!-- 检测失效的sessionId,超时时定位到另外一个URL -->
<session-managementinvalid-session-url="/login.jsp"/>
<!--
增加一个自定义filter,与Acegi是不一样的,不能修改默认的filter,这个filter位于FILTER_SECURITY_INTERCEPTOR之前
-->
<custom-filterref="resourceSecurityInterceptor"before="FILTER_SECURITY_INTERCEPTOR"/>
</http>
<!-- 自定义过滤器 -->
<beans:beanid="resourceSecurityInterceptor"
class="com.common.springsecurity.customfilter.FilterSecurityInterceptor">
<!-- 认证管理器,实现用户认证的入口 -->
<beans:propertyname="authenticationManager"ref="MyAuthenticationManager"/>
<!-- 访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源 -->
<beans:propertyname="accessDecisionManager"ref="AccessDecisionManager"/>
<!-- 资源源数据定义,即定义某一资源可以被哪些角色访问 -->
<beans:propertyname="securityMetadataSource"
ref="InvocationSecurityMetadataSourceService"/>
<!-- 每次请求都进行检查. 如果设为true,则只第一次检查,默认为true. 注:默认true时,用户访问权限仅拦截一次.
<beans:property name="observeOncePerRequest" value="false" />-->
</beans:bean>
<!-- 认证管理器 -->
<authentication-manageralias="MyAuthenticationManager">
<authentication-providerref="daoAuthenticationProvider">
<!--
<user-service>
<user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
<user name="user" password="user" authorities="ROLE_USER" />
</user-service>
<jdbc-user-service data-source-ref="UserDetailService" />
-->
</authentication-provider>
</authentication-manager>
<!--
访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源
,AffirmativeBased表示只要有一个Voter通过权限要求,就可以访问
-->
<beans:beanid="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<!-- 是否允许所有的投票者弃权,如果为false,表示如果所有的投票者弃权,就禁止访问 -->
<beans:propertyname="allowIfAllAbstainDecisions"
value="false"/>
<beans:propertyname="decisionVoters">
<beans:list>
<!--
RoleVoter默认角色名称都要以ROLE_开头,否则不会被计入权限控制,如果要修改前缀,可以通过对rolePrefix属性进行修改
-->
<beans:beanclass="org.springframework.security.access.vote.RoleVoter"/>
<beans:bean
class="org.springframework.security.access.vote.AuthenticatedVoter"/>
</beans:list>
</beans:property>
</beans:bean>
<!-- 国际化异常信息 -->
<beans:beanid="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:propertyname="basename"
value="WEB-INF/log/messages_zh_CN"/>
</beans:bean>
<!-- DAO认证提供器
Spring Security包含了一个产品级别的AuthenticationProvider实现,叫做DaoAuthenticationProvider。
这个认证提供器兼容所有生成UsernamePasswordAuthenticationToken的验证机制,它可能是框架里最常用到的提供器。
与其他认证提供器一样,DaoAuthenticationProvider通过一个UserDetailsService来获得用户名,密码和GrantedAuthority[]。
与其他认证提供器不同的是,这个认证提供器需要获得一个密码,它会根据认证请求对象里的密码来判断认证是否成功。 -->
<beans:beanid="daoAuthenticationProvider"class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:propertyname="userDetailsService"ref="UserDetailService"/> <!-- 必须实现的接口 -->
<beans:propertyname="hideUserNotFoundExceptions"value="false"/><!-- 是否隐藏用户没有找到的异常,默认为trye,即将不能准确地报告用户是否存在的异常 -->
<!-- [可选项] PasswordEncoder为从配置好的UserDetailsService中返回的UserDetails对象里的密码,提供加密功能。
SaltSource使用盐值生成密码,这可以提升认证资源密码的安全性。
Spring Security支持MD5,SHA和纯文本编码的PasswordEncoder实现。
Spring Security提供了两种SaltSource实现:SystemWideSaltSource对所有密码都使用相同的盐值进行编码,
ReflectionSaltSource,使用返回的UserDetails对象的属性来获得盐值。
<beans:property name="saltSource" ref bean="saltSource"/>
<beans:property name="passwordEncoder" ref="passwordEncoder"/> -->
</beans:bean>
</beans:beans>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<!-- access-denied-page 自定义拒绝页面 -->
<httpauto-config='true'access-denied-page="/accessDenied.jsp">
<!--
filters='none' spring security不对其进行拦截,任何用户都可以不授权访问 <intercept-url
pattern='/index.jsp' access="ROLE_ADMIN" /> <intercept-url
pattern="/**" access="ROLE_USER" />
-->
<!-- 只有拦截后才能使spring security 标签-->
<intercept-urlpattern="/common/**/*.jsp"filters="none"/>
<intercept-urlpattern="/common/**/index-top.jsp"access="ROLE_ADMIN"/>
<intercept-urlpattern='/login.jsp'filters='none'/>
<!-- 不要过滤图片等静态资源 -->
<intercept-urlpattern="/**/*.jpg"filters="none"/>
<intercept-urlpattern="/**/*.png"filters="none"/>
<intercept-urlpattern="/**/*.gif"filters="none"/>
<intercept-urlpattern="/**/*.css"filters="none"/>
<intercept-urlpattern="/**/*.js"filters="none"/>
<intercept-urlpattern="/**"access="IS_AUTHENTICATED_FULLY"/>
<!--
<form-login> 登录过滤器; login-page 登录页面(必须在以上拦截链中配置其可对任何人访问,否则不停的拦截跳转);
authentication-failure-url 登陆失败页面;default-target-url 默认登录成功后转向的页面
-->
<form-loginlogin-page='/login.jsp'
authentication-failure-url="/login.jsp?error=true"
default-target-url="/index.jsp"/>
<!--
<logout /> 注销过滤器; invalidate-session=true 用户注销,不设置此参数时默认值为true;
logout-success-url 用户注销后跳转的页面/action(可在此处理回收资源等);
logout-url="/j_spring_security_logout"
设置一个特殊的URL以便特定的注销过滤器来捕捉处理,在任何页面中添加一个链接来注销<s:a
href="j_spring_security_logout"></s:a>.
不设置此参数默认值为:"/j_spring_security_logout".
-->
<!--注销用户-->
<logoutinvalidate-session="true"logout-success-url="/login.jsp"
logout-url="/j_spring_security_logout"/>
<!-- 检测失效的sessionId,超时时定位到另外一个URL -->
<session-managementinvalid-session-url="/login.jsp"/>
<!--
增加一个自定义filter,与Acegi是不一样的,不能修改默认的filter,这个filter位于FILTER_SECURITY_INTERCEPTOR之前
-->
<custom-filterref="resourceSecurityInterceptor"before="FILTER_SECURITY_INTERCEPTOR"/>
</http>
<!-- 自定义过滤器 -->
<beans:beanid="resourceSecurityInterceptor"
class="com.common.springsecurity.customfilter.FilterSecurityInterceptor">
<!-- 认证管理器,实现用户认证的入口 -->
<beans:propertyname="authenticationManager"ref="MyAuthenticationManager"/>
<!-- 访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源 -->
<beans:propertyname="accessDecisionManager"ref="AccessDecisionManager"/>
<!-- 资源源数据定义,即定义某一资源可以被哪些角色访问 -->
<beans:propertyname="securityMetadataSource"
ref="InvocationSecurityMetadataSourceService"/>
<!-- 每次请求都进行检查. 如果设为true,则只第一次检查,默认为true. 注:默认true时,用户访问权限仅拦截一次.
<beans:property name="observeOncePerRequest" value="false" />-->
</beans:bean>
<!-- 认证管理器 -->
<authentication-manageralias="MyAuthenticationManager">
<authentication-providerref="daoAuthenticationProvider">
<!--
<user-service>
<user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
<user name="user" password="user" authorities="ROLE_USER" />
</user-service>
<jdbc-user-service data-source-ref="UserDetailService" />
-->
</authentication-provider>
</authentication-manager>
<!--
访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源
,AffirmativeBased表示只要有一个Voter通过权限要求,就可以访问
-->
<beans:beanid="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<!-- 是否允许所有的投票者弃权,如果为false,表示如果所有的投票者弃权,就禁止访问 -->
<beans:propertyname="allowIfAllAbstainDecisions"
value="false"/>
<beans:propertyname="decisionVoters">
<beans:list>
<!--
RoleVoter默认角色名称都要以ROLE_开头,否则不会被计入权限控制,如果要修改前缀,可以通过对rolePrefix属性进行修改
-->
<beans:beanclass="org.springframework.security.access.vote.RoleVoter"/>
<beans:bean
class="org.springframework.security.access.vote.AuthenticatedVoter"/>
</beans:list>
</beans:property>
</beans:bean>
<!-- 国际化异常信息 -->
<beans:beanid="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:propertyname="basename"
value="WEB-INF/log/messages_zh_CN"/>
</beans:bean>
<!-- DAO认证提供器
Spring Security包含了一个产品级别的AuthenticationProvider实现,叫做DaoAuthenticationProvider。
这个认证提供器兼容所有生成UsernamePasswordAuthenticationToken的验证机制,它可能是框架里最常用到的提供器。
与其他认证提供器一样,DaoAuthenticationProvider通过一个UserDetailsService来获得用户名,密码和GrantedAuthority[]。
与其他认证提供器不同的是,这个认证提供器需要获得一个密码,它会根据认证请求对象里的密码来判断认证是否成功。 -->
<beans:beanid="daoAuthenticationProvider"class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:propertyname="userDetailsService"ref="UserDetailService"/> <!-- 必须实现的接口 -->
<beans:propertyname="hideUserNotFoundExceptions"value="false"/><!-- 是否隐藏用户没有找到的异常,默认为trye,即将不能准确地报告用户是否存在的异常 -->
<!-- [可选项] PasswordEncoder为从配置好的UserDetailsService中返回的UserDetails对象里的密码,提供加密功能。
SaltSource使用盐值生成密码,这可以提升认证资源密码的安全性。
Spring Security支持MD5,SHA和纯文本编码的PasswordEncoder实现。
Spring Security提供了两种SaltSource实现:SystemWideSaltSource对所有密码都使用相同的盐值进行编码,
ReflectionSaltSource,使用返回的UserDetails对象的属性来获得盐值。
<beans:property name="saltSource" ref bean="saltSource"/>
<beans:property name="passwordEncoder" ref="passwordEncoder"/> -->
</beans:bean>
</beans:beans>
0 0
- Spring Security
- Spring Security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- spring security
- Spring Security
- spring security
- spring-security
- Spring Security
- Spring Security
- spring security
- spring Security
- Intel Hadoop Distribution 2.5.1 HBase Thrift启动异常
- Wireshark抓包分析Sip流程
- andriod柱形图简单实现
- C#静态方法,静态变量
- 有时候容易受骗是一种善良的表现
- Spring Security
- 美文
- 抽象类实例
- js ==与===区别(两个等号与三个等号)
- 看完<软件随想录>有感
- OpenGL中viewport和 scissor test的问题
- Objective-C Blocks测试题与解析
- JavaScript 数组array 插入[ push() ] 与 删除[ splice() ]
- 模版内容不能改变的问题