日期:2014-05-16 浏览次数:20524 次
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:s="http://www.springframework.org/schema/security" 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-2.5.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd" default-autowire="byType" default-lazy-init="true"> <description>SpringSecurity安全配置</description> <!-- http安全配置 --> <s:http auto-config="true" access-decision-manager-ref="accessDecisionManager"> <s:form-login login-page="/login.action" default-target-url="/" authentication-failure-url="/login.action?error=true" /> <s:logout logout-success-url="/" /> <s:remember-me key="e37f4b31-0c45-11dd-bd0b-0800200c9a66" /> </s:http> <!-- 认证配置 --> <s:authentication-provider user-service-ref="userDetailsService"> <!-- 可设置hash使用sha1或md5散列密码后再存入数据库 --> <s:password-encoder hash="plaintext" /> </s:authentication-provider> <!-- 项目实现的用户查询服务 --> <bean id="userDetailsService" class="org.springside.examples.miniweb.service.security.UserDetailsServiceImpl" /> <!-- 重新定义的FilterSecurityInterceptor,使用databaseDefinitionSource提供的url-授权关系定义 --> <bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor"> <s:custom-filter before="FILTER_SECURITY_INTERCEPTOR" /> <property name="accessDecisionManager" ref="accessDecisionManager" /> <property name="objectDefinitionSource" ref="databaseDefinitionSource" /> </bean> <!-- DefinitionSource工厂,使用resourceDetailsService提供的URL-授权关系. --> <bean id="databaseDefinitionSource" class="org.springside.modules.security.springsecurity.DefinitionSourceFactoryBean"> <property name="resourceDetailsService" ref="resourceDetailsService" /> </bean> <!-- 项目实现的URL-授权查询服务 --> <bean id="resourceDetailsService" class="org.springside.examples.miniweb.service.security.ResourceDetailsServiceImpl" /> <!-- 授权判断配置, 将授权名称的默认前缀由ROLE_改为A_. --> <bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased"> <property name="decisionVoters"> <list> <bean class="org.springframework.security.vote.RoleVoter"> <property name="rolePrefix" value="A_" /> </bean> <bean class="org.springframework.security.vote.AuthenticatedVoter" /> </list> </property> </bean> </beans>