<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:util="http://www.springframework.org/schema/util"
	   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.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	<!-- 缓存管理器 使用Ehcache实现 -->
	<bean id="cacheManager" class="com.tipdm.framework.common.spring.SpringCacheManager">
        <property name="cacheManager" ref="springCacheManager"/>
    </bean>

	<!-- Realm实现 -->
	<bean id="tokenRealm" class="com.tipdm.framework.dmserver.shiro.realm.BearerTokenRealm">
		<property name="tokenManager" ref="tokenManager"/>
		<property name="cachingEnabled" value="false" />
		<property name="dataSchemaService" ref="dataSchemaService"/>
	</bean>

	<bean id="subjectFactory" class="com.tipdm.framework.dmserver.shiro.mgt.BearerTokenSubjectFactory"/>

	<!-- 会话管理器 -->
	<bean id="sessionManager" class="org.apache.shiro.session.mgt.DefaultSessionManager">
		<property name="sessionValidationSchedulerEnabled" value="false"/>
	</bean>

	<!-- 安全管理器 -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="tokenRealm" />
		<property name="sessionManager" ref="sessionManager" />
		<property name="subjectDAO.sessionStorageEvaluator.sessionStorageEnabled" value="false"/>
		<property name="subjectFactory" ref="subjectFactory"/>
	</bean>

	<!-- 相当于调用SecurityUtils.setSecurityManager(securityManager) -->
	<bean
		class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
		<property name="staticMethod"
			value="org.apache.shiro.SecurityUtils.setSecurityManager" />
		<property name="arguments" ref="securityManager" />
	</bean>

	<bean id="tokenAuthcFilter" class="com.tipdm.framework.dmserver.shiro.filter.BearerTokenAuthenticatingFilter" >
		<property name="allowOrigin" value="${Access-Control-Allow-Origin}"/>
		<property name="allowMethods" value="${Access-Control-Allow-Methods}"/>
		<property name="allowHeaders" value="${Access-Control-Allow-Headers}"/>
	</bean>

	<bean id="corsFilter" class="com.tipdm.framework.dmserver.shiro.filter.CORSFilter" />

	<!-- Shiro的Web过滤器 -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<property name="securityManager" ref="securityManager" />
		<property name="filters">
			<util:map>
				<entry key="tokenAuthc" value-ref="tokenAuthcFilter"/>
				<entry key="cors" value-ref="corsFilter"/>
			</util:map>
		</property>

		<property name="filterChainDefinitions"><!-- 用于申明过滤器与url的关系，过滤器采用短路原则，越上面越先匹配 -->
			<value>
				/ = anon
				/401 = anon
				/403 = anon
				/404 = anon
				/api-docs/** = anon
				/apiDoc/** = anon
				/dev/** = anon
				/token/** = cors
				/authorize = anon
				/oauth2-login = anon
				/license/** = anon
				/api/** = tokenAuthc
				/report/** = cors
				/s/** = cors
			</value>
		</property>
	</bean>

	<!-- Shiro生命周期处理器 -->
	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />


</beans>