<?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"
	xmlns:util="http://www.springframework.org/schema/util"
	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/util http://www.springframework.org/schema/util/spring-util.xsd"
	default-lazy-init="true">
	
	<bean id="credentialsMatcher"
		class="com.iemes.shiro.credentials.RetryLimitHashedCredentialsMatcher">
		<!-- hashAlgorithmName必须的，没有默认值。可以有MD5或者SHA-1，如果对密码安全有更高要求可以用SHA-256或者更高。
		这里使用MD5 storedCredentialsHexEncoded默认是true，此时用的是密码加密用的是Hex编码；false时用Base64编码 
		hashIterations迭代次数，默认值是1。 -->
		<constructor-arg ref="cacheManager" />
		<property name="hashAlgorithmName" value="md5" />
		<property name="hashIterations" value="2" />
		<property name="storedCredentialsHexEncoded" value="true" />
	</bean>
	<!-- 凭证匹配器 -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="myRealm" />
		<property name="sessionManager" ref="sessionManager"/>
		<!-- 使用下面配置的缓存管理器 -->
		<property name="cacheManager" ref="cacheManager" />
	</bean>
	<!--自定义Realm -->
	<bean id="myRealm" class="com.iemes.shiro.MyRealm">
		<property name="credentialsMatcher" ref="credentialsMatcher" />
		<property name="cachingEnabled" value="false" />
		<!-- 如需要自定义缓存时间放开以下.修改 ehcache.xml-->
		 <!--<property name="authenticationCachingEnabled" value="true"/>-->
        <!--<property name="authenticationCacheName" value="authenticationCache"/>-->
        <!--<property name="authorizationCachingEnabled" value="true"/>-->
        <!--<property name="authorizationCacheName" value="authorizationCache"/>-->
	</bean>
	
     <bean id="sysUserFilter" class="com.iemes.shiro.filter.SysUserFilter"/>
    
    
	 <bean id="kickoutSessionControlFilter" class="com.iemes.shiro.filter.KickoutSessionControlFilter">
        <property name="cacheManager" ref="cacheManager"/>
        <property name="sessionManager" ref="sessionManager"/>

        <property name="kickoutAfter" value="false"/>
        <property name="maxSession" value="1"/>
        <property name="kickoutUrl" value="/login.shtml"/>
    </bean>
    
    
	<!-- 配置shiro的过滤器工厂类，id- shiroFilter要和我们在web.xml中配置的过滤器一致 -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<property name="securityManager" ref="securityManager" />
		<property name="loginUrl" value="/login.shtml" />
		<property name="successUrl" value="/index.shtml" />
		<property name="unauthorizedUrl" value="/denied.jsp" />
		<!-- 自定义权限配置 -->
		<property name="filterChainDefinitionMap" ref="chainDefinitionSectionMetaSource" />
		<property name="filters">
            <util:map>
                <entry key="sysUser" value-ref="sysUserFilter"/>
                <entry key="kickout" value-ref="kickoutSessionControlFilter"/>
            </util:map>
        </property>
	</bean>
	<!--自定义filterChainDefinitionMap -->
	<bean id="chainDefinitionSectionMetaSource" class="com.iemes.shiro.ChainDefinitionSectionMetaSource">
		<property name="filterChainDefinitions">
			<value>
			/favicon.ico = anon
    		/admin_files/** = anon
    		/fonts/** = anon
    		/404/** = anon
    		/error.jsp = anon
    		/layui/** = anon
    		/js/** = anon
    		/layer-v1.9.2/** = anon
    		/notebook/** = anon
    		/login.shtml = anon
			/denied.jsp = anon
			/install.shtml = anon
			/uploadFile/** = anon
			/css/** = anon
			/js/** = anon
			/images/favicon.ico = anon
			/images/** = anon
			</value>
		</property>
	</bean>
	
	<bean id="sessionIdGenerator" class="org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator"/>
	
	 <!-- 会话DAO -->
    <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO">
        <property name="activeSessionsCacheName" value="shiro-activeSessionCache"/>
        <property name="sessionIdGenerator" ref="sessionIdGenerator"/>
    </bean>

    <!-- 会话验证调度器 -->
     <!-- 全局的会话信息检测扫描信息间隔30分钟-->
    <bean id="sessionValidationScheduler" class="org.apache.shiro.session.mgt.quartz.QuartzSessionValidationScheduler">
        <property name="sessionValidationInterval" value="1800000"/>
        <property name="sessionManager" ref="sessionManager"/>
    </bean>
	
	 <!-- 会话管理器 -->
	  <!-- 全局的会话信息设置成30分钟,sessionValidationSchedulerEnabled参数就是是否开启扫描  -->
    <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
        <property name="globalSessionTimeout" value="1800000"/>
        <property name="deleteInvalidSessions" value="true"/>
        <property name="sessionValidationSchedulerEnabled" value="true"/>
        <property name="sessionValidationScheduler" ref="sessionValidationScheduler"/>
        <property name="sessionDAO" ref="sessionDAO"/>
    </bean>
	
	
	<!--shiro缓存管理器 -->
	<bean id="cacheManager" class="com.iemes.shiro.spring.SpringCacheManagerWrapper" >
	<property name="cacheManager" ref="springCacheManager"/>
	</bean>
	
	 <bean id="springCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcacheManager"/>
    </bean>

    <!--ehcache-->
    <bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml"/>
    </bean>
	
	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
</beans>
