<?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:util="http://www.springframework.org/schema/util"
       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">

    <!-- 配置一个shiro框架的过滤器工厂bean，用于创建shiro框架的过滤器 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
    </bean>

    <bean id="appTokenAuthFilter" class="com.izouma.awesomeadmin.shiro.AppTokenFilter"/>

    <!-- 注册安全管理器 -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <!-- 注入realm到安全管理器进行密码匹配 -->
        <property name="authenticator" ref="modularRealmAuthenticator"/>
        <property name="realms">
            <list>
                <ref bean="phoneCodeRealm"/>
                <ref bean="userPasswordRealm"/>
                <ref bean="appTokenRealm"/>
                <ref bean="wechatRealm"/>
            </list>
        </property>
        <!--<property name="subjectFactory" ref="agileSubjectFactory"/>-->
    </bean>

    <bean id="modularRealmAuthenticator" class="com.izouma.awesomeadmin.shiro.MyModularRealmAuthenticator">
        <property name="authenticationStrategy">
            <!-- 认证策略 -->
            <bean class="org.apache.shiro.authc.pam.FirstSuccessfulStrategy"/>
        </property>
        <property name="realms">
            <list>
                <ref bean="phoneCodeRealm"/>
                <ref bean="userPasswordRealm"/>
                <ref bean="appTokenRealm"/>
                <ref bean="wechatRealm"/>
            </list>
        </property>
    </bean>

    <!-- 自定义的realm -->
    <bean id="phoneCodeRealm" class="com.izouma.awesomeadmin.shiro.PhoneCodeRealm">
        <property name="authenticationTokenClass" value="com.izouma.awesomeadmin.shiro.PhoneCodeToken"/>
    </bean>

    <bean id="userPasswordRealm" class="com.izouma.awesomeadmin.shiro.UserPasswordRealm">
        <property name="authenticationTokenClass" value="org.apache.shiro.authc.UsernamePasswordToken"/>
    </bean>

    <bean id="appTokenRealm" class="com.izouma.awesomeadmin.shiro.AppTokenRealm">
        <property name="authenticationTokenClass" value="com.izouma.awesomeadmin.shiro.AppToken"/>
    </bean>

    <bean id="wechatRealm" class="com.izouma.awesomeadmin.shiro.WechatRealm">
        <property name="authenticationTokenClass" value="com.izouma.awesomeadmin.shiro.WechatToken"/>
    </bean>

    <bean id="agileSubjectFactory" class="com.izouma.awesomeadmin.shiro.AgileSubjectFactory"/>

    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
</beans>