<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <description>
        Configuration file for the Inspektr package which handles auditing for Java applications.
        If enabled this should be modified to log audit and statistics information the same way
        your local applications do. The default is currently to log to the console which is good
        for debugging/testing purposes.
    </description>

    <aop:aspectj-autoproxy/>

    <bean id="auditTrailManagementAspect" class="org.jasig.inspektr.audit.AuditTrailManagementAspect"
          c:applicationCode="${cas.audit.appcode:CAS}" c:auditablePrincipalResolver-ref="assertionAsReturnValuePrincipalResolver"
          c:auditTrailManagers-ref="auditTrailManager" c:auditActionResolverMap-ref="auditActionResolverMap"
          c:auditResourceResolverMap-ref="auditResourceResolverMap"/>

    <util:map id="auditActionResolverMap">
        <entry key="AUTHENTICATION_RESOLVER">
            <ref bean="authenticationActionResolver"/>
        </entry>
        <entry key="SAVE_SERVICE_ACTION_RESOLVER">
            <ref bean="authenticationActionResolver"/>
        </entry>

        <entry key="CREATE_TICKET_GRANTING_TICKET_RESOLVER">
            <ref bean="ticketCreationActionResolver"/>
        </entry>
        <entry key="DESTROY_TICKET_GRANTING_TICKET_RESOLVER">
            <bean class="org.jasig.inspektr.audit.spi.support.DefaultAuditActionResolver"/>
        </entry>

        <entry key="CREATE_PROXY_GRANTING_TICKET_RESOLVER">
            <ref bean="ticketCreationActionResolver"/>
        </entry>
        <entry key="DESTROY_PROXY_GRANTING_TICKET_RESOLVER">
            <bean class="org.jasig.inspektr.audit.spi.support.DefaultAuditActionResolver"/>
        </entry>

        <entry key="GRANT_SERVICE_TICKET_RESOLVER">
            <ref bean="ticketCreationActionResolver"/>
        </entry>
        <entry key="GRANT_PROXY_TICKET_RESOLVER">
            <ref bean="ticketCreationActionResolver"/>
        </entry>

        <entry key="VALIDATE_SERVICE_TICKET_RESOLVER">
            <ref bean="ticketValidationActionResolver"/>
        </entry>
    </util:map>

    <util:map id="auditResourceResolverMap">
        <entry key="AUTHENTICATION_RESOURCE_RESOLVER">
            <bean class="org.jasig.cas.audit.spi.CredentialsAsFirstParameterResourceResolver"/>
        </entry>
        <entry key="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER">
            <ref bean="returnValueResourceResolver"/>
        </entry>
        <entry key="DESTROY_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER">
            <ref bean="ticketResourceResolver"/>
        </entry>

        <entry key="CREATE_PROXY_GRANTING_TICKET_RESOURCE_RESOLVER">
            <ref bean="returnValueResourceResolver"/>
        </entry>
        <entry key="DESTROY_PROXY_GRANTING_TICKET_RESOURCE_RESOLVER">
            <ref bean="ticketResourceResolver"/>
        </entry>

        <entry key="GRANT_SERVICE_TICKET_RESOURCE_RESOLVER">
            <bean class="org.jasig.cas.audit.spi.ServiceResourceResolver"/>
        </entry>
        <entry key="GRANT_PROXY_TICKET_RESOURCE_RESOLVER">
            <bean class="org.jasig.cas.audit.spi.ServiceResourceResolver"/>
        </entry>

        <entry key="VALIDATE_SERVICE_TICKET_RESOURCE_RESOLVER">
            <ref bean="ticketResourceResolver"/>
        </entry>
        <entry key="SAVE_SERVICE_RESOURCE_RESOLVER">
            <ref bean="returnValueResourceResolver"/>
        </entry>
    </util:map>

    <bean id="authenticationActionResolver"
          class="org.jasig.inspektr.audit.spi.support.DefaultAuditActionResolver"
          c:successSuffix="_SUCCESS" c:failureSuffix="_FAILED"/>

    <bean id="ticketCreationActionResolver"
          class="org.jasig.inspektr.audit.spi.support.DefaultAuditActionResolver"
          c:successSuffix="_CREATED" c:failureSuffix="_NOT_CREATED"/>

    <bean id="ticketValidationActionResolver"
          class="org.jasig.inspektr.audit.spi.support.DefaultAuditActionResolver"
          c:successSuffix="D" c:failureSuffix="_FAILED"/>

    <bean id="returnValueResourceResolver"
          class="org.jasig.inspektr.audit.spi.support.ReturnValueAsStringResourceResolver"/>

</beans>
