<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ WSO2 Inc. licenses this file to you under the Apache License,
  ~ Version 2.0 (the "License"); you may not use this file except
  ~ in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied. See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
         http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
         http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    <!--Discovery Service GET Endpoint-->
    <jaxrs:server id="DiscoveryService_rest" address="/discovery/get">
        <jaxrs:serviceBeans>
            <ref bean="discoveryService"/>
            <ref bean="swaggerResource"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean="jsonProvider"/>
            <ref bean="swaggerWriter"/>
        </jaxrs:providers>
    </jaxrs:server>

    <!--Discovery Service POST Endpoint-->
    <jaxws:endpoint
            id="DiscoveryService"
            implementor="org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.impl.DiscoveryServiceImpl"
            address="/discovery/post"/>

    <!--XCEP endpoint for Federated Auth-Policy-->
    <jaxws:endpoint
            id="EnrollmentPolicyService"
            implementor="org.wso2.carbon.device.mgt.mobile.windows.api.services.xcep.impl.CertificateEnrollmentPolicyServiceImpl"
            address="/certificatepolicy/xcep">
        <jaxws:properties>
            <entry key="ws-security.bst.validator" value-ref="customvalidator"/>
        </jaxws:properties>
        <jaxws:inInterceptors>
            <ref bean="wss4jInInterceptor_federated"/>
        </jaxws:inInterceptors>
        <jaxws:handlers>
            <bean id="securityheader"
                  class="org.wso2.carbon.device.mgt.mobile.windows.api.common.util.SOAPSecurityHandler"/>
        </jaxws:handlers>
    </jaxws:endpoint>

    <!--WSTEP Endpoint for Federated Auth-Policy-->
    <jaxws:endpoint
            id="CertificateEnrollmentService"
            implementor="org.wso2.carbon.device.mgt.mobile.windows.api.services.wstep.impl.CertificateEnrollmentServiceImpl"
            address="/deviceenrolment/wstep">
        <jaxws:properties>
            <entry key="ws-security.bst.validator" value-ref="customvalidator"/>
        </jaxws:properties>
        <jaxws:inInterceptors>
            <ref bean="wss4jInInterceptor_federated"/>
        </jaxws:inInterceptors>
        <jaxws:handlers>
            <ref bean="serviceOptionsHandler"/>
        </jaxws:handlers>
    </jaxws:endpoint>

    <!-- Enrollment Endpoint for windows 10 -->
    <jaxws:endpoint
            id="EnrollmentService"
            implementor="org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.impl.EnrollmentServiceImpl"
            address="/deviceenrolment/enrollment">
        <jaxws:properties>
            <entry key="ws-security.bst.validator" value-ref="customvalidator"/>
        </jaxws:properties>
        <jaxws:inInterceptors>
            <ref bean="wss4jInInterceptor_federated"/>
        </jaxws:inInterceptors>
        <jaxws:handlers>
            <ref bean="serviceOptionsHandler"/>
        </jaxws:handlers>
    </jaxws:endpoint>

    <!--Syncml Endpoint-->
    <jaxrs:server id="Syncmlinitial" address="/syncml">
        <jaxrs:serviceBeans>
            <ref bean="Syncml_initial_bean"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <!--Syncml Windows 10 device mgt Endpoint-->
    <jaxrs:server id="Win10devicemgtSession" address="/management">
        <jaxrs:serviceBeans>
            <ref bean="devicemgt_bean"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <!--BST provider Endpoint for returning binary security token after authentication-->
    <jaxrs:server id="bstprovider" address="/federated">
        <jaxrs:serviceBeans>
            <ref bean="bstProviderService"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <jaxrs:server id="services" address="/">
    <jaxrs:serviceBeans>
        <ref bean="configurationMgtService"/>
        <ref bean="deviceMgtAdminService"/>
        <ref bean="swaggerResource"/>
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <ref bean="jsonProvider"/>
        <ref bean="errorHandler"/>
        <ref bean="swaggerWriter"/>
    </jaxrs:providers>
        <jaxrs:properties>
            <!-- This is added to catch interceptor level exceptions in GlobalThrowableMapper. -->
            <entry key="map.cxf.interceptor.fault" value="true" />
        </jaxrs:properties>
    </jaxrs:server>


    <bean id="bstProviderService"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst.impl.BSTProviderImpl"/>
    <bean id="deviceMgtAdminService"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.DeviceManagementAdminServiceImpl"/>
    <bean id="discoveryService"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.impl.DiscoveryServiceImpl"/>
    <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
        <property name="properties">
            <map>
                <entry key="action" value="UsernameToken"/>
                <entry key="passwordType" value="PasswordText"/>
                <entry key="isBSPCompliant" value="false"/>
                <entry key="allowNamespaceQualifiedPasswordTypes" value="true"/>
            </map>
        </property>
    </bean>

    <bean id="wss4jInInterceptor_federated" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
        <property name="properties">
            <map>
                <entry key="action" value="NoSecurity"/>
                <entry key="isBSPCompliant" value="false"/>
            </map>
        </property>
    </bean>
    <bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
    <bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />

    <bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
        <property name="resourcePackage" value="org.wso2.carbon.device.mgt.mobile.windows.api.services"/>
        <property name="version" value="1.0"/>
        <property name="host" value="localhost:9443"/>
        <property name="schemes" value="https" />
        <property name="basePath" value="/api/device-mgt/windows/v1.0"/>
        <property name="title" value="Windows Device Management API Definitions"/>
        <property name="contact" value="dev@wso2.org"/>
        <property name="license" value="Apache 2.0"/>
        <property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
        <property name="scan" value="true"/>
    </bean>
    <bean id="Syncml_initial_bean"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.impl.SyncmlServiceImpl"/>
    <bean id="devicemgt_bean"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.DeviceManagementServiceImpl"/>
    <bean id="customvalidator"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.common.util.BSTValidator"/>
    <bean id="customvalidatoronpremise"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.common.util.UsernameTokenValidator"/>
    <bean id="serviceOptionsHandler"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.wstep.util.MessageHandler"/>
    <bean id="jsonProvider" class="org.wso2.carbon.device.mgt.mobile.windows.api.common.util.GsonMessageBodyHandler"/>
    <bean id="configurationMgtService"
          class="org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.ConfigurationMgtServiceImpl"/>
    <bean id="errorHandler" class="org.wso2.carbon.device.mgt.mobile.windows.api.common.util.ErrorHandler"/>
</beans>

