<?xml version="1.0" encoding="UTF-8"?>
<!--
    Application context for the Gateway Management assertion 
-->
<beans xmlns:spr="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       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/tx
                            http://www.springframework.org/schema/tx/spring-tx.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context.xsd">
    <context:component-scan base-package="com.l7tech.external.assertions.gatewaymanagement.server.rest">
        <context:include-filter type="annotation" expression="jakarta.ws.rs.ext.Provider"/>
    </context:component-scan>
    <context:component-scan base-package="com.l7tech.external.assertions.gatewaymanagement.server" />

    <bean id="policyHelper" class="com.l7tech.external.assertions.gatewaymanagement.server.PolicyHelper">
        <constructor-arg index="0" ref="licenseManager"/>
        <constructor-arg index="1">
            <bean class="com.l7tech.server.policy.validator.CompositePolicyValidator">
                <constructor-arg index="0">
                    <list>
                        <bean class="com.l7tech.policy.validator.DefaultPolicyValidator">
                            <constructor-arg index="0" ref="policyManager"/>
                            <constructor-arg index="1" ref="policyPathBuilderFactory"/>
                        </bean>
                        <ref bean="serverPolicyValidator"/>
                    </list>
                </constructor-arg>
            </bean>
        </constructor-arg>
        <constructor-arg index="2" ref="wspReader"/>
        <constructor-arg index="3" ref="gatewayExternalReferenceFinder"/>
        <constructor-arg index="4" ref="resourceEntrySchemaSourceResolver"/>
        <constructor-arg index="5" ref="policyAssertionRbacChecker"/>
    </bean>
    <bean id="encapsulatedAssertionHelper" class="com.l7tech.external.assertions.gatewaymanagement.server.EncapsulatedAssertionHelper">
        <constructor-arg index="0" ref="gatewayExternalReferenceFinder"/>
        <constructor-arg index="1" ref="resourceEntrySchemaSourceResolver"/>
    </bean>

    <bean id="gatewayExternalReferenceFinder" class="com.l7tech.external.assertions.gatewaymanagement.server.PolicyHelper$GatewayExternalReferenceFinder">
        <constructor-arg index="0" ref="rbacServices"/>
        <constructor-arg index="1">
            <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
                <property name="targetObject" ref="rbacAdvice"/>
                <property name="targetMethod" value="getSecurityFilter"/>
            </bean>
        </constructor-arg>
        <constructor-arg index="2" ref="customAssertionRegistrar"/>
        <constructor-arg index="3" ref="identityProviderConfigManager"/>
        <constructor-arg index="4" ref="identityProviderFactory"/>
        <constructor-arg index="5" ref="jdbcConnectionManager"/>
        <constructor-arg index="6" ref="jmsConnectionManager"/>
        <constructor-arg index="7" ref="jmsEndpointManager"/>
        <constructor-arg index="8">
            <bean class="com.l7tech.server.policy.VersioningPolicyManager">
                <constructor-arg index="0" ref="policyManager"/>
                <constructor-arg index="1" ref="policyVersionManager"/>
            </bean>
        </constructor-arg>
        <constructor-arg index="9" ref="resourceEntryManager"/>
        <constructor-arg index="10" ref="ssgKeyStoreManager"/>
        <constructor-arg index="11" ref="trustedCertManager"/>
        <constructor-arg index="12" ref="ssgActiveConnectorManager"/>
        <constructor-arg index="13" ref="policyExporterImporterManager"/>
        <constructor-arg index="14" ref="siteMinderConfigurationManager"/>
        <constructor-arg index="15" ref="genericEntityManager" />
        <constructor-arg index="16" ref="httpConfigurationManager" />
        <constructor-arg index="17" ref="roleManager" />
        <constructor-arg index="18" ref="securePasswordManager" />
        <constructor-arg index="19" ref="customKeyValueStoreManager" />
        <constructor-arg index="20" ref="cassandraEntityManager" />
    </bean>

    <bean id="securityFilter" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="rbacAdvice"/>
        <property name="targetMethod" value="getSecurityFilter"/>
    </bean>

    <bean id="resourceFactoryParent" abstract="true">
        <constructor-arg index="0" ref="rbacServices"/>
        <constructor-arg index="1" ref="securityFilter"/>
        <constructor-arg index="2" ref="transactionManager"/>
    </bean>

    <bean id="folderResourceFactory"  class="com.l7tech.external.assertions.gatewaymanagement.server.FolderResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="folderManager"/>
        <constructor-arg index="4">
            <map>
                <entry key="com.l7tech.objectmodel.folder.Folder">
                    <ref bean="folderManager"/>
                </entry>
                <entry key="com.l7tech.policy.Policy">
                    <ref bean="policyManager"/>
                </entry>
                <entry key="com.l7tech.gateway.common.service.PublishedService">
                    <ref bean="serviceManager"/>
                </entry>
                <entry key="com.l7tech.policy.PolicyAlias">
                    <ref bean="policyAliasManager"/>
                </entry>
                <entry key="com.l7tech.gateway.common.service.PublishedServiceAlias">
                    <ref bean="serviceAliasManager"/>
                </entry>
            </map>
        </constructor-arg>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>

    <bean id="policyResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.PolicyResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3">
            <bean class="com.l7tech.server.policy.VersioningPolicyManager">
                <constructor-arg index="0" ref="policyManager"/>
                <constructor-arg index="1" ref="policyVersionManager"/>
            </bean>
        </constructor-arg>
        <constructor-arg index="4" ref="policyHelper"/>
        <constructor-arg index="5" ref="folderResourceFactory"/>
        <constructor-arg index="6" ref="securityZoneManager"/>
        <constructor-arg index="7" ref="policyVersionManager"/>
        <constructor-arg index="8" ref="clusterPropertyManager"/>
        <constructor-arg index="9" ref="serviceManager"/>
    </bean>

    <bean id="serviceResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.ServiceResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3">
            <bean class="com.l7tech.server.service.PolicyVersioningServiceManager">
                <constructor-arg index="0" ref="serviceManager"/>
                <constructor-arg index="1" ref="policyVersionManager"/>
            </bean>
        </constructor-arg>
        <constructor-arg index="4" ref="serviceDocumentManager"/>
        <constructor-arg index="5" ref="serviceDocumentResolver"/>
        <constructor-arg index="6" ref="uddiServiceWsdlUpdateChecker"/>
        <constructor-arg index="7" ref="policyHelper"/>
        <constructor-arg index="8" ref="folderResourceFactory"/>
        <constructor-arg index="9" ref="securityZoneManager"/>
        <constructor-arg index="10" ref="policyVersionManager"/>
    </bean>
    <bean id="certificateResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.CertificateResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="trustedCertManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
        <constructor-arg index="5" ref="revocationCheckPolicyManager"/>
    </bean>
    <bean id="clusterPropertyResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.ClusterPropertyResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="clusterPropertyManager"/>
    </bean>
    <bean id="documentResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.DocumentResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="resourceEntryManager"/>
        <constructor-arg index="4" ref="resourceEntrySchemaSourceResolver"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>
    <bean id="identityProviderResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.IdentityProviderResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="identityProviderConfigManager"/>
        <constructor-arg index="4" ref="ldapTemplateManager"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>
    <bean id="interfaceTagResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.InterfaceTagResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="clusterPropertyManager"/>
    </bean>
    <bean id="jmsDestinationResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.JMSDestinationResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="jmsEndpointManager"/>
        <constructor-arg index="4" ref="jmsConnectionManager"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>
    <bean id="jdbcConnectionResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.JDBCConnectionResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="jdbcConnectionManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
    </bean>
    <bean id="listenPortResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.ListenPortResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="ssgConnectorManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
    </bean>
    <bean id="privateKeyResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.PrivateKeyResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="serverConfig"/>
        <constructor-arg index="4" ref="ssgKeyStoreManager"/>
        <constructor-arg index="5" ref="clusterPropertyCache"/>
        <constructor-arg index="6" ref="clusterPropertyManager"/>
        <constructor-arg index="7" ref="defaultKey"/>
        <constructor-arg index="8" ref="applicationEventProxy"/>
        <constructor-arg index="9" ref="securityZoneManager"/>
    </bean>
    <bean id="revocationCheckingPolicyResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.RevocationCheckingPolicyResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="revocationCheckPolicyManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
    </bean>
    <bean id="securePasswordResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.SecurePasswordResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="securePasswordManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
    </bean>
    <bean id="encapsulatedAssertionResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.EncapsulatedAssertionResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="encapsulatedAssertionConfigManager"/>
        <constructor-arg index="4">
            <bean class="com.l7tech.server.policy.VersioningPolicyManager">
                <constructor-arg index="0" ref="policyManager"/>
                <constructor-arg index="1" ref="policyVersionManager"/>
            </bean>
        </constructor-arg>
        <constructor-arg index="5" ref="encapsulatedAssertionHelper"/>
        <constructor-arg index="6" ref="policyHelper"/>
        <constructor-arg index="7" ref="securityZoneManager"/>
    </bean>
    <bean id="genericEntityResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.GenericEntityResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="genericEntityManager" />
    </bean>
    <bean id="customKeyValueStoreResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.CustomKeyValueStoreResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="customKeyValueStoreManager" />
    </bean>
    <bean id="activeConnectorResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.ActiveConnectorResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="ssgActiveConnectorManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
    </bean>
    <bean id="securityZoneResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.SecurityZoneResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="securityZoneManager"/>
    </bean>
    <bean id="siteMinderConfigurationResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.SiteMinderConfigurationResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="siteMinderConfigurationManager"/>
        <constructor-arg index="4" ref="securePasswordManager"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>
    <bean id="assertionSecurityZoneResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.AssertionSecurityZoneResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="assertionAccessManager"/>
        <constructor-arg index="4" ref="securityZoneManager"/>
        <constructor-arg index="5" ref="assertionRegistry"/>
    </bean>
    <bean id="httpConfigurationResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.HttpConfigurationResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="httpConfigurationManager"/>
        <constructor-arg index="4" ref="securePasswordManager"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>
    <bean id="rbacRoleResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.RbacRoleResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="roleManager"/>
        <constructor-arg index="4" ref="folderManager"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
        <constructor-arg index="6" ref="entityCrud"/>
        <constructor-arg index="7" ref="identityProviderFactory"/>
    </bean>
    <bean id="policyAliasResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.PolicyAliasResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="policyAliasManager"/>
        <constructor-arg index="4" ref="policyResourceFactory"/>
        <constructor-arg index="5" ref="folderResourceFactory"/>
        <constructor-arg index="6" ref="securityZoneManager"/>
    </bean>
    <bean id="emailListenerResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.EmailListenerResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="emailListenerManager"/>
        <constructor-arg index="4" ref="serviceResourceFactory"/>
        <constructor-arg index="5" ref="securityZoneManager"/>
    </bean>
    <bean id="serviceAliasResourceFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.ServiceAliasResourceFactory" parent="resourceFactoryParent">
        <constructor-arg index="3" ref="serviceAliasManager"/>
        <constructor-arg index="4" ref="serviceResourceFactory"/>
        <constructor-arg index="5" ref="folderResourceFactory"/>
        <constructor-arg index="6" ref="securityZoneManager"/>
    </bean>
    <bean id="resourceFactoryRegistry" class="com.l7tech.external.assertions.gatewaymanagement.server.ResourceFactoryRegistry">
        <constructor-arg index="0">
            <list>
                <ref bean="certificateResourceFactory" />
                <ref bean="clusterPropertyResourceFactory" />
                <ref bean="documentResourceFactory" />
                <ref bean="folderResourceFactory"/>
                <ref bean="identityProviderResourceFactory" />
                <ref bean="interfaceTagResourceFactory" />
                <ref bean="jmsDestinationResourceFactory" />
                <ref bean="jdbcConnectionResourceFactory" />
                <ref bean="listenPortResourceFactory" />
                <ref bean="policyResourceFactory"/>
                <ref bean="privateKeyResourceFactory" />
                <ref bean="revocationCheckingPolicyResourceFactory" />
                <ref bean="serviceResourceFactory"/>
                <ref bean="securePasswordResourceFactory" />
                <ref bean="encapsulatedAssertionResourceFactory" />
                <ref bean="genericEntityResourceFactory" />
                <ref bean="customKeyValueStoreResourceFactory"/>
                <ref bean="activeConnectorResourceFactory" />
                <ref bean="securityZoneResourceFactory" />
                <ref bean="siteMinderConfigurationResourceFactory"/>
                <ref bean="assertionSecurityZoneResourceFactory" />
                <ref bean="httpConfigurationResourceFactory" />
                <ref bean="rbacRoleResourceFactory" />
                <ref bean="policyAliasResourceFactory" />
                <ref bean="emailListenerResourceFactory" />
                <ref bean="serviceAliasResourceFactory" />
            </list>
        </constructor-arg>
    </bean>

    <bean id="restAgent" class="com.l7tech.gateway.rest.RestAgentImpl" init-method="init">
        <property name="autoScannedComponentAnnotations">
            <list value-type="java.lang.Class">
                <value>jakarta.ws.rs.ext.Provider</value>
            </list>
        </property>
        <!-- This makes it so that the default jersey wadl generator does not get initialized.-->
        <property name="resourceConfigProperties">
            <map>
                <entry key="#{T(org.glassfish.jersey.server.ServerProperties).WADL_FEATURE_DISABLE}">
                <value type="java.lang.Boolean">true</value>
            </entry>
            </map>
        </property>
        <property name="additionalResourceClasses">
            <list value-type="java.lang.Class">
                <value>com.l7tech.external.assertions.gatewaymanagement.server.rest.resource.impl.BundleResource</value>
            </list>
        </property>
    </bean>

    <bean id="urlAccessibleLocator" class="com.l7tech.external.assertions.gatewaymanagement.server.rest.URLAccessibleLocatorImpl" />
    <bean id="apiUtilityLocator" class="com.l7tech.external.assertions.gatewaymanagement.server.rest.APIUtilityLocatorImpl" />
    <bean id="bundleImporter" class="com.l7tech.external.assertions.gatewaymanagement.server.rest.BundleImporter" />
    <bean id="bundleExporter" class="com.l7tech.external.assertions.gatewaymanagement.server.rest.BundleExporter" />
    <bean id="rbacAccessService" class="com.l7tech.external.assertions.gatewaymanagement.server.rest.RbacAccessService" />

    <bean id="secretsEncryptorFactory" class="com.l7tech.external.assertions.gatewaymanagement.server.rest.SecretsEncryptorFactory">
        <constructor-arg index="0">
            <bean class="com.l7tech.server.util.PropertiesValueFactoryBean">
                <constructor-arg ref="nodeProperties"/>
                <constructor-arg value="node.cluster.pass"/>
            </bean>
        </constructor-arg>
    </bean>
</beans>