<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <!-- load common properties -->
    <bean id="virtserver-properties"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders">
            <value>true</value>
        </property>
        <property name="locations">
            <list>
                <value>file:${catalina.base}/conf/alfresco-shared.properties</value>
                <value>file:${catalina.base}/conf/alfresco-virtserver.properties</value>
            </list>
        </property>
    </bean>

    <!-- Advice for automatic reauthentication.

         NOTE: Cannot use org.alfresco.repo.remote.ReauthenticatingAdvice
               because that would force spring.jar to live inside common/lib,
               but we only want it to live in server/lib, so as not to
               generate classloader problems when virtualizing webapps
               that use Spring.
    -->
    <bean id="avmReauthenticatingAdvisor"
          class="org.springframework.aop.support.DefaultPointcutAdvisor">
        <property name="advice">
            <ref bean="reauthenticatingAdvice"/>
        </property>
        <property name="pointcut">
            <bean class="org.springframework.aop.TruePointcut"/>
        </property>
    </bean>
    <bean id="reauthenticatingAdvice"
          class="org.alfresco.catalina.host.ReauthenticatingAdvice">
        <property name="authenticationService">
            <ref bean="authenticationService"/>
        </property>
        <property name="clientTicketHolder">
            <ref bean="clientTicketHolder"/>
        </property>
        <property name="user">
            <value>${alfresco.server.user}</value>
        </property>
        <property name="password">
            <value>${alfresco.server.password}</value>
        </property>
        <property name="retryInterval">
            <value>${alfresco.virtserver.connection.retry.interval}</value>
        </property>
    </bean>

    <!-- Client Ticket Holder. -->
    <bean id="clientTicketHolder" 
          class="org.alfresco.repo.remote.ClientTicketHolderGlobal"/>

    <!-- The remote authentication service. -->
    <bean id="authenticationService" 
          class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl">
            <value>rmi://${alfresco.rmi.services.host}:${alfresco.rmi.services.port}/authentication</value>
        </property>
        <property name="serviceInterface">
            <value>org.alfresco.service.cmr.security.AuthenticationService</value>
        </property>
        <property name="refreshStubOnConnectFailure">
            <value>true</value>
        </property>
    </bean>


    <!-- Remote Alfresco RMI Proxy bean -->
    <bean id="avmRemote" 
          class="org.alfresco.repo.remote.AVMRemoteImpl">
        <property name="avmRemoteTransport">
            <ref bean="avmRemoteTransport"/>
        </property>
        <property name="clientTicketHolder">
            <ref bean="clientTicketHolder"/>
        </property>
    </bean>
    <!-- Re-authenticating transport for AVMRemote -->
    <bean id="avmRemoteTransport"
          class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
            <list>
                <value>org.alfresco.service.cmr.remote.AVMRemoteTransport</value>
            </list>
        </property>
        <property name="target">
            <ref bean="avmRemoteTransportRaw"/>
        </property>
        <property name="interceptorNames">
            <list>
                <value>avmReauthenticatingAdvisor</value>
            </list>
        </property>
    </bean>
    <!-- Raw transport for AVMRemote -->
    <bean id="avmRemoteTransportRaw"
          class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl">
            <value>rmi://${alfresco.rmi.services.host}:${alfresco.rmi.services.port}/avm</value>
        </property>

        <property name="serviceInterface">
            <value>org.alfresco.service.cmr.remote.AVMRemoteTransport</value>
        </property>

        <property name="refreshStubOnConnectFailure">
            <value>true</value>
        </property>
    </bean>


    <!-- The JNDI info bean for jndi-client specific property access -->
    <bean id="jndiInfoBean" 
          class="org.alfresco.jndi.JndiInfoBean">
        <property name="alfrescoServerUser">
            <value>${alfresco.server.user}</value>
        </property>
        <property name="alfrescoServerPassword">
            <value>${alfresco.server.password}</value>
        </property>
    </bean>


    <!-- Info for peer/peer MBean registration with remote Alfresco server -->
    <bean id="virtServerInfo"
          class="org.alfresco.mbeans.VirtServerInfo"
          lazy-init="true">

        <!-- local virtualization server domain  -->
        <!-- Note: the actual virtualization server hostname used -->
        <!--       in URLs created by the Alfreseco webapp will   -->
        <!--       be:    avm.${alfresco.virtserver.domain}       -->
        <!--                                                      -->
        <property name="virtServerDomain">
            <value>${alfresco.virtserver.domain}</value>
        </property>

        <!-- local virtualization server HTTP port  -->
        <property name="virtServerHttpPort">
            <value>${alfresco.virtserver.http.port}</value>
        </property>

        <!-- local virtualization server JMX RMI port  -->
        <property name="virtServerJmxRmiPort">
            <value>${alfresco.virtserver.jmxrmi.port}</value>
        </property>


        <!-- local CIFS automount props -->
        <property name="virtServerCifsAvmVersionTreeWin">
            <value>${alfresco.virtserver.cifs.avm.versiontree.win}</value>
        </property>
        <property name="virtServerCifsAvmVersionTreeWinAutomount">
            <value>${alfresco.virtserver.cifs.avm.versiontree.win.automount}</value>
        </property>
        <property name="virtServerCifsAvmVersionTreeUnix">
            <value>${alfresco.virtserver.cifs.avm.versiontree.unix}</value>
        </property>
        <property name="virtServerCifsAvmVersionTreeUnixAutomount">
            <value>${alfresco.virtserver.cifs.avm.versiontree.unix.automount}</value>
        </property>





        <!-- remote Alfresco server hostname -->
        <property name="alfrescoJmxRmiHost">
            <value>${alfresco.rmi.services.host}</value>
        </property>

        <!-- remote Alfresco server JMX RMI port -->
        <property name="alfrescoJmxRmiPort">
            <value>${alfresco.rmi.services.port}</value>
        </property>

        <!-- retry interval when network connections fail (in milliseconds)  -->
        <property name="virtServerConnectionRetryInterval">
            <value>${alfresco.virtserver.connection.retry.interval}</value>
        </property>


    </bean>



    <!-- Custom MBeanServer                                    -->
    <!--                                                       -->
    <!-- Note:                                                 -->
    <!--   The Alfresco servlet container performs callbacks   -->
    <!--   to this MBeanServer when critical events happen,    -->
    <!--   such as a modification to a jar/class in WEB-INF,   -->
    <!--   or a change to a webapp's WEB-INF/web.xml;          -->
    <!--   when this happens, the virtualization server        -->
    <!--   needs to reload the webapp, and any webapps         -->
    <!--   that depend on it (e.g.: webapps corresponding      -->
    <!--   to sandboxes that aren't "staging").                -->
    <bean id="virtServerMBeanServer" 
          class="org.springframework.jmx.support.MBeanServerFactoryBean"/>


    <bean id="virtServerRegistry"   
          class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
        <property name="port" value="${alfresco.virtserver.jmxrmi.port}"/>
    </bean>


    <!-- MBeanServer Connector (registers itself with custom virtServerMBeanServer) -->
    <bean id="serverConnector"
          class="org.springframework.jmx.support.ConnectorServerFactoryBean"
          depends-on="virtServerRegistry">

        <property name="server"      ref="virtServerMBeanServer"/>
        <property name="objectName"  value="connector:name=rmi"/>
        <property name="serviceUrl"
                  value="service:jmx:rmi://localhost/jndi/rmi://localhost:${alfresco.virtserver.jmxrmi.port}/alfresco/jmxrmi" />

        <property name="environment">
            <map>
                <!-- The following keys are only valid when sun jmx is used -->
                <entry key="jmx.remote.x.password.file" value="${catalina.base}/conf/alfresco-jmxrmi.password"/>
                <entry key="jmx.remote.x.access.file"   value="${catalina.base}/conf/alfresco-jmxrmi.access"/>
            </map>
        </property>
    </bean>


    <bean id="virtServerExporter" 
          class="org.springframework.jmx.export.MBeanExporter">
       <property name="server" ref="virtServerMBeanServer"/>
       <property name="beans">
         <map>
           <!-- MBeans to register with virtServerMBeanServer -->
           <entry key="Alfresco:Name=VirtWebappRegistry,Type=VirtWebappRegistry" value-ref="virtWebappRegistry"/>
         </map>
       </property>
     </bean>


    <!-- MBeans registered with virtServerMBeanServer -->
    <bean id="virtWebappRegistry" 
          class="org.alfresco.mbeans.VirtWebappRegistry"/>

    <!--
         The virtualization server forces different HTTP "Cache-Control" headers
         into its response, depending upon which virtual host being accessed.

         The goal is to balance performance/freshness without requiring
         the user to tune their browser's cache settings.

         Note that:

            o  When looking at a "preview" virtual host, the files that
               tend to change the most rapidly are often the exactly those
               files that the user wants to see.  Thus, forcing a short
               max-age is a good idea; otherwise, users would need to hit
               "refresh" every time they look at a "fresh preview"
               (which is unfriendly).

            o  While the contents within "staging" virtual host might
               change quite often too, seeing something that's slightly
               more "stale" every so often in exchange for much better
               average case performance is a good trade-off.  If the user
               needs to be sure they're not seeing content from their
               browser's cache, they can always hit "refresh".


         For details on "Cache-Control" see RFC 2616 (section 14):
         http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html


         Note:

            o  Each key='...' within "cacheControlRules" property
               is a java/PCRE regex that matches virtual hosts;
               there's no implicit '^' regex prefix  or '$' regex
               suffix, so if you want to anchor something to the
               starting or ending position of a FQDN, do so explicitly.

            o  For more details on the regular expression grammar, see:
               http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
               However, note that in this context, when you want to escape
               a character that's a part of the regex grammar, use a single
               '\', not '\\' (unlike what the web page mentined above says).
               Thus, to compose a regex that inclues the literal dot-character,
               you'd do something like this "moo\.cow", not "moo\\.cow"
               (see the <entry> key strings below for more examples).

            o  Each "value" is the corresponding "Cache-Control" HTTP header
               value that's set in the virtualization server's response to
               this host.

            o  All "max-age" time values are given in seconds.

            o  Rules are processed in order; the first match (if any) wins.

    -->
    <bean id="cacheControlInfo"
          class="org.alfresco.filter.CacheControlFilterInfoBean">

        <property name="cacheControlRules">
            <map>
                <entry key="^preview\."
                       value="max-age=${alfresco.virtserver.cache-control.max-age.preview}"/>

                <entry key="^[^.]+\.[^.]+\.www--sandbox\."
                       value="max-age=${alfresco.virtserver.cache-control.max-age.workarea}"/>

                <entry key="^[^.]+\.www--sandbox\."
                       value="max-age=${alfresco.virtserver.cache-control.max-age.staging}"/>

                <!-- Default rule (user work areas) -->
                <entry key="\."
                       value="max-age=${alfresco.virtserver.cache-control.max-age.default}"/>
            </map>
        </property>
    </bean>

</beans>
