<?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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd"> 
    <description>Tigon Shiro Core Configuration</description>

    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
        depends-on="lifecycleBeanPostProcessor" 
        p:proxyTargetClass="true" />
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"
        p:securityManager-ref="securityManager" />

    <bean id="securityManagerParent" class="me.chyxion.tigon.shiro.TigonWebSecurityManager" abstract="true">
        <property name="sessionManager">
            <bean class="me.chyxion.tigon.shiro.TigonWebSessionManager">
                <property name="globalSessionTimeout"
                      value="${tigon.shiro.session.timeout:1800000}"/>
                <property name="sessionValidationSchedulerEnabled"
                      value="${tigon.shiro.session.validation.scheduler.enabled:false}" />
                <property name="sessionValidationInterval"
                      value="${tigon.shiro.session.validation.interval:3600000}" />
                <property name="sessionDAO">
                    <bean class="me.chyxion.tigon.shiro.TigonSessionDAO" />
                </property>
                <property name="sessionIdCookieEnabled" value="${tigon.shiro.session.id.cookie.enabled:true}" />
                <property name="sessionIdUrlRewritingEnabled" value="${tigon.shiro.session.id.url.rewriting.enabled:true}" />
                <property name="sessionIdCookie">
                    <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
                        <constructor-arg value="${tigon.shiro.session.id.cookie.name:SID}" />
                        <property name="domain" value="${tigon.shiro.cookie.domain:}" />
                        <property name="path" value="${tigon.shiro.cookie.path:/}" />
                        <property name="maxAge" value="${tigon.shiro.cookie.max.age:-1}" />
                        <property name="version" value="${tigon.shiro.cookie.version:-1}" />
                        <property name="secure" value="${tigon.shiro.cookie.secure:false}" />
                        <property name="httpOnly" value="${tigon.shiro.cookie.http.only:true}" />
                        <property name="comment" value="${tigon.shiro.cookie.comment:}" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

    <bean id="shiroFilterParent" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" abstract="true">
        <property name="securityManager" ref="securityManager" />
        <property name="loginUrl" value="${tigon.shiro.login-url:/login}" />
        <property name="successUrl" value="${tigon.shiro.login-success-url:/}" />
        <property name="unauthorizedUrl" value="${tigon.shiro.unauthorized-url:/403}" />

        <property name="filterChainDefinitionMap">
            <bean class="me.chyxion.tigon.shiro.FilterChainDefinitionMap">
                <constructor-arg value="${tigon.shiro.filter-chain-definition.config-location:classpath:shiro/auth.properties}" />
            </bean>
        </property>
    </bean>

    <bean class="org.springframework.boot.web.servlet.FilterRegistrationBean">
        <property name="filter">
            <bean class="org.springframework.web.filter.DelegatingFilterProxy">
                <constructor-arg value="shiroFilter" />
            </bean>
        </property>
        <property name="enabled" value="${tigon.shiro.fitler.enabled:true}" />
        <property name="initParameters">
            <map>
                <entry key="targetFilterLifecycle" value="true" />
            </map>
        </property>
        <property name="urlPatterns" value="${tigon.shiro.fitler.url-patterns:/*}" />
    </bean>

</beans>
