日期:2014-05-16 浏览次数:20592 次
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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-3.0.xsd
">
<description>apache shiro 配置</description>
<context:component-scan base-package="com.haier.uhome.hr91.util.shiro" />
<!-- 自定义shiro的realm数据库身份验证 -->
<bean id="jdbcAuthenticationRealm" class="com.haier.uhome.hr91.util.shiro.JdbcAuthenticationRealm" >
<property name="name" value="jdbcAuthentication" />
<property name="credentialsMatcher">
<bean class="com.haier.uhome.hr91.util.shiro.UhomeSecurityPasswd">
</bean>
</property>
<property name="defaultPermissionString" value="security:index,menu:list,info:list" />
</bean>
<bean id="customRememberMeManager" class="com.haier.uhome.hr91.util.shiro.CustomRememberMeManager"></bean>
<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"></bean>
<!-- 使用默认的WebSecurityManager -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- realm认证和授权,从数据库读取资源 -->
<property name="realm" ref="jdbcAuthenticationRealm" />
<property name="rememberMeManager" ref="customRememberMeManager" />
<property name="sessionManager" ref="sessionManager" />
</bean>
<!-- 自定义对 shiro的连接约束,结合shiroSecurityFilter实现动态获取资源 -->
<bean id="chainDefinitionSectionMetaSource" class="com.haier.uhome.hr91.util.shiro.ChainDefinitionSectionMetaSource">
<!-- 默认的连接配置 -->
<property name="filterChainDefinitions">
<value>
/manager/login.do = captchaAuthc
/manager/logout.do = logout
/manager/css/** = anon
/manager/images/** = anon
/manager/js/** = anon
/webservice/VerificationCode = anon
/manager/index.html = perms[security:index]
/manager/changePassword = perms[security:change-password]
/manager/menu.do = perms[menu:list]
/manager/info.do = perms[info:list]
</value>
</property>
<property name="webmap">
<value>/WEB-INF/conf/webmap.xml</value>
</property>
</bean>
<!-- 将shiro与spring集合 -->
<bean id="captchaAuthenticationFilter" class="com.haier.uhome.hr91.util.shiro.CaptchaAuthenticationFilter">
<property name="usernameParam"><value>loginName</value></property>
<property name="passwordParam"><value>loginPwd</value></property>
<property name="captchaParam"><value>rand</value></property>
<property name="sessionCaptchaKeyAttribute"><value>repeatCode</value></property>
<property name="failureKeyAttribute"><value>errStr</value></property>
</bean>
<bean id="uhomeRoleFilter" class="com.haier.uhome.hr91.util.shiro.UhomeRolesAuthorizationFilter"></bean>
<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
<property name="redirectUrl"><value>/manager/login.do</value></property>
</bean>
<bean id="shiroSecurityFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="filters">
<map>
<entry key="captchaAuthc" value-ref="captchaAuthenticationFilter" />
<entry key="uhomeRoles" value-ref="uhomeRoleFilter" />
</map>
</property>
<!-- shiro的核心安全接口 -->
<property name="securityManager" ref="securityManager" />