forked from community/device-mgt-plugins
commit
088eba6b22
@ -1,407 +0,0 @@
|
||||
<!--
|
||||
~ 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.a
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>windows-plugin</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<version>4.2.9-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.mobile.windows.api</artifactId>
|
||||
<name>WSO2 Carbon - Windows JAX-RS API</name>
|
||||
<description>Windows JAX-RS API</description>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
<version>2.3.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<!--<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>-->
|
||||
<warName>api#device-mgt#windows#v1.0</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>deploy</id>
|
||||
<build>
|
||||
<defaultGoal>compile</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
|
||||
<fileset dir="${basedir}/target">
|
||||
<include name="api#device-mgt#windows#v1.0.war" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>client</id>
|
||||
<build>
|
||||
<defaultGoal>test</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
<!--project dependancies-->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-bindings-soap</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-bindings-http</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.security</groupId>
|
||||
<artifactId>wss4j</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-extension-providers</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-ws-security</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.wss4j</groupId>
|
||||
<artifactId>wss4j-ws-security-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
|
||||
<artifactId>axiom</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--dependency>
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>axiom-impl</artifactId>
|
||||
</dependency-->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<!--dependency>
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
<artifactId>spring-ws-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency-->
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-rt</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.messaging.saaj</groupId>
|
||||
<artifactId>saaj-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.orbit.org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.orbit.org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.madgag.spongycastle</groupId>
|
||||
<artifactId>pkix</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.madgag.spongycastle</groupId>
|
||||
<artifactId>prov</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.madgag.spongycastle</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--CDM dependancies-->
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.mobile.windows</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.webapp.authenticator.framework</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.base</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
<version>0.5</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jettison.wso2</groupId>
|
||||
<artifactId>jettison</artifactId>
|
||||
<version>1.1.wso2v1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json.wso2</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>2.0.0.wso2v1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jaxrs</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,277 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.bean;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.SyncmlOperationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.ProfileConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.*;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.OperationCode;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.SyncmlGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "EnterpriseApplication", description = "Information related to Enterprise Application.")
|
||||
public class EnterpriseApplication extends WindowsOperation {
|
||||
|
||||
private static Log log = LogFactory.getLog(EnterpriseApplication.class);
|
||||
|
||||
@ApiModelProperty(name = "packageURL", value = "Package URL.")
|
||||
private HostedAppxApplication hostedAppxApplication;
|
||||
@ApiModelProperty(name = "packageFamilyName", value = "Package family name.")
|
||||
private HostedMSIApplication hostedMSIApplication;
|
||||
|
||||
public HostedAppxApplication getHostedAppxApplication() {
|
||||
return hostedAppxApplication;
|
||||
}
|
||||
|
||||
public void setHostedAppxApplication(HostedAppxApplication hostedAppxApplication) {
|
||||
this.hostedAppxApplication = hostedAppxApplication;
|
||||
}
|
||||
|
||||
public HostedMSIApplication getHostedMSIApplication() {
|
||||
return hostedMSIApplication;
|
||||
}
|
||||
|
||||
public void setHostedMSIApplication(HostedMSIApplication hostedMSIApplication) {
|
||||
this.hostedMSIApplication = hostedMSIApplication;
|
||||
}
|
||||
|
||||
public void validateRequest() throws ProfileConfigurationException {
|
||||
if (getHostedAppxApplication() != null) {
|
||||
if (isNullOrEmpty(getHostedAppxApplication().getpackageUri())) {
|
||||
throw new ProfileConfigurationException(
|
||||
"Appx package URL is not found for enterprise app installation");
|
||||
}
|
||||
if (isNullOrEmpty(getHostedAppxApplication().getpackageFamilyName())) {
|
||||
throw new ProfileConfigurationException(
|
||||
"Appx package Family Name is not found for enterprise app installation");
|
||||
}
|
||||
} else if (getHostedMSIApplication() != null) {
|
||||
if (isNullOrEmpty(getHostedMSIApplication().getProductId())) {
|
||||
throw new ProfileConfigurationException(
|
||||
"MSI product ID is not found for enterprise app installation");
|
||||
}
|
||||
if (isNullOrEmpty(getHostedMSIApplication().getContentUrl())) {
|
||||
throw new ProfileConfigurationException(
|
||||
"MSI product content download URL is not found for enterprise app installation");
|
||||
}
|
||||
if (isNullOrEmpty(getHostedMSIApplication().getFileHash())) {
|
||||
throw new ProfileConfigurationException(
|
||||
"MSI product file hash is not found for enterprise app installation");
|
||||
}
|
||||
} else {
|
||||
throw new ProfileConfigurationException("MSI or APPX payload is not found for enterprise app installation");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> createOperationContent(Operation operation) throws WindowsOperationException {
|
||||
List<Object> enterpriseApplicationContent = new ArrayList<>();
|
||||
if (getHostedAppxApplication() != null) {
|
||||
enterpriseApplicationContent.addAll(createAddTag(operation.getId(),
|
||||
OperationCode.Command.INSTALL_ENTERPRISE_APPX_APPLICATION.getCode(),
|
||||
PluginConstants.ApplicationInstallProperties.PACKAGE_FAMILY_NAME,
|
||||
getHostedAppxApplication().getpackageFamilyName(),
|
||||
PluginConstants.ApplicationInstallProperties.TYPE_APPX));
|
||||
enterpriseApplicationContent.addAll(createExecuteTag(operation.getId(),
|
||||
OperationCode.Command.INSTALL_ENTERPRISE_APPX_APPLICATION.getCode(),
|
||||
PluginConstants.ApplicationInstallProperties.PACKAGE_FAMILY_NAME,
|
||||
getHostedAppxApplication().getpackageFamilyName()
|
||||
+ PluginConstants.ApplicationInstallProperties.HOSTED_INSTALL,
|
||||
PluginConstants.ApplicationInstallProperties.TYPE_APPX));
|
||||
} else if (getHostedMSIApplication() != null) {
|
||||
enterpriseApplicationContent.addAll(createAddTag(operation.getId(),
|
||||
OperationCode.Command.INSTALL_ENTERPRISE_MSI_APPLICATION.getCode(),
|
||||
PluginConstants.ApplicationInstallProperties.PRODUCT_ID, getHostedMSIApplication().getProductId(),
|
||||
PluginConstants.ApplicationInstallProperties.TYPE_MSI));
|
||||
enterpriseApplicationContent.addAll(createExecuteTag(operation.getId(),
|
||||
OperationCode.Command.INSTALL_ENTERPRISE_MSI_APPLICATION.getCode(),
|
||||
PluginConstants.ApplicationInstallProperties.PRODUCT_ID, getHostedMSIApplication().getProductId(),
|
||||
PluginConstants.ApplicationInstallProperties.TYPE_MSI));
|
||||
}
|
||||
return enterpriseApplicationContent;
|
||||
}
|
||||
|
||||
/***
|
||||
* Create add objects required for APPX or MSI application installation which then will be converted as AddTag
|
||||
* elements to add in SyncML XML.
|
||||
*
|
||||
* @param operationId used to set as command ID
|
||||
* @param operationCode is the LocURI
|
||||
* @param replaceOld operation code placeholder
|
||||
* @param replaceNew replace value of operation code placeholder
|
||||
* @param appType APPX or MSI
|
||||
* @return list of AddTag objects
|
||||
*/
|
||||
private List<AddTag> createAddTag(int operationId, String operationCode, String replaceOld, String replaceNew,
|
||||
String appType) {
|
||||
List<AddTag> addTagList = new ArrayList<>();
|
||||
List<ItemTag> itemTagList = new ArrayList<>();
|
||||
AddTag addTag = new AddTag();
|
||||
ItemTag itemTag = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
String locUri = operationCode.replace(replaceOld, replaceNew);
|
||||
targetTag.setLocURI(locUri);
|
||||
itemTag.setTarget(targetTag);
|
||||
itemTagList.add(itemTag);
|
||||
addTag.setCommandId(operationId);
|
||||
addTag.setItems(itemTagList);
|
||||
addTagList.add(addTag);
|
||||
if (PluginConstants.ApplicationInstallProperties.TYPE_APPX.equals(appType)) {
|
||||
if (!isNullOrEmpty(getHostedAppxApplication().getCertificateHash()) && !isNullOrEmpty(
|
||||
getHostedAppxApplication().getEncodedCertificate())) {
|
||||
List<ItemTag> certItemTagList = new ArrayList<>();
|
||||
AddTag certAddTag = new AddTag();
|
||||
ItemTag certItemTag = new ItemTag();
|
||||
MetaTag certMetaTag = new MetaTag();
|
||||
TargetTag certTargetTag = new TargetTag();
|
||||
certTargetTag.setLocURI(OperationCode.Command.INSTALL_ENTERPRISE_APPX_CERTIFICATE.getCode()
|
||||
.replace(PluginConstants.ApplicationInstallProperties.CERT_HASH,
|
||||
getHostedAppxApplication().getCertificateHash()));
|
||||
certMetaTag.setFormat(Constants.META_FORMAT_B64);
|
||||
certItemTag.setTarget(certTargetTag);
|
||||
certItemTag.setMeta(certMetaTag);
|
||||
certItemTag.setData(getHostedAppxApplication().getEncodedCertificate());
|
||||
certItemTagList.add(certItemTag);
|
||||
certAddTag.setCommandId(operationId);
|
||||
certAddTag.setItems(certItemTagList);
|
||||
addTagList.add(certAddTag);
|
||||
}
|
||||
}
|
||||
return addTagList;
|
||||
}
|
||||
|
||||
/***
|
||||
* Create execute objects required for APPX or MSI application installation which then will be converted as
|
||||
* ExecuteTag elements to add in SyncML XML.
|
||||
*
|
||||
* @param operationId used to set as command ID
|
||||
* @param operationCode is the LocURI
|
||||
* @param replaceOld operation code placeholder
|
||||
* @param replaceNew replace value of operation code placeholder
|
||||
* @param appType APPX or MSI
|
||||
* @return list of ExecuteTag objects
|
||||
* @throws WindowsOperationException
|
||||
*/
|
||||
private List<ExecuteTag> createExecuteTag(int operationId, String operationCode, String replaceOld,
|
||||
String replaceNew, String appType) throws WindowsOperationException {
|
||||
List<ExecuteTag> executeTagList = new ArrayList<>();
|
||||
List<ItemTag> itemTagList = new ArrayList<>();
|
||||
ExecuteTag executeTag = new ExecuteTag();
|
||||
ItemTag itemTag = new ItemTag();
|
||||
MetaTag metaTag = new MetaTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
Document document;
|
||||
Element dependencyElement;
|
||||
targetTag.setLocURI(operationCode.replace(replaceOld, replaceNew));
|
||||
metaTag.setFormat(Constants.META_FORMAT_XML);
|
||||
try {
|
||||
if (PluginConstants.ApplicationInstallProperties.TYPE_APPX.equals(appType)) {
|
||||
document = SyncmlGenerator.generateDocument();
|
||||
Element applicationElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.APPLICATION);
|
||||
applicationElement.setAttribute(PluginConstants.ApplicationInstallProperties.PACKAGE_URI,
|
||||
getHostedAppxApplication().getpackageUri());
|
||||
if (!isNullOrEmpty(getHostedAppxApplication().getDependencyPackageUri())) {
|
||||
Element dependenciesElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.DEPENDENCIES);
|
||||
for (String dependency : getHostedAppxApplication().getDependencyPackageUri()) {
|
||||
dependencyElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.DEPENDENCY);
|
||||
dependencyElement
|
||||
.setAttribute(PluginConstants.ApplicationInstallProperties.PACKAGE_URI, dependency);
|
||||
dependenciesElement.appendChild(dependencyElement);
|
||||
}
|
||||
applicationElement.appendChild(dependenciesElement);
|
||||
}
|
||||
itemTag.setElementData(applicationElement);
|
||||
} else if (PluginConstants.ApplicationInstallProperties.TYPE_MSI.equals(appType)) {
|
||||
metaTag.setType(Constants.META_TYPE_TEXT_PLAIN);
|
||||
document = SyncmlGenerator.generateDocument();
|
||||
Element contentURLElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.CONTENT_URL);
|
||||
contentURLElement.setTextContent(getHostedMSIApplication().getContentUrl());
|
||||
Element contentURLListElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.CONTENT_URL_LIST);
|
||||
contentURLListElement.appendChild(contentURLElement);
|
||||
Element downloadElement = document.createElement(PluginConstants.ApplicationInstallProperties.DOWNLOAD);
|
||||
downloadElement.appendChild(contentURLListElement);
|
||||
Element fileHashElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.FILE_HASH);
|
||||
fileHashElement.setTextContent(getHostedMSIApplication().getFileHash());
|
||||
Element validationElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.VALIDATION);
|
||||
validationElement.appendChild(fileHashElement);
|
||||
Element enforcementElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.ENFORCEMENT);
|
||||
Element commandLineElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.COMMAND_LINE);
|
||||
commandLineElement.setTextContent(PluginConstants.ApplicationInstallProperties.COMMAND_LINE_VALUE);
|
||||
enforcementElement.appendChild(commandLineElement);
|
||||
Element timeOutElement = document.createElement(PluginConstants.ApplicationInstallProperties.TIMEOUT);
|
||||
timeOutElement.setTextContent(PluginConstants.ApplicationInstallProperties.TIMEOUT_VALUE);
|
||||
enforcementElement.appendChild(timeOutElement);
|
||||
Element retryCountElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.RETRY_COUNT);
|
||||
retryCountElement.setTextContent(PluginConstants.ApplicationInstallProperties.RETRY_COUNT_VALUE);
|
||||
enforcementElement.appendChild(retryCountElement);
|
||||
Element retryIntervalElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.RETRY_INTERVAL);
|
||||
retryIntervalElement.setTextContent(PluginConstants.ApplicationInstallProperties.RETRY_INTERVAL_VALUE);
|
||||
enforcementElement.appendChild(retryIntervalElement);
|
||||
Element productElement = document.createElement(PluginConstants.ApplicationInstallProperties.PRODUCT);
|
||||
productElement.setAttribute(PluginConstants.ApplicationInstallProperties.VERSION,
|
||||
PluginConstants.ApplicationInstallProperties.VERSION_VALUE);
|
||||
productElement.appendChild(downloadElement);
|
||||
productElement.appendChild(validationElement);
|
||||
productElement.appendChild(enforcementElement);
|
||||
Element msiInstallJobElement = document
|
||||
.createElement(PluginConstants.ApplicationInstallProperties.MSI_INSTALL_JOB);
|
||||
msiInstallJobElement.setAttribute(PluginConstants.ApplicationInstallProperties.ID,
|
||||
PluginConstants.ApplicationInstallProperties.URL_ESCAPED_OPEN_CURLY + getHostedMSIApplication()
|
||||
.getProductId() + PluginConstants.ApplicationInstallProperties.URL_ESCAPED_CLOSE_CURLY);
|
||||
msiInstallJobElement.appendChild(productElement);
|
||||
itemTag.setElementData(msiInstallJobElement);
|
||||
}
|
||||
} catch (SyncmlOperationException e) {
|
||||
String errorMsg = "Error occurred while generating a document to add as a node to Data element of Execute "
|
||||
+ "command which is required to Install " + appType + " application.";
|
||||
log.error(errorMsg);
|
||||
throw new WindowsOperationException(errorMsg, e);
|
||||
}
|
||||
itemTag.setTarget(targetTag);
|
||||
itemTag.setMeta(metaTag);
|
||||
itemTagList.add(itemTag);
|
||||
executeTag.setCommandId(operationId);
|
||||
executeTag.setItems(itemTagList);
|
||||
executeTagList.add(executeTag);
|
||||
return executeTagList;
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.bean;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HostedAppxApplication {
|
||||
|
||||
@ApiModelProperty(name = "packageUri", value = "Package URL.", required = true)
|
||||
private String packageUri;
|
||||
@ApiModelProperty(name = "packageFamilyName", value = "Package family name.", required = true)
|
||||
private String packageFamilyName;
|
||||
@ApiModelProperty(name = "dependencyPackageURLs", value = "Dependency Package URLs.")
|
||||
private List<String> dependencyPackageUri;
|
||||
@ApiModelProperty(name = "certificateHash", value = "Application signed SHA1 certificate hash.")
|
||||
private String certificateHash;
|
||||
@ApiModelProperty(name = "encodedCertificate", value = "Application signed Base64 encoded certificate.")
|
||||
private String encodedCertificate;
|
||||
|
||||
public String getpackageUri() {
|
||||
return packageUri;
|
||||
}
|
||||
|
||||
public void setpackageUri (String packageUri) {
|
||||
this.packageUri = packageUri;
|
||||
}
|
||||
|
||||
public String getpackageFamilyName() {
|
||||
return packageFamilyName;
|
||||
}
|
||||
|
||||
public void setpackageFamilyName(String packageFamilyName) {
|
||||
this.packageFamilyName = packageFamilyName;
|
||||
}
|
||||
|
||||
public List<String> getDependencyPackageUri() {
|
||||
return dependencyPackageUri;
|
||||
}
|
||||
|
||||
public void setDependencyPackageUri(List<String> dependencyPackageUri) {
|
||||
this.dependencyPackageUri = dependencyPackageUri;
|
||||
}
|
||||
|
||||
public String getCertificateHash() {
|
||||
return certificateHash;
|
||||
}
|
||||
|
||||
public void setCertificateHash(String certificateHash) {
|
||||
this.certificateHash = certificateHash;
|
||||
}
|
||||
|
||||
public String getEncodedCertificate() {
|
||||
return encodedCertificate;
|
||||
}
|
||||
|
||||
public void setEncodedCertificate(String encodedCertificate) {
|
||||
this.encodedCertificate = encodedCertificate;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.bean;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class HostedMSIApplication {
|
||||
|
||||
@ApiModelProperty(name = "productId", value = "Product ID.", required = true)
|
||||
private String productId;
|
||||
@ApiModelProperty(name = "contentUrl", value = "Content URL.", required = true)
|
||||
private String contentUrl;
|
||||
@ApiModelProperty(name = "fileHash", value = "File Hash.", required = true)
|
||||
private String fileHash;
|
||||
|
||||
public String getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public String getContentUrl() {
|
||||
return contentUrl;
|
||||
}
|
||||
|
||||
public void setContentUrl(String contentUrl) {
|
||||
this.contentUrl = contentUrl;
|
||||
}
|
||||
|
||||
public String getFileHash() {
|
||||
return fileHash;
|
||||
}
|
||||
|
||||
public void setFileHash(String fileHash) {
|
||||
this.fileHash = fileHash;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.bean;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.WindowsOperationException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/***
|
||||
* This abstract class is used for extending generic functions with regard to operation.
|
||||
*/
|
||||
public abstract class WindowsOperation {
|
||||
|
||||
public abstract List<Object> createOperationContent(Operation operation) throws WindowsOperationException;
|
||||
|
||||
/***
|
||||
* Converts operation object to a json format.
|
||||
*
|
||||
* @return JSON formatted String
|
||||
*/
|
||||
public String toJSON() {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string is null or empty
|
||||
*
|
||||
* @param value string value to check
|
||||
* @return boolean value of null or empty
|
||||
*/
|
||||
public boolean isNullOrEmpty(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
/***
|
||||
* Checks if the given list is null or empty
|
||||
*
|
||||
* @param value string list value to check
|
||||
* @return boolean value of null or empty
|
||||
*/
|
||||
public boolean isNullOrEmpty(List<String> value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.bean.wrapper;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.bean.EnterpriseApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "EnterpriseApplicationBeanWrapper",
|
||||
description = "Information related to Enterprise Application.")
|
||||
public class EnterpriseApplicationBeanWrapper {
|
||||
|
||||
@ApiModelProperty(name = "deviceIDs",
|
||||
value = "List of device Ids to be need to execute operation.", required = true)
|
||||
private List<String> deviceIDs;
|
||||
@ApiModelProperty(name = "operation",
|
||||
value = "Enterprise Application.", required = true)
|
||||
private EnterpriseApplication operation;
|
||||
|
||||
public List<String> getDeviceIDs() {
|
||||
return deviceIDs;
|
||||
}
|
||||
|
||||
public void setDeviceIDs(List<String> deviceIDs) {
|
||||
this.deviceIDs = deviceIDs;
|
||||
}
|
||||
|
||||
public EnterpriseApplication getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public void setOperation(EnterpriseApplication operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
}
|
@ -1,422 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common;
|
||||
|
||||
/**
|
||||
* PluginConstants class for Windows plugin. This class has inner classes for containing constants for
|
||||
* each service.
|
||||
*/
|
||||
public final class PluginConstants {
|
||||
|
||||
//Service endpoints
|
||||
public static final String DISCOVERY_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.DiscoveryService";
|
||||
public static final String CERTIFICATE_ENROLLMENT_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.device.mgt.mobile.windows.api.services.wstep.CertificateEnrollmentService";
|
||||
public static final String CERTIFICATE_ENROLLMENT_POLICY_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.device.mgt.mobile.windows.api.services.xcep.CertificateEnrollmentPolicyService";
|
||||
public static final String ENROLLMENT_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.EnrollmentService";
|
||||
|
||||
//Services' target namespaces
|
||||
public static final String DISCOVERY_SERVICE_TARGET_NAMESPACE =
|
||||
"http://schemas.microsoft.com/windows/management/2012/01/enrollment";
|
||||
public static final String DEVICE_ENROLLMENT_SERVICE_TARGET_NAMESPACE =
|
||||
"http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RSTRC";
|
||||
public static final String CERTIFICATE_ENROLLMENT_POLICY_SERVICE_TARGET_NAMESPACE =
|
||||
"http://schemas.microsoft.com/windows/pki/2009/01/enrollmentpolicy";
|
||||
|
||||
//Certificate enrollment service urls and namespaces
|
||||
public static final String WS_TRUST_TARGET_NAMESPACE =
|
||||
"http://docs.oasis-open.org/ws-sx/ws-trust/200512";
|
||||
public static final String WS_SECURITY_TARGET_NAMESPACE =
|
||||
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
|
||||
public static final String SOAP_AUTHORIZATION_TARGET_NAMESPACE =
|
||||
"http://schemas.xmlsoap.org/ws/2006/12/authorization";
|
||||
|
||||
//Certificate enrollment policy service urls and namespaces
|
||||
public static final String ENROLLMENT_POLICY_TARGET_NAMESPACE =
|
||||
"http://schemas.microsoft.com/windows/pki/2009/01/enrollmentpolicy";
|
||||
public static final String REQUEST_WRAPPER_CLASS_NAME =
|
||||
"com.microsoft.schemas.windows.pki._2009._01.enrollmentpolicy.GetPolicies";
|
||||
public static final String RESPONSE_WRAPPER_CLASS_NAME =
|
||||
"com.microsoft.schemas.windows.pki._2009._01.enrollmentpolicy.GetPoliciesResponse";
|
||||
|
||||
//Servlet Context attributes names
|
||||
public static final String CONTEXT_WAP_PROVISIONING_FILE = "WAP_PROVISIONING_FILE";
|
||||
|
||||
//Message handler constants
|
||||
public static final String CONTENT_LENGTH = "Content-Length";
|
||||
public static final String SECURITY = "Security";
|
||||
public static final String TO = "To";
|
||||
public static final String CXF_REQUEST_URI = "org.apache.cxf.request.uri";
|
||||
|
||||
//Web services media types
|
||||
public static final String SYNCML_MEDIA_TYPE = "application/vnd.syncml.dm+xml";
|
||||
|
||||
/**
|
||||
* Discovery service related other constants
|
||||
*/
|
||||
public final class Discovery {
|
||||
private Discovery() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String DEVICE_ENROLLMENT_SUBDOMAIN = "https://EnterpriseEnrollment.";
|
||||
public static final String CERTIFICATE_ENROLLMENT_POLICY_SERVICE_URL =
|
||||
"/ENROLLMENTSERVER/PolicyEnrollmentWebservice.svc";
|
||||
public static final String CERTIFICATE_ENROLLMENT_SERVICE_URL =
|
||||
"/ENROLLMENTSERVER/DeviceEnrollmentWebservice.svc";
|
||||
public static final String ENROLLMENT_SERVICE_URL =
|
||||
"/ENROLLMENTSERVER/Win10DeviceEnrollmentWebservice.svc";
|
||||
public static final String WAB_URL = "/windows-web-agent/enrollments/windows/login-agent";
|
||||
}
|
||||
|
||||
/**
|
||||
* Certificate enrolment policy service related constants
|
||||
*/
|
||||
public final class CertificateEnrolmentPolicy {
|
||||
private CertificateEnrolmentPolicy() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final int MINIMAL_KEY_LENGTH = 2048;
|
||||
public static final int POLICY_SCHEMA = 3;
|
||||
public static final int HASH_ALGORITHM_OID_REFERENCE = 0;
|
||||
public static final int OID_REFERENCE = 0;
|
||||
public static final String OID = "1.3.14.3.2.29";
|
||||
public static final String OID_DEFAULT_NAME = "szOID_OIWSEC_sha1RSASign";
|
||||
public static final int OID_GROUP = 1;
|
||||
public static final int OID_REFERENCE_ID = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Certificate enrollment Service related constants.
|
||||
*/
|
||||
public final class CertificateEnrolment {
|
||||
private CertificateEnrolment() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String TOKEN_TYPE =
|
||||
"http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentToken";
|
||||
public static final String PARM = "parm";
|
||||
public static final String TYPE = "type";
|
||||
public static final String VALUE = "value";
|
||||
public static final String VALUE_TYPE =
|
||||
"http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentProvisionDoc";
|
||||
public static final String ENCODING_TYPE =
|
||||
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd#base64binary";
|
||||
public static final String CA_CERT = "cacert";
|
||||
public static final String X_509 = "X.509";
|
||||
public static final String WAP_PROVISIONING_XML = "wap-provisioning.xml";
|
||||
public static final String PROVIDER = "BC";
|
||||
public static final String ALGORITHM = "SHA1withRSA";
|
||||
public static final String JKS = "JKS";
|
||||
public static final String SECURITY = "Security";
|
||||
public static final String WSS_SECURITY_UTILITY =
|
||||
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
|
||||
public static final String TIMESTAMP_ID = "Id";
|
||||
public static final String TIMESTAMP_U = "u";
|
||||
public static final String TIMESTAMP = "Timestamp";
|
||||
public static final String TIMESTAMP_0 = "_0";
|
||||
public static final String CREATED = "Created";
|
||||
public static final String EXPIRES = "Expires";
|
||||
public static final String UTF_8 = "utf-8";
|
||||
|
||||
public static final int DOMAIN_SEGMENT = 1;
|
||||
public static final int EMAIL_SEGMENT = 0;
|
||||
public static final int REQUEST_ID = 0;
|
||||
public static final int CA_CERTIFICATE_POSITION = 0;
|
||||
public static final int SIGNED_CERTIFICATE_POSITION = 1;
|
||||
public static final int APPAUTH_USERNAME_POSITION = 21;
|
||||
public static final int APPAUTH_PASSWORD_POSITION = 22;
|
||||
public static final int POLLING_FREQUENCY_POSITION = 24;
|
||||
public static final int SYNCML_PROVISIONING_ADDR_POSITION = 8;
|
||||
public static final int DOMAIN_POSITION = 7;
|
||||
public static final String ENROLL_SUBDOMAIN = "https://EnterpriseEnrollment.";
|
||||
public static final String SYNCML_PROVISIONING_SERVICE_URL = "/Syncml/initialquery";
|
||||
public static final String SYNCML_PROVISIONING_WIN10_SERVICE_URL = "/devicemgt";
|
||||
public static final String ENROLLMENT_DISPOSITION_MESSAGE = "http://schemas.microsoft.com/windows/pki/" +
|
||||
"2009/01/enrollment";
|
||||
}
|
||||
|
||||
/**
|
||||
* SynclML service related constants.
|
||||
*/
|
||||
public final class SyncML {
|
||||
private SyncML() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String SYNCML_SOURCE = "Source";
|
||||
public static final String SYNCML_DATA = "Data";
|
||||
public static final String SYNCML_META = "Meta";
|
||||
public static final String SYNCML_CMD = "Cmd";
|
||||
public static final String SYNCML_CHAL = "ChallengeTag";
|
||||
public static final String SYNCML_CMD_ID = "CmdID";
|
||||
public static final String SYNCML_CMD_REF = "CmdRef";
|
||||
public static final String SYNCML_MESSAGE_REF = "MsgRef";
|
||||
public static final String SYNCML_LOCATION_URI = "LocURI";
|
||||
public static final String SYNCML_TARGET_REF = "TargetRef";
|
||||
|
||||
public static final int SYNCML_FIRST_MESSAGE_ID = 1;
|
||||
public static final int SYNCML_SECOND_MESSAGE_ID = 2;
|
||||
public static final int SYNCML_FIRST_SESSION_ID = 1;
|
||||
public static final int SYNCML_SECOND_SESSION_ID = 2;
|
||||
public static final int OSVERSION_POSITION = 0;
|
||||
public static final int DEVICE_ID_POSITION = 0;
|
||||
public static final int DEVICE_MODEL_POSITION = 2;
|
||||
public static final int DEVICE_MAN_POSITION = 1;
|
||||
public static final int DEVICE_MOD_VER_POSITION = 3;
|
||||
public static final int DEVICE_LANG_POSITION = 4;
|
||||
public static final int IMSI_POSITION = 1;
|
||||
public static final int IMEI_POSITION = 2;
|
||||
public static final int VENDOR_POSITION = 4;
|
||||
public static final int MODEL_POSITION = 5;
|
||||
public static final int MAC_ADDRESS_POSITION = 7;
|
||||
public static final int RESOLUTION_POSITION = 8;
|
||||
public static final int DEVICE_NAME_POSITION = 10;
|
||||
public static final String SYNCML_DATA_ONE = "1";
|
||||
public static final String SYNCML_DATA_ZERO = "0";
|
||||
public static final String OS_VERSION = "OS_VERSION";
|
||||
public static final String IMSI = "IMSI";
|
||||
public static final String IMEI = "IMEI";
|
||||
public static final String VENDOR = "VENDOR";
|
||||
public static final String MODEL = "DEVICE_MODEL";
|
||||
public static final String MAC_ADDRESS = "MAC_ADDRESS";
|
||||
public static final String DEVICE_INFO = "DEVICE_INFO";
|
||||
public static final String DEVICE_NAME = "DEVICE_NAME";
|
||||
public static final String SOFTWARE_VERSION = "SOFTWARE_VERSION";
|
||||
public static final String DEV_ID = "DEV_ID";
|
||||
public static final String MANUFACTURER = "MANUFACTURER";
|
||||
public static final String LANGUAGE = "LANGUAGE";
|
||||
public static final String RESOLUTION = "RESOLUTION";
|
||||
|
||||
// windows 10 codes
|
||||
public static final String TOTAL_RAM = "TOTAL_RAM";// available ram in MB
|
||||
public static final String TOTAL_STORAGE = "TOTAL_STORAGE";
|
||||
public static final String OS_PLATFORM = "OS_PLATFORM";
|
||||
public static final String DEVICE_TYPE = "DEVICE_TYPE";
|
||||
public static final String BATTERY_QUERY = "BATTERY_QUERY";
|
||||
public static final String BATTERY_STATUS = "BATTERY_STATUS";
|
||||
public static final String BATTERY_CHARGE_REMAINING = "BATTERY_CHARGE_REMAINING";
|
||||
public static final String BATTERY_ESTIMATED_RUNTIME = "BATTERY_ESTIMATED_RUNTIME";
|
||||
public static final String MOBILE_ID = "MOBILE_ID";
|
||||
public static final String LONGITUDE = "LONGITUDE";
|
||||
public static final String LATITUDE = "LATITUDE";
|
||||
|
||||
public static final String DEVICE_UNENROLL_META_TYPE = "com.microsoft:mdm.unenrollment.userrequest";
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows device constants.
|
||||
*/
|
||||
public final class DeviceConstants {
|
||||
private DeviceConstants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String DEVICE_ID_NOT_FOUND = "Device Id not found for device found at %s";
|
||||
public static final String DEVICE_ID_SERVICE_NOT_FOUND =
|
||||
"Issue in retrieving device management service instance for device found at %s";
|
||||
}
|
||||
|
||||
/**
|
||||
* Device Operation codes.
|
||||
*/
|
||||
public final class OperationCodes {
|
||||
private OperationCodes() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String DEVICE_LOCK = "DEVICE_LOCK";
|
||||
public static final String DISENROLL = "DISENROLL";
|
||||
public static final String DEVICE_RING = "DEVICE_RING";
|
||||
public static final String WIPE_DATA = "WIPE_DATA";
|
||||
public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE";
|
||||
public static final String LOCK_RESET = "LOCK_RESET";
|
||||
public static final String PIN_CODE = "LOCK_PIN";
|
||||
public static final String CAMERA = "CAMERA";
|
||||
public static final String PASSCODE_POLICY = "PASSCODE_POLICY";
|
||||
public static final String PASSWORD_EXPIRE = "PASSWORD_EXPIRE";
|
||||
public static final String PASSWORD_HISTORY = "PASSWORD_HISTORY";
|
||||
public static final String MAX_PASSWORD_INACTIVE_TIME = "MAX_PASSWORD_INACTIVE_TIME";
|
||||
public static final String MIN_PASSWORD_COMPLEX_CHARACTERS = "MIN_PASSWORD_COMPLEX_CHARACTERS";
|
||||
public static final String ALPHANUMERIC_PASSWORD = "ALPHANUMERIC_PASSWORD";
|
||||
public static final String SIMPLE_PASSWORD = "SIMPLE_PASSWORD";
|
||||
public static final String MIN_PASSWORD_LENGTH = "MIN_PASSWORD_LENGTH";
|
||||
public static final String DEVICE_PASSWORD_ENABLE = "DEVICE_PASSWORD_ENABLE";
|
||||
public static final String PASSWORD_MAX_FAIL_ATTEMPTS = "PASSWORD_MAX_FAIL_ATTEMPTS";
|
||||
public static final String MONITOR = "MONITOR";
|
||||
public static final String CAMERA_STATUS = "CAMERA_STATUS";
|
||||
public static final String POLICY_BUNDLE = "POLICY_BUNDLE";
|
||||
public static final String ENCRYPT_STORAGE_STATUS = "ENCRYPT_STORAGE_STATUS";
|
||||
public static final String DEVICE_PASSWORD_STATUS = "DEVICE_PASSWORD_STATUS";
|
||||
public static final String DEVICE_PASSCODE_DELETE = "DEVICE_PASSCODE_DELETE";
|
||||
public static final String DEVICE_INFO = "DEVICE_INFO";
|
||||
public static final String POLICY_REVOKE = "POLICY_REVOKE";
|
||||
public static final String DEVICE_LOCATION = "DEVICE_LOCATION";
|
||||
public static final String LONGITUDE = "LONGITUDE";
|
||||
public static final String LATITUDE = "LATITUDE";
|
||||
public static final String DEVICE_REBOOT = "DEVICE_REBOOT";
|
||||
public static final String INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin response status code constants.
|
||||
*/
|
||||
public final class StatusCodes {
|
||||
private StatusCodes() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final int MULTI_STATUS_HTTP_CODE = 207;
|
||||
|
||||
}
|
||||
|
||||
public final class WindowsConstant {
|
||||
public static final String DEVICE_TYPE_WINDOWS = "windows";
|
||||
public static final String HEADER_CONTENT_TYPE = "Content-Type";
|
||||
public static final String APPLICATION_JSON = "application/json";
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenant Configuration related constants.
|
||||
*/
|
||||
public final class TenantConfigProperties {
|
||||
private TenantConfigProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String LICENSE_KEY = "windowsLicense";
|
||||
public static final String LANGUAGE_US = "en_US";
|
||||
public static final String CONTENT_TYPE_TEXT = "text";
|
||||
public static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
||||
public static final String DEFAULT_FREQUENCY = "8";
|
||||
public static final String AUTH_POLICY = "authPolicy";
|
||||
public static final String DEFAULT_AUTH_POLICY = "Federated";
|
||||
}
|
||||
|
||||
/**
|
||||
* Policy Configuration related constants.
|
||||
*/
|
||||
public final class PolicyConfigProperties {
|
||||
private PolicyConfigProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String POLICY_ENABLE = "enabled";
|
||||
public static final String ENCRYPTED_ENABLE = "encrypted";
|
||||
public static final String ENABLE_PASSWORD = "enablePassword";
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication related constants.
|
||||
*/
|
||||
public final class AuthenticatorProperties {
|
||||
private AuthenticatorProperties() { throw new AssertionError(); }
|
||||
public static final String MAX_CONNECTION_PER_HOST = "MaxConnectionsPerHost";
|
||||
public static final String MAX_TOTAL_CONNECTIONS = "MaxTotalConnections";
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows version(8.1/10) related constants.
|
||||
*/
|
||||
public final class WindowsVersionProperties {
|
||||
private WindowsVersionProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String REQUESTED_WIN10_VERSION = "3.0";
|
||||
public static final String REQUESTED_WIN81_VERSION = "2.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows10 enrollment property constants.
|
||||
*/
|
||||
|
||||
public final class WindowsEnrollmentProperties {
|
||||
private WindowsEnrollmentProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String DEVICE_NAME = "DeviceName";
|
||||
public static final String DEVICE_VERSION = "OSVersion";
|
||||
public static final String DEVICE_ID = "DeviceID";
|
||||
public static final String IMEI = "MobileEquipmentId";
|
||||
public static final String TYPE = "DeviceType";
|
||||
}
|
||||
|
||||
public final class ApplicationInstallProperties {
|
||||
private ApplicationInstallProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String APPLICATION = "Application";
|
||||
public static final String TYPE_APPX = "APPX";
|
||||
public static final String TYPE_MSI = "MSI";
|
||||
public static final String PACKAGE_FAMILY_NAME = "{PackageFamilyName}";
|
||||
public static final String PRODUCT_ID = "{ProductId}";
|
||||
public static final String CERT_HASH = "{CertHash}";
|
||||
public static final String HOSTED_INSTALL = "/HostedInstall";
|
||||
|
||||
//XML Related Constants
|
||||
public static final String ID = "id";
|
||||
public static final String PACKAGE_URI = "PackageUri";
|
||||
public static final String DEPENDENCIES = "Dependencies";
|
||||
public static final String DEPENDENCY = "Dependency";
|
||||
public static final String CONTENT_URL = "ContentURL";
|
||||
public static final String CONTENT_URL_LIST = "ContentURLList";
|
||||
public static final String DOWNLOAD = "Download";
|
||||
public static final String COMMAND_LINE = "CommandLine";
|
||||
public static final String COMMAND_LINE_VALUE = "/quiet";
|
||||
public static final String FILE_HASH = "FileHash";
|
||||
public static final String VALIDATION = "Validation";
|
||||
public static final String ENFORCEMENT = "Enforcement";
|
||||
public static final String TIMEOUT = "TimeOut";
|
||||
public static final String RETRY_COUNT = "RetryCount";
|
||||
public static final String RETRY_INTERVAL = "RetryInterval";
|
||||
public static final String PRODUCT = "Product";
|
||||
public static final String MSI_INSTALL_JOB = "MsiInstallJob";
|
||||
public static final String VERSION = "version";
|
||||
public static final String VERSION_VALUE = "1.0.0";
|
||||
public static final String TIMEOUT_VALUE = "5";
|
||||
public static final String RETRY_COUNT_VALUE = "3";
|
||||
public static final String RETRY_INTERVAL_VALUE = "5";
|
||||
public static final String LICENSE = "License";
|
||||
public static final String CONTENT = "Content";
|
||||
public static final String URL_ESCAPED_OPEN_CURLY = "%7B";
|
||||
public static final String URL_ESCAPED_CLOSE_CURLY = "%7D";
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common;
|
||||
|
||||
public enum SyncmlCommandType {
|
||||
|
||||
WIFI("WIFI");
|
||||
|
||||
private final String commandType;
|
||||
|
||||
SyncmlCommandType(final String commandType) {
|
||||
this.commandType = commandType;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.commandType;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.OAuthValidationResponse;
|
||||
|
||||
/**
|
||||
* Declares the contract for OAuth2TokenValidator implementations.
|
||||
*/
|
||||
public interface OAuth2TokenValidator {
|
||||
/**
|
||||
* This method gets a string accessToken and validates it and generate the OAuthValidationResponse
|
||||
* containing the validity and user details if valid.
|
||||
*
|
||||
* @param accessToken which need to be validated.
|
||||
* @param resource which need to be validated.
|
||||
* @return OAuthValidationResponse with the validated results.
|
||||
*/
|
||||
OAuthValidationResponse validateToken(String accessToken, String resource) throws OAuthTokenValidationException;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator;
|
||||
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Defines constants to be used inside oauth validators.
|
||||
*/
|
||||
public class OAuthConstants {
|
||||
|
||||
public static final String AUTHORIZATION_HEADER_PREFIX_BEARER = "Bearer";
|
||||
public static final String AUTHORIZATION_HEADER_PREFIX_BASIC = "Basic";
|
||||
public static final String BEARER_TOKEN_TYPE = "bearer";
|
||||
public static final String BEARER_TOKEN_IDENTIFIER = "token";
|
||||
public static final String AUTHENTICATOR_NAME = "OAuthAuthenticator";
|
||||
public static final String RESOURCE_KEY = "resource";
|
||||
public static final String AUTHENTICATOR_CONFIG_PATH = CarbonUtils.getEtcCarbonConfigDirPath() +
|
||||
File.separator + "webapp-authenticator-config.xml";
|
||||
private static final String AUTHENTICATOR_CONFIG_SCHEMA_PATH =
|
||||
"resources/config/schema/webapp-authenticator-config-schema.xsd";
|
||||
}
|
@ -1,215 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator;
|
||||
|
||||
import org.apache.axis2.AxisFault;
|
||||
import org.apache.axis2.client.Options;
|
||||
import org.apache.axis2.client.ServiceClient;
|
||||
import org.apache.axis2.transport.http.HTTPConstants;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpConnectionManager;
|
||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.pool.PoolableObjectFactory;
|
||||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class OAuthTokenValidationStubFactory implements PoolableObjectFactory {
|
||||
private String url;
|
||||
private String basicAuthHeader;
|
||||
private HttpClient httpClient;
|
||||
|
||||
private static final Log log = LogFactory.getLog(
|
||||
org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthTokenValidationStubFactory.class);
|
||||
|
||||
public OAuthTokenValidationStubFactory(String url, String adminUsername, String adminPassword,
|
||||
Properties properties) {
|
||||
this.validateUrl(url);
|
||||
this.url = url;
|
||||
|
||||
this.validateCredentials(adminUsername, adminPassword);
|
||||
this.basicAuthHeader = new String(Base64.encodeBase64((adminUsername + ":" + adminPassword).getBytes()));
|
||||
|
||||
HttpConnectionManager connectionManager = this.createConnectionManager(properties);
|
||||
this.httpClient = new HttpClient(connectionManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
|
||||
*
|
||||
* @param properties Properties to configure MultiThreadedHttpConnectionManager
|
||||
* @return An instance of properly configured MultiThreadedHttpConnectionManager
|
||||
*/
|
||||
private HttpConnectionManager createConnectionManager(Properties properties) {
|
||||
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
throw new IllegalArgumentException("Parameters required to initialize HttpClient instances " +
|
||||
"associated with OAuth token validation service stub are not provided");
|
||||
}
|
||||
String maxConnectionsPerHostParam = properties.getProperty(PluginConstants.
|
||||
AuthenticatorProperties.MAX_CONNECTION_PER_HOST);
|
||||
if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, " +
|
||||
"which is 2, will be used");
|
||||
}
|
||||
} else {
|
||||
params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
|
||||
}
|
||||
|
||||
String maxTotalConnectionsParam = properties.getProperty(PluginConstants.
|
||||
AuthenticatorProperties.MAX_TOTAL_CONNECTIONS);
|
||||
if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, " +
|
||||
"which is 10, will be used");
|
||||
}
|
||||
} else {
|
||||
params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
|
||||
}
|
||||
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
|
||||
connectionManager.setParams(params);
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of PoolingHttpClientConnectionManager using HttpClient 4.x APIs
|
||||
*
|
||||
* @param properties Properties to configure PoolingHttpClientConnectionManager
|
||||
* @return An instance of properly configured PoolingHttpClientConnectionManager
|
||||
*/
|
||||
private HttpClientConnectionManager createClientConnectionManager(Properties properties) {
|
||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
|
||||
if (properties != null) {
|
||||
String maxConnectionsPerHostParam = properties.getProperty(PluginConstants.
|
||||
AuthenticatorProperties.MAX_CONNECTION_PER_HOST);
|
||||
if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, " +
|
||||
"which is 2, will be used");
|
||||
}
|
||||
} else {
|
||||
connectionManager.setDefaultMaxPerRoute(Integer.parseInt(maxConnectionsPerHostParam));
|
||||
}
|
||||
|
||||
String maxTotalConnectionsParam = properties.getProperty(PluginConstants.
|
||||
AuthenticatorProperties.MAX_TOTAL_CONNECTIONS);
|
||||
if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, " +
|
||||
"which is 10, will be used");
|
||||
}
|
||||
} else {
|
||||
connectionManager.setMaxTotal(Integer.parseInt(maxTotalConnectionsParam));
|
||||
}
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Properties, i.e. MaxTotalConnections/MaxConnectionsPerHost, required to tune the " +
|
||||
"HttpClient used in OAuth token validation service stub instances are not provided. " +
|
||||
"Therefore, the defaults, 2/10 respectively, will be used");
|
||||
}
|
||||
}
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object makeObject() throws Exception {
|
||||
return this.createStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyObject(Object o) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateObject(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateObject(Object o) throws Exception {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("OAuth token validate stub instance is activated");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passivateObject(Object o) throws Exception {
|
||||
if (o instanceof OAuth2TokenValidationServiceStub) {
|
||||
OAuth2TokenValidationServiceStub stub = (OAuth2TokenValidationServiceStub) o;
|
||||
stub._getServiceClient().cleanupTransport();
|
||||
}
|
||||
}
|
||||
|
||||
private OAuth2TokenValidationServiceStub createStub() throws OAuthTokenValidationException {
|
||||
OAuth2TokenValidationServiceStub stub;
|
||||
try {
|
||||
stub = new OAuth2TokenValidationServiceStub(url);
|
||||
ServiceClient client = stub._getServiceClient();
|
||||
client.getServiceContext().getConfigurationContext().setProperty(
|
||||
HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
|
||||
|
||||
List<Header> headerList = new ArrayList<>();
|
||||
Header header = new Header();
|
||||
header.setName(HTTPConstants.HEADER_AUTHORIZATION);
|
||||
header.setValue(OAuthConstants.AUTHORIZATION_HEADER_PREFIX_BASIC + " " + basicAuthHeader);
|
||||
headerList.add(header);
|
||||
|
||||
Options options = client.getOptions();
|
||||
options.setProperty(HTTPConstants.HTTP_HEADERS, headerList);
|
||||
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
|
||||
client.setOptions(options);
|
||||
} catch (AxisFault axisFault) {
|
||||
throw new OAuthTokenValidationException("Error occurred while creating the " +
|
||||
"OAuth2TokenValidationServiceStub.", axisFault);
|
||||
}
|
||||
return stub;
|
||||
}
|
||||
|
||||
private void validateUrl(String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
throw new IllegalArgumentException("Url provided as the endpoint of the OAuth token validation service " +
|
||||
"is null");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCredentials(String adminUsername, String adminPassword) {
|
||||
if (adminUsername == null || adminUsername.isEmpty()) {
|
||||
throw new IllegalArgumentException("An appropriate username required to initialize OAuth token " +
|
||||
"validation service stub factory hasn't been provided");
|
||||
}
|
||||
if (adminPassword == null || adminPassword.isEmpty()) {
|
||||
throw new IllegalArgumentException("An appropriate password required to initialize OAuth token " +
|
||||
"validation service stub factory hasn't been provided");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.impl.LocalOAuthValidator;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.impl.RemoteOAuthValidator;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The class validate the configurations and provide the most suitable implementation according to the configuration.
|
||||
* Factory class for OAuthValidator.
|
||||
*/
|
||||
public class OAuthValidatorFactory {
|
||||
|
||||
private static Properties authenticatorProperties;
|
||||
|
||||
public static OAuth2TokenValidator getValidator() {
|
||||
Properties authenticatorProperties = getAuthenticatorProperties();
|
||||
boolean isRemote = Boolean.parseBoolean(authenticatorProperties.getProperty("IsRemote"));
|
||||
if (isRemote) {
|
||||
String url = authenticatorProperties.getProperty("TokenValidationEndpointUrl");
|
||||
if ((url == null) || (url.isEmpty())) {
|
||||
throw new IllegalStateException("OAuth token validation endpoint url is not provided");
|
||||
}
|
||||
String adminUsername = authenticatorProperties.getProperty("Username");
|
||||
if (adminUsername == null) {
|
||||
throw new IllegalStateException("Username to connect to the OAuth token validation endpoint " +
|
||||
"is not provided");
|
||||
}
|
||||
|
||||
String adminPassword = authenticatorProperties.getProperty("Password");
|
||||
if (adminPassword == null) {
|
||||
throw new IllegalStateException("Password to connect to the OAuth token validation endpoint " +
|
||||
"is not provided");
|
||||
}
|
||||
|
||||
Properties validatorProperties = new Properties();
|
||||
validatorProperties.setProperty("MaxTotalConnections", authenticatorProperties.getProperty("MaxTotalConnections"));
|
||||
validatorProperties.setProperty("MaxConnectionsPerHost", authenticatorProperties.getProperty("MaxConnectionsPerHost"));
|
||||
if ((url != null) && (!url.trim().isEmpty())) {
|
||||
url = url + "/services/OAuth2TokenValidationService.OAuth2TokenValidationServiceHttpsSoap12Endpoint/";
|
||||
return new RemoteOAuthValidator(url, adminUsername, adminPassword, validatorProperties);
|
||||
}
|
||||
throw new IllegalStateException("Remote server host can't be empty in OAuthAuthenticator configuration.");
|
||||
}
|
||||
return new LocalOAuthValidator();
|
||||
}
|
||||
|
||||
private static Properties getAuthenticatorProperties() {
|
||||
if (authenticatorProperties == null) {
|
||||
AuthenticatorConfig config = WindowsAPIUtils.getBSTAuthenticatorConfig();
|
||||
if ((config.getParams() != null) && (!config.getParams().isEmpty())) {
|
||||
Properties properties = new Properties();
|
||||
for (AuthenticatorConfig.Parameter param : config.getParams()) {
|
||||
properties.setProperty(param.getName(), param.getValue());
|
||||
}
|
||||
authenticatorProperties = properties;
|
||||
}
|
||||
}
|
||||
return authenticatorProperties;
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuth2TokenValidator;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.OAuthValidationResponse;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
/**
|
||||
* Handles the OAuth2 token validation from the same server using OSGi services.
|
||||
*/
|
||||
public class LocalOAuthValidator implements OAuth2TokenValidator {
|
||||
@Override
|
||||
public OAuthValidationResponse validateToken(String accessToken, String resource)
|
||||
throws OAuthTokenValidationException {
|
||||
|
||||
OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
|
||||
OAuth2TokenValidationRequestDTO.OAuth2AccessToken oauthToken =
|
||||
validationRequest.new OAuth2AccessToken();
|
||||
oauthToken.setTokenType(OAuthConstants.BEARER_TOKEN_TYPE);
|
||||
oauthToken.setIdentifier(accessToken);
|
||||
validationRequest.setAccessToken(oauthToken);
|
||||
|
||||
//Set the resource context param. This will be used in scope validation.
|
||||
OAuth2TokenValidationRequestDTO.TokenValidationContextParam
|
||||
resourceContextParam = validationRequest.new TokenValidationContextParam();
|
||||
resourceContextParam.setKey(OAuthConstants.RESOURCE_KEY);
|
||||
resourceContextParam.setValue(resource);
|
||||
|
||||
OAuth2TokenValidationRequestDTO.TokenValidationContextParam[]
|
||||
tokenValidationContextParams =
|
||||
new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1];
|
||||
tokenValidationContextParams[0] = resourceContextParam;
|
||||
validationRequest.setContext(tokenValidationContextParams);
|
||||
|
||||
org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO tokenValidationResponse =
|
||||
WindowsAPIUtils.getOAuth2TokenValidationService().findOAuthConsumerIfTokenIsValid(
|
||||
validationRequest).getAccessTokenValidationResponse();
|
||||
boolean isValid = tokenValidationResponse.isValid();
|
||||
String username;
|
||||
String tenantDomain;
|
||||
if (isValid) {
|
||||
username = MultitenantUtils.getTenantAwareUsername(
|
||||
tokenValidationResponse.getAuthorizedUser());
|
||||
tenantDomain =
|
||||
MultitenantUtils.getTenantDomain(tokenValidationResponse.getAuthorizedUser());
|
||||
} else {
|
||||
OAuthValidationResponse oAuthValidationResponse = new OAuthValidationResponse();
|
||||
oAuthValidationResponse.setErrorMsg(tokenValidationResponse.getErrorMsg());
|
||||
return oAuthValidationResponse;
|
||||
}
|
||||
return new OAuthValidationResponse(username, tenantDomain, isValid);
|
||||
}
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuth2TokenValidator;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthTokenValidationStubFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.OAuthValidationResponse;
|
||||
import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub;
|
||||
import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO;
|
||||
import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken;
|
||||
import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_TokenValidationContextParam;
|
||||
import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationResponseDTO;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Handles the OAuth2 token validation from remote IS servers using remote OAuthValidation service-stub.
|
||||
*/
|
||||
public class RemoteOAuthValidator implements OAuth2TokenValidator {
|
||||
|
||||
private GenericObjectPool stubs;
|
||||
private static final Log log = LogFactory.getLog(
|
||||
org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.impl.RemoteOAuthValidator.class);
|
||||
|
||||
public RemoteOAuthValidator(String hostURL, String adminUsername, String adminPassword, Properties properties) {
|
||||
this.stubs =
|
||||
new GenericObjectPool(new OAuthTokenValidationStubFactory(
|
||||
hostURL, adminUsername, adminPassword, properties));
|
||||
}
|
||||
|
||||
public OAuthValidationResponse validateToken(String accessToken,
|
||||
String resource) throws OAuthTokenValidationException {
|
||||
OAuth2TokenValidationServiceStub stub = null;
|
||||
OAuth2TokenValidationResponseDTO validationResponse;
|
||||
try {
|
||||
OAuth2TokenValidationRequestDTO validationRequest = createValidationRequest(accessToken, resource);
|
||||
stub = (OAuth2TokenValidationServiceStub) this.stubs.borrowObject();
|
||||
validationResponse =
|
||||
stub.findOAuthConsumerIfTokenIsValid(validationRequest).getAccessTokenValidationResponse();
|
||||
} catch (RemoteException e) {
|
||||
throw new OAuthTokenValidationException("Remote Exception occurred while invoking the Remote " +
|
||||
"IS server for OAuth2 token validation.", e);
|
||||
} catch (Exception e) {
|
||||
throw new OAuthTokenValidationException("Error occurred while borrowing an oauth token validation " +
|
||||
"service stub from the pool", e);
|
||||
} finally {
|
||||
try {
|
||||
this.stubs.returnObject(stub);
|
||||
} catch (Exception e) {
|
||||
log.warn("Error occurred while returning the object back to the oauth token validation service " +
|
||||
"stub pool", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (validationResponse == null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Response returned by the OAuth token validation service is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isValid = validationResponse.getValid();
|
||||
String tenantDomain;
|
||||
String username;
|
||||
if (isValid) {
|
||||
username = MultitenantUtils.getTenantAwareUsername(validationResponse.getAuthorizedUser());
|
||||
tenantDomain = MultitenantUtils.getTenantDomain(validationResponse.getAuthorizedUser());
|
||||
} else {
|
||||
OAuthValidationResponse oAuthValidationResponse = new OAuthValidationResponse();
|
||||
oAuthValidationResponse.setErrorMsg(validationResponse.getErrorMsg());
|
||||
return oAuthValidationResponse;
|
||||
}
|
||||
return new OAuthValidationResponse(username, tenantDomain, isValid);
|
||||
}
|
||||
|
||||
private OAuth2TokenValidationRequestDTO createValidationRequest(String accessToken, String resource) {
|
||||
OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
|
||||
OAuth2TokenValidationRequestDTO_OAuth2AccessToken oauthToken =
|
||||
new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
|
||||
|
||||
oauthToken.setTokenType("bearer");
|
||||
oauthToken.setIdentifier(accessToken);
|
||||
validationRequest.setAccessToken(oauthToken);
|
||||
|
||||
OAuth2TokenValidationRequestDTO_TokenValidationContextParam resourceContextParam =
|
||||
new OAuth2TokenValidationRequestDTO_TokenValidationContextParam();
|
||||
|
||||
resourceContextParam.setKey("resource");
|
||||
resourceContextParam.setValue(resource);
|
||||
|
||||
OAuth2TokenValidationRequestDTO_TokenValidationContextParam[] tokenValidationContextParams =
|
||||
new OAuth2TokenValidationRequestDTO_TokenValidationContextParam[1];
|
||||
|
||||
tokenValidationContextParams[0] = resourceContextParam;
|
||||
validationRequest.setContext(tokenValidationContextParams);
|
||||
|
||||
return validationRequest;
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Class for java CacheEntry
|
||||
*/
|
||||
public class CacheEntry implements Serializable {
|
||||
private String deviceID;
|
||||
private String username;
|
||||
private String ownership;
|
||||
|
||||
private static final long serialVersionUID = 19981017L;
|
||||
|
||||
public String getOwnership() {
|
||||
return ownership;
|
||||
}
|
||||
|
||||
public void setOwnership(String ownership) {
|
||||
this.ownership = ownership;
|
||||
}
|
||||
|
||||
public String getDeviceID() {
|
||||
return deviceID;
|
||||
}
|
||||
|
||||
public void setDeviceID(String deviceID) {
|
||||
this.deviceID = deviceID;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
/**
|
||||
* Class for get device IDS.
|
||||
*/
|
||||
public class Device {
|
||||
|
||||
private String id;
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setID(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ErrorDTO {
|
||||
|
||||
private Long code = null;
|
||||
private String message = null;
|
||||
private String description = null;
|
||||
|
||||
public void setMoreInfo(String moreInfo) {
|
||||
this.moreInfo = moreInfo;
|
||||
}
|
||||
|
||||
public void setCode(Long code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setError(List<ErrorDTO> error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
private String moreInfo = null;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getMoreInfo() {
|
||||
return moreInfo;
|
||||
}
|
||||
|
||||
public List<ErrorDTO> getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("class ErrorDTO {\n");
|
||||
stringBuilder.append(" code: ").append(code).append("\n");
|
||||
stringBuilder.append(" message: ").append(message).append("\n");
|
||||
stringBuilder.append(" description: ").append(description).append("\n");
|
||||
stringBuilder.append(" moreInfo: ").append(moreInfo).append("\n");
|
||||
stringBuilder.append(" error: ").append(error).append("\n");
|
||||
stringBuilder.append("}\n");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private List<ErrorDTO> error = new ArrayList<>();
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel(description = "")
|
||||
public class ErrorListItem {
|
||||
|
||||
@NotNull
|
||||
private String code = null;
|
||||
@NotNull
|
||||
private String message = null;
|
||||
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
@JsonProperty("code")
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ErrorListItem() {}
|
||||
|
||||
public ErrorListItem(String code, String msg) {
|
||||
this.code = code;
|
||||
this.message = msg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description about individual errors occurred
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "Description about individual errors occurred")
|
||||
@JsonProperty("message")
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("errorItem {\n");
|
||||
|
||||
sb.append(" code: ").append(code).append("\n");
|
||||
sb.append(" message: ").append(message).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ErrorResponse {
|
||||
private Long code = null;
|
||||
private String message = null;
|
||||
private String description = null;
|
||||
private String moreInfo = null;
|
||||
private List<ErrorListItem> errorItems = new ArrayList<>();
|
||||
|
||||
@JsonProperty(value = "code")
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Long code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@JsonProperty(value = "message")
|
||||
@ApiModelProperty(required = true, value = "ErrorResponse message.")
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@JsonProperty(value = "description")
|
||||
@ApiModelProperty(value = "A detail description about the error message.")
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@JsonProperty(value = "moreInfo")
|
||||
@ApiModelProperty(value = "Preferably an url with more details about the error.")
|
||||
public String getMoreInfo() {
|
||||
return moreInfo;
|
||||
}
|
||||
|
||||
public void setMoreInfo(String moreInfo) {
|
||||
this.moreInfo = moreInfo;
|
||||
}
|
||||
|
||||
public void addErrorListItem(ErrorListItem item) {
|
||||
this.errorItems.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* If there are more than one error list them out. \nFor example, list out validation errors by each field.
|
||||
*/
|
||||
@JsonProperty(value = "errorItems")
|
||||
@ApiModelProperty(value = "If there are more than one error list them out. \n" +
|
||||
"For example, list out validation errors by each field.")
|
||||
public List<ErrorListItem> getErrorItems() {
|
||||
return errorItems;
|
||||
}
|
||||
|
||||
public void setErrorItems(List<ErrorListItem> error) {
|
||||
this.errorItems = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append("{");
|
||||
// boolean cont = false;
|
||||
// if (code != null) {
|
||||
// cont = true;
|
||||
// sb.append(" \"code\": ").append(code);
|
||||
// }
|
||||
// if (message != null) {
|
||||
// if (cont) {
|
||||
// sb.append(",");
|
||||
// }
|
||||
// cont = true;
|
||||
// sb.append(" \"message\": \"").append(message).append("\"");
|
||||
// }
|
||||
// if (description != null) {
|
||||
// if (cont) {
|
||||
// sb.append(",");
|
||||
// }
|
||||
// cont = true;
|
||||
// sb.append(" \"description\": ").append(description).append("\"");
|
||||
// }
|
||||
// if (moreInfo != null) {
|
||||
// if (cont) {
|
||||
// sb.append(",");
|
||||
// }
|
||||
// cont = true;
|
||||
// sb.append(" \"moreInfo\": \"").append(moreInfo).append("\"");
|
||||
// }
|
||||
// if (error != null && error.size() > 0) {
|
||||
// if (cont) {
|
||||
// sb.append(",");
|
||||
// }
|
||||
// sb.append(" \"errorItems\": ").append(error);
|
||||
// }
|
||||
// sb.append("}");
|
||||
// return sb.toString();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class ErrorResponseBuilder {
|
||||
|
||||
private Long code = null;
|
||||
private String message = null;
|
||||
private String description = null;
|
||||
private String moreInfo = null;
|
||||
private List<ErrorListItem> error;
|
||||
|
||||
|
||||
public ErrorResponseBuilder() {
|
||||
this.error = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ErrorResponseBuilder setCode(long code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ErrorResponseBuilder setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ErrorResponseBuilder setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ErrorResponseBuilder setMoreInfo(String moreInfo) {
|
||||
this.moreInfo = moreInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ErrorResponseBuilder addErrorItem(String code, String msg) {
|
||||
ErrorListItem item = new ErrorListItem();
|
||||
item.setCode(code);
|
||||
item.setMessage(msg);
|
||||
this.error.add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ErrorResponse build() {
|
||||
ErrorResponse errorResponse = new ErrorResponse();
|
||||
errorResponse.setCode(code);
|
||||
errorResponse.setMessage(message);
|
||||
errorResponse.setErrorItems(error);
|
||||
errorResponse.setDescription(description);
|
||||
errorResponse.setMoreInfo(moreInfo);
|
||||
return errorResponse;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.BasicOperation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for set basic operations.
|
||||
*/
|
||||
public class OperationRequest {
|
||||
|
||||
private List<Device> deviceList;
|
||||
private BasicOperation basicOperation;
|
||||
|
||||
public BasicOperation getBasicOperation() {
|
||||
return basicOperation;
|
||||
}
|
||||
|
||||
public void setBasicOperation(BasicOperation basicOperation) {
|
||||
this.basicOperation = basicOperation;
|
||||
}
|
||||
|
||||
public List<Device> getDeviceList() {
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
public void setDeviceList(List<Device> deviceList) {
|
||||
this.deviceList = deviceList;
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
|
||||
|
||||
/**
|
||||
* Class for challenge token
|
||||
*/
|
||||
public class Token {
|
||||
private String challengeToken;
|
||||
|
||||
public String getChallengeToken() {
|
||||
return challengeToken;
|
||||
}
|
||||
|
||||
public void setChallengeToken(String challengeToken) {
|
||||
this.challengeToken = challengeToken;
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for authentication failures in windows device enrollment.
|
||||
*/
|
||||
public class AuthenticationException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public AuthenticationException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public AuthenticationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public AuthenticationException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public AuthenticationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public AuthenticationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Exception class for bad request failures
|
||||
*/
|
||||
public class BadRequestException extends WebApplicationException {
|
||||
|
||||
public BadRequestException(ErrorResponse error) {
|
||||
super(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for Certificate generation failures in WSTEP stage.
|
||||
*/
|
||||
public class CertificateGenerationException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public CertificateGenerationException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public CertificateGenerationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public CertificateGenerationException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public CertificateGenerationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public CertificateGenerationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for file reading/writing failures.
|
||||
*/
|
||||
public class FileOperationException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public FileOperationException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public FileOperationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public FileOperationException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public FileOperationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public FileOperationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for Keystore generation failures.
|
||||
*/
|
||||
public class KeyStoreGenerationException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public KeyStoreGenerationException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public KeyStoreGenerationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public KeyStoreGenerationException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public KeyStoreGenerationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public KeyStoreGenerationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* MDMAPIUtils class provides utility function which are used by CDM REST-API classes.
|
||||
*/
|
||||
public class MDMAPIException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 7950151650447893900L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public MDMAPIException(String msg, Exception e) {
|
||||
super(msg, e);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public MDMAPIException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public MDMAPIException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public MDMAPIException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MDMAPIException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Custom exception to be thrown inside OAuthTokenValidation related functionality.
|
||||
*/
|
||||
public class OAuthTokenValidationException extends Exception {
|
||||
private static final long serialVersionUID = -3151279311929070297L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public OAuthTokenValidationException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OAuthTokenValidationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public OAuthTokenValidationException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OAuthTokenValidationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public OAuthTokenValidationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
public class ProfileConfigurationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 8025559931927889261L;
|
||||
|
||||
public ProfileConfigurationException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
}
|
||||
|
||||
public ProfileConfigurationException(String errorMsg, Throwable throwable) {
|
||||
super(errorMsg, throwable);
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for bad format syncml message exceptions.
|
||||
*/
|
||||
public class SyncmlMessageFormatException extends Exception {
|
||||
private String errorMessage;
|
||||
|
||||
public SyncmlMessageFormatException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SyncmlMessageFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SyncmlMessageFormatException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SyncmlMessageFormatException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SyncmlMessageFormatException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for syncml Operation and policy related errors.
|
||||
*/
|
||||
public class SyncmlOperationException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public SyncmlOperationException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SyncmlOperationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SyncmlOperationException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SyncmlOperationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SyncmlOperationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorDTO;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class UnexpectedServerErrorException extends WebApplicationException {
|
||||
private String message;
|
||||
private static final long serialVersionUID = 147943579458906890L;
|
||||
|
||||
public UnexpectedServerErrorException(ErrorResponse error) {
|
||||
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
|
||||
}
|
||||
public UnexpectedServerErrorException(ErrorDTO errorDTO) {
|
||||
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(errorDTO)
|
||||
.header(PluginConstants.WindowsConstant.HEADER_CONTENT_TYPE, PluginConstants.WindowsConstant.APPLICATION_JSON)
|
||||
.build());
|
||||
message = errorDTO.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for property/provisioning XML file reading failures.
|
||||
*/
|
||||
public class WAPProvisioningException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public WAPProvisioningException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WAPProvisioningException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WAPProvisioningException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WAPProvisioningException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public WAPProvisioningException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Custom class for windows device configurations.
|
||||
*/
|
||||
public class WindowsConfigurationException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
private static final long serialVersionUID = 7950151650447893900L;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public WindowsConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public WindowsConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WindowsConfigurationException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public WindowsConfigurationException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public WindowsConfigurationException(String msg, Exception exception) {
|
||||
super(msg, exception);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
/**
|
||||
* Exception class for general WSTEP messaging/message generation failures.
|
||||
*/
|
||||
public class WindowsDeviceEnrolmentException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public WindowsDeviceEnrolmentException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WindowsDeviceEnrolmentException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WindowsDeviceEnrolmentException(String message, Exception nestedEx) {
|
||||
super(message, nestedEx);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WindowsDeviceEnrolmentException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public WindowsDeviceEnrolmentException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
|
||||
public class WindowsEnrollmentTokenException extends Exception {
|
||||
private static final long serialVersionUID = -2297311387874900305L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public WindowsEnrollmentTokenException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public WindowsEnrollmentTokenException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public WindowsEnrollmentTokenException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public WindowsEnrollmentTokenException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WindowsEnrollmentTokenException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Exception Class for windows operations related exceptions
|
||||
*/
|
||||
public class WindowsOperationsException extends WebApplicationException {
|
||||
|
||||
public WindowsOperationsException(Message message, MediaType mediaType) {
|
||||
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).
|
||||
type(mediaType).build());
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
/**
|
||||
* DTO class to hold the information of authenticated user.
|
||||
*/
|
||||
public class AuthenticationInfo {
|
||||
private String message;
|
||||
private String username;
|
||||
private String tenantDomain;
|
||||
private int tenantId = -1;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getTenantDomain() {
|
||||
return tenantDomain;
|
||||
}
|
||||
|
||||
public void setTenantDomain(String tenantDomain) {
|
||||
this.tenantDomain = tenantDomain;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.ws.security.WSSecurityException;
|
||||
import org.apache.ws.security.handler.RequestData;
|
||||
import org.apache.ws.security.message.token.BinarySecurity;
|
||||
import org.apache.ws.security.validate.Credential;
|
||||
import org.apache.ws.security.validate.Validator;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthValidatorFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.AuthenticationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.impl.dto.MobileCacheEntry;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Validator class for user authentication checking the default carbon user store.
|
||||
*/
|
||||
public class BSTValidator implements Validator {
|
||||
|
||||
/**
|
||||
* This method validates the binary security token in SOAP message coming from the device.
|
||||
*
|
||||
* @param credential - binary security token credential object.
|
||||
* @param requestData - Request data associated with the request.
|
||||
* @return - Credential object if authentication is success, or null if not success.
|
||||
* @throws WSSecurityException
|
||||
*/
|
||||
@Override
|
||||
public Credential validate(Credential credential, RequestData requestData) throws WSSecurityException {
|
||||
String bearerToken;
|
||||
String requestedUri;
|
||||
Credential userCredentials;
|
||||
|
||||
HashMap msgContext = (HashMap) requestData.getMsgContext();
|
||||
requestedUri = msgContext.get(PluginConstants.CXF_REQUEST_URI).toString();
|
||||
BinarySecurity binarySecurityTokenObject = credential.getBinarySecurityToken();
|
||||
String binarySecurityToken = binarySecurityTokenObject.getElement().getFirstChild().getTextContent();
|
||||
Base64 base64 = new Base64();
|
||||
bearerToken = new String(base64.decode(binarySecurityToken));
|
||||
AuthenticationInfo authenticationInfo;
|
||||
try {
|
||||
authenticationInfo = validateRequest(requestedUri, bearerToken);
|
||||
WindowsAPIUtils.startTenantFlow(authenticationInfo);
|
||||
|
||||
if (authenticate(binarySecurityToken, authenticationInfo)) {
|
||||
userCredentials = credential;
|
||||
} else {
|
||||
throw new WindowsDeviceEnrolmentException(
|
||||
"Authentication failure due to invalid binary security token.");
|
||||
}
|
||||
} catch (AuthenticationException e) {
|
||||
throw new WSSecurityException("Failure occurred in the BST validator.", e);
|
||||
} catch (WindowsDeviceEnrolmentException e) {
|
||||
throw new WSSecurityException("Authentication failure occurred due to binary security token.", e);
|
||||
} catch (OAuthTokenValidationException e) {
|
||||
throw new WSSecurityException(
|
||||
"Failed to authenticate the incoming request due to oauth token validation error.", e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
return userCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method authenticates the client who comes with binary security token.
|
||||
*
|
||||
* @param binarySecurityToken - Binary security token received in the SOAP message header.
|
||||
* @return - Authentication status.
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
private boolean authenticate(String binarySecurityToken, AuthenticationInfo authenticationInfo) throws
|
||||
AuthenticationException {
|
||||
WindowsAPIUtils.startTenantFlow(authenticationInfo);
|
||||
MobileCacheEntry cacheEntry;
|
||||
try {
|
||||
cacheEntry = DeviceUtil.getTokenEntry(binarySecurityToken);
|
||||
if (cacheEntry != null) {
|
||||
String username = cacheEntry.getUsername();
|
||||
return username != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (WindowsDeviceEnrolmentException e) {
|
||||
throw new AuthenticationException("Authentication failure when fetching token entry", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate SOAP request token.
|
||||
*
|
||||
* @param requestedUri -Requested endpoint URI.
|
||||
* @param binarySecurityToken -Binary security token comes from the soap request message.
|
||||
* @return returns authorized user information.
|
||||
* @throws WindowsDeviceEnrolmentException
|
||||
*/
|
||||
private AuthenticationInfo validateRequest(String requestedUri, String binarySecurityToken)
|
||||
throws WindowsDeviceEnrolmentException, OAuthTokenValidationException {
|
||||
|
||||
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
|
||||
String resource = requestedUri + ":POST";
|
||||
OAuthValidationResponse oAuthValidationResponse = OAuthValidatorFactory.getValidator().
|
||||
validateToken(binarySecurityToken, resource);
|
||||
try {
|
||||
if (oAuthValidationResponse.isValid()) {
|
||||
String username = oAuthValidationResponse.getUserName();
|
||||
String tenantDomain = oAuthValidationResponse.getTenantDomain();
|
||||
|
||||
authenticationInfo.setUsername(username);
|
||||
authenticationInfo.setTenantDomain(tenantDomain);
|
||||
authenticationInfo.setTenantId(WindowsAPIUtils.getTenantIdOFUser(username + "@" + tenantDomain));
|
||||
} else {
|
||||
authenticationInfo.setMessage(oAuthValidationResponse.getErrorMsg());
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new WindowsDeviceEnrolmentException(
|
||||
"Authentication failure due to invalid binary security token.", e);
|
||||
}
|
||||
return authenticationInfo;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This class performs one time operations.
|
||||
*/
|
||||
public class ContextInitializer implements ServletContextListener {
|
||||
|
||||
/**
|
||||
* This method loads wap-provisioning file and sets wap-provisioning file as attribute in servlet context.
|
||||
*
|
||||
* @param servletContextEvent - Uses when servlet communicating with servlet container.
|
||||
*/
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||
ServletContext servletContext = servletContextEvent.getServletContext();
|
||||
|
||||
File wapProvisioningFile = new File(getClass().getClassLoader().getResource(
|
||||
PluginConstants.CertificateEnrolment.WAP_PROVISIONING_XML).getFile());
|
||||
servletContext.setAttribute(PluginConstants.CONTEXT_WAP_PROVISIONING_FILE, wapProvisioningFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for holding valid and invalid devices.
|
||||
*/
|
||||
public class DeviceIDHolder {
|
||||
|
||||
private List<String> invalidDeviceIdList;
|
||||
private List<DeviceIdentifier> validDeviceIDList;
|
||||
|
||||
public List<String> getInvalidDeviceIdList() {
|
||||
return invalidDeviceIdList;
|
||||
}
|
||||
|
||||
public void setInvalidDeviceIdList(List<String> invalidDeviceIdList) {
|
||||
this.invalidDeviceIdList = invalidDeviceIdList;
|
||||
}
|
||||
|
||||
public List<DeviceIdentifier> getValidDeviceIDList() {
|
||||
return validDeviceIDList;
|
||||
}
|
||||
|
||||
public void setValidDeviceIDList(List<DeviceIdentifier> validDeviceIDList) {
|
||||
this.validDeviceIDList = validDeviceIDList;
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsTokenService;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.impl.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.impl.dto.MobileCacheEntry;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Class for generate random token for XCEP and WSTEP.
|
||||
*/
|
||||
public class DeviceUtil {
|
||||
|
||||
private static WindowsTokenService tokenService;
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceUtil.class);
|
||||
|
||||
static {
|
||||
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
|
||||
}
|
||||
|
||||
public static String generateRandomToken() {
|
||||
return String.valueOf(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public static void persistChallengeToken(String token, String deviceID, String username)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
try {
|
||||
if(tokenService == null) {
|
||||
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
|
||||
}
|
||||
MobileCacheEntry existingCacheEntry = tokenService.getCacheToken(token);
|
||||
PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
if (existingCacheEntry == null) {
|
||||
MobileCacheEntry newCacheEntry = new MobileCacheEntry();
|
||||
newCacheEntry.setDeviceID(deviceID);
|
||||
newCacheEntry.setUsername(username);
|
||||
newCacheEntry.setCacheToken(token);
|
||||
newCacheEntry.setTenantDomain(carbonCtx.getTenantDomain());
|
||||
newCacheEntry.setTenanatID(carbonCtx.getTenantId());
|
||||
tokenService.saveCacheToken(newCacheEntry);
|
||||
} else {
|
||||
existingCacheEntry.setDeviceID(deviceID);
|
||||
existingCacheEntry.setCacheToken(token);
|
||||
tokenService.updateCacheToken(existingCacheEntry);
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
String msg = "Error occurred when saving cache token for device: " + deviceID;
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static MobileCacheEntry getTokenEntry(String token)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
MobileCacheEntry tokenEntry;
|
||||
try {
|
||||
if (tokenService == null) {
|
||||
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
|
||||
}
|
||||
tokenEntry = tokenService.getCacheToken(token);
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
String msg = "Error occurred when retrieving enrollment token.";
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
}
|
||||
return tokenEntry;
|
||||
}
|
||||
|
||||
public static MobileCacheEntry getTokenEntryFromDeviceId(String deviceId)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
MobileCacheEntry tokenEntry;
|
||||
try {
|
||||
if (tokenService == null) {
|
||||
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
|
||||
}
|
||||
tokenEntry = tokenService.getCacheTokenFromDeviceId(deviceId);
|
||||
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
String msg = "Error occurred when retrieving enrollment token.";
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
}
|
||||
return tokenEntry;
|
||||
}
|
||||
|
||||
public static void removeTokenEntry(String token) {
|
||||
try {
|
||||
if (tokenService == null) {
|
||||
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
|
||||
}
|
||||
tokenService.removeCacheToken(token);
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
String msg = "Error occurred when removing enrollment token.";
|
||||
log.error(msg);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
||||
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
/**
|
||||
* Class for handle response exceptions.
|
||||
*/
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class ErrorHandler implements ExceptionMapper<WindowsConfigurationException> {
|
||||
|
||||
public Response toResponse(WindowsConfigurationException exception) {
|
||||
ErrorMessage errorMessage = new ErrorMessage();
|
||||
errorMessage.setErrorMessage(exception.getErrorMessage());
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate Error Messages for responses.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
public class ErrorMessage {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.ext.MessageBodyReader;
|
||||
import javax.ws.rs.ext.MessageBodyWriter;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
|
||||
/**
|
||||
* Class for parse Gson Messages.
|
||||
*/
|
||||
@Provider
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Consumes(APPLICATION_JSON)
|
||||
public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> {
|
||||
private Gson gson;
|
||||
private static final String UTF_8 = "UTF-8";
|
||||
|
||||
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Gson getGson() {
|
||||
if (gson == null) {
|
||||
final GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gson = gsonBuilder.create();
|
||||
}
|
||||
return gson;
|
||||
}
|
||||
|
||||
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||
MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream entityStream)
|
||||
throws IOException, WebApplicationException {
|
||||
InputStreamReader reader = new InputStreamReader(entityStream, UTF_8);
|
||||
try {
|
||||
return getGson().fromJson(reader, type);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getSize(Object o, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void writeTo(Object object, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||
MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream entityStream)
|
||||
throws IOException, WebApplicationException {
|
||||
|
||||
OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
|
||||
try {
|
||||
getGson().toJson(object, type, writer);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for generate response Messages.
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class Message {
|
||||
private String responseCode;
|
||||
private String responseMessage;
|
||||
|
||||
@XmlElement
|
||||
public String getResponseMessage() {
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
public void setResponseMessage(String responseMessage) {
|
||||
this.responseMessage = responseMessage;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public void setResponseCode(String responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
/**
|
||||
* Class for OAuthValidation Response.
|
||||
*/
|
||||
public class OAuthValidationResponse {
|
||||
|
||||
private String userName;
|
||||
private String tenantDomain;
|
||||
private boolean isValid;
|
||||
private String errorMsg;
|
||||
|
||||
public OAuthValidationResponse() {
|
||||
}
|
||||
|
||||
public OAuthValidationResponse(String userName, String tenantDomain, boolean isValid) {
|
||||
this.userName = userName;
|
||||
this.tenantDomain = tenantDomain;
|
||||
this.isValid = isValid;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getTenantDomain() {
|
||||
return tenantDomain;
|
||||
}
|
||||
|
||||
public void setTenantDomain(String tenantDomain) {
|
||||
this.tenantDomain = tenantDomain;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return isValid;
|
||||
}
|
||||
|
||||
public void setIsValid(boolean isValid) {
|
||||
this.isValid = isValid;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.handler.MessageContext;
|
||||
import javax.xml.ws.handler.soap.SOAPHandler;
|
||||
import javax.xml.ws.handler.soap.SOAPMessageContext;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class for handle SOAP message security.
|
||||
*/
|
||||
public class SOAPSecurityHandler implements SOAPHandler<SOAPMessageContext> {
|
||||
|
||||
/**
|
||||
* This method resolves the security header coming in the SOAP message.
|
||||
*
|
||||
* @return - Security Header
|
||||
*/
|
||||
@Override
|
||||
public Set<QName> getHeaders() {
|
||||
QName securityHeader = new QName(PluginConstants.WS_SECURITY_TARGET_NAMESPACE, PluginConstants.SECURITY);
|
||||
HashSet<QName> headers = new HashSet<QName>();
|
||||
headers.add(securityHeader);
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(SOAPMessageContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFault(SOAPMessageContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(MessageContext context) {
|
||||
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.apache.ws.security.WSSecurityException;
|
||||
import org.apache.ws.security.handler.RequestData;
|
||||
import org.apache.ws.security.validate.Credential;
|
||||
import org.apache.ws.security.validate.Validator;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.AuthenticationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.user.api.UserRealm;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
/**
|
||||
* Validator class for user authentication checking the default carbon user store.
|
||||
*/
|
||||
public class UsernameTokenValidator implements Validator {
|
||||
|
||||
private static final int USER_SEGMENT = 0;
|
||||
private static final int DOMAIN_SEGMENT = 1;
|
||||
private static final String DELIMITER = "@";
|
||||
|
||||
/**
|
||||
* This method validates the username token in SOAP message coming from the device.
|
||||
*
|
||||
* @param credential - Username token credentials coming from device
|
||||
* @param requestData - Request data associated with the request
|
||||
* @return - Credential object if authentication is success, or null if not success
|
||||
* @throws WSSecurityException
|
||||
*/
|
||||
@Override
|
||||
public Credential validate(Credential credential, RequestData requestData) throws
|
||||
WSSecurityException {
|
||||
|
||||
String domainUser = credential.getUsernametoken().getName();
|
||||
String[] domainUserArray = domainUser.split(DELIMITER);
|
||||
Credential returnCredentials;
|
||||
String user = domainUserArray[USER_SEGMENT];
|
||||
String domain = domainUserArray[DOMAIN_SEGMENT];
|
||||
String password = credential.getUsernametoken().getPassword();
|
||||
|
||||
try {
|
||||
if (authenticate(user, password, domain)) {
|
||||
returnCredentials = credential;
|
||||
} else {
|
||||
throw new WindowsDeviceEnrolmentException("Authentication failure due to incorrect credentials.");
|
||||
}
|
||||
} catch (AuthenticationException e) {
|
||||
throw new WSSecurityException("Failure occurred in the BST validator.", e);
|
||||
} catch (WindowsDeviceEnrolmentException e) {
|
||||
throw new WSSecurityException("Authentication Failure occurred due to binary security token.", e);
|
||||
}
|
||||
return returnCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method authenticate the user checking the carbon default user store.
|
||||
*
|
||||
* @param username - Username in username token
|
||||
* @param password - Password in username token
|
||||
* @param tenantDomain - Tenant domain is extracted from the username
|
||||
* @return - Returns boolean representing authentication result
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public boolean authenticate(String username, String password, String tenantDomain) throws
|
||||
AuthenticationException {
|
||||
|
||||
try {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||
|
||||
if (realmService == null) {
|
||||
throw new AuthenticationException("RealmService not initialized.");
|
||||
}
|
||||
int tenantId;
|
||||
if (tenantDomain == null || tenantDomain.trim().isEmpty()) {
|
||||
tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
||||
} else {
|
||||
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
|
||||
}
|
||||
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
|
||||
throw new AuthenticationException("Invalid tenant domain " + tenantDomain);
|
||||
}
|
||||
UserRealm userRealm = realmService.getTenantUserRealm(tenantId);
|
||||
return userRealm.getUserStoreManager().authenticate(username, password);
|
||||
} catch (UserStoreException e) {
|
||||
throw new AuthenticationException("User store is not initialized.", e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,268 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsTokenService;
|
||||
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
|
||||
import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
import org.wso2.carbon.user.api.TenantManager;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig;
|
||||
import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfigService;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for get Windows API utilities.
|
||||
*/
|
||||
public class WindowsAPIUtils {
|
||||
|
||||
private static Log log = LogFactory.getLog(WindowsAPIUtils.class);
|
||||
|
||||
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
|
||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
identifier.setId(deviceId);
|
||||
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||
if (deviceManagementProviderService == null) {
|
||||
throw new IllegalStateException("Device Management service has not initialized.");
|
||||
}
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
|
||||
public static NotificationManagementService getNotificationManagementService() {
|
||||
NotificationManagementService notificationManagementService;
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
notificationManagementService =
|
||||
(NotificationManagementService) ctx.getOSGiService(NotificationManagementService.class, null);
|
||||
if (notificationManagementService == null) {
|
||||
throw new IllegalStateException("Notification Management service not initialized.");
|
||||
}
|
||||
return notificationManagementService;
|
||||
}
|
||||
|
||||
public static WindowsTokenService getEnrollmentTokenService() {
|
||||
WindowsTokenService tokenService;
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
tokenService = (WindowsTokenService)
|
||||
ctx.getOSGiService(WindowsTokenService.class, null);
|
||||
|
||||
if(tokenService == null) {
|
||||
throw new IllegalStateException("WindowsTokenService is not initialized");
|
||||
}
|
||||
return tokenService;
|
||||
}
|
||||
|
||||
public static MediaType getResponseMediaType(String acceptHeader) {
|
||||
MediaType responseMediaType;
|
||||
if (MediaType.WILDCARD.equals(acceptHeader)) {
|
||||
responseMediaType = MediaType.APPLICATION_JSON_TYPE;
|
||||
} else {
|
||||
responseMediaType = MediaType.valueOf(acceptHeader);
|
||||
}
|
||||
return responseMediaType;
|
||||
}
|
||||
|
||||
public static Response getOperationResponse(List<String> deviceIDs, Operation operation)
|
||||
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||
if (deviceIDs == null || deviceIDs.size() == 0) {
|
||||
String errorMessage = "Device identifier list is empty";
|
||||
log.error(errorMessage);
|
||||
throw new BadRequestException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
||||
}
|
||||
DeviceIdentifier deviceIdentifier;
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
for (String deviceId : deviceIDs) {
|
||||
deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(deviceId);
|
||||
deviceIdentifier.setType(PluginConstants.WindowsConstant.DEVICE_TYPE_WINDOWS);
|
||||
deviceIdentifiers.add(deviceIdentifier);
|
||||
}
|
||||
Activity activity = getDeviceManagementService().addOperation(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, operation, deviceIdentifiers);
|
||||
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||
}
|
||||
|
||||
public static PolicyManagerService getPolicyManagerService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
PolicyManagerService policyManagerService =
|
||||
(PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null);
|
||||
if (policyManagerService == null) {
|
||||
throw new IllegalStateException("Policy Manager service has not initialized");
|
||||
}
|
||||
return policyManagerService;
|
||||
}
|
||||
|
||||
public static void updateOperation(String deviceId, Operation operation)
|
||||
throws OperationManagementException {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(deviceId);
|
||||
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
getDeviceManagementService().updateOperation(deviceIdentifier, operation);
|
||||
}
|
||||
|
||||
public static List<? extends Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException, DeviceManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
pendingDataOperations = org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils.
|
||||
getDeviceManagementService().getOperationsByDeviceAndStatus(
|
||||
deviceIdentifier, Operation.Status.PENDING);
|
||||
return pendingDataOperations;
|
||||
}
|
||||
|
||||
public static PlatformConfiguration getTenantConfiguration() throws DeviceManagementException {
|
||||
return getDeviceManagementService().getConfiguration(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
}
|
||||
|
||||
public static int getTenantIdOFUser(String username) throws DeviceManagementException {
|
||||
int tenantId = 0;
|
||||
RealmService realmService;
|
||||
String domainName = MultitenantUtils.getTenantDomain(username);
|
||||
if (domainName != null) {
|
||||
try {
|
||||
if ((realmService = IdentityTenantUtil.getRealmService()) != null) {
|
||||
TenantManager tenantManager = realmService.getTenantManager();
|
||||
tenantId = tenantManager.getTenantId(domainName);
|
||||
}
|
||||
if (realmService == null) {
|
||||
throw new IllegalStateException("Realm service has not initialized.");
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
throw new DeviceManagementException("Error when getting the tenant id from the tenant domain : "
|
||||
+ domainName, e);
|
||||
}
|
||||
}
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public static OAuth2TokenValidationService getOAuth2TokenValidationService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
OAuth2TokenValidationService oAuth2TokenValidationService =
|
||||
(OAuth2TokenValidationService) ctx.getOSGiService(OAuth2TokenValidationService.class, null);
|
||||
if (oAuth2TokenValidationService == null) {
|
||||
throw new IllegalStateException("OAuth2TokenValidation service has not initialized.");
|
||||
}
|
||||
return oAuth2TokenValidationService;
|
||||
}
|
||||
|
||||
public static AuthenticatorConfig getBSTAuthenticatorConfig() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
AuthenticatorConfigService authenticatorConfigService =
|
||||
(AuthenticatorConfigService) ctx.getOSGiService(AuthenticatorConfigService.class, null);
|
||||
if (authenticatorConfigService == null) {
|
||||
throw new IllegalStateException("AuthenticatorConfiguration service has not initialized.");
|
||||
}
|
||||
AuthenticatorConfig authenticatorConfig = authenticatorConfigService.getAuthenticatorConfig("BST");
|
||||
if (authenticatorConfig == null) {
|
||||
throw new IllegalStateException("BST authenticatorConfig has not initialized.");
|
||||
}
|
||||
return authenticatorConfig;
|
||||
}
|
||||
|
||||
public static void startTenantFlow(AuthenticationInfo authenticationInfo) {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
if (authenticationInfo.getTenantDomain() == null) {
|
||||
privilegedCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
privilegedCarbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
} else {
|
||||
privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId());
|
||||
privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain());
|
||||
}
|
||||
privilegedCarbonContext.setUsername(authenticationInfo.getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get tenant configurations.
|
||||
*
|
||||
* @return List of Configurations entries.
|
||||
* @throws DeviceManagementException
|
||||
*/
|
||||
public static List<ConfigurationEntry> getTenantConfigurationData() throws DeviceManagementException {
|
||||
PlatformConfiguration tenantConfiguration;
|
||||
if ((tenantConfiguration = org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils
|
||||
.getTenantConfiguration()) != null) {
|
||||
return tenantConfiguration.getConfiguration();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to update Device Information.
|
||||
* @param deviceId DeviceID to need to update.
|
||||
* @param deviceInfo Device Info to be update/
|
||||
* @throws DeviceDetailsMgtException Error occurs while updating Device Info.
|
||||
*/
|
||||
public static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo)
|
||||
throws DeviceDetailsMgtException {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceInformationManager informationManager =
|
||||
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
||||
informationManager.addDeviceInfo(deviceId, deviceInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to update device location.
|
||||
* @param deviceLocation Device coordination related information.
|
||||
* @throws DeviceDetailsMgtException Error occurs while updating Device location.
|
||||
*/
|
||||
public static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceInformationManager informationManager =
|
||||
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
||||
informationManager.addDeviceLocation(deviceLocation);
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Configurations that needs to be added on the device.
|
||||
*/
|
||||
public class AddTag {
|
||||
int commandId = -1;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void buildAddElement(Document doc, Element rootElement) {
|
||||
if (getItems() != null) {
|
||||
Element add = doc.createElement(Constants.ADD);
|
||||
rootElement.appendChild(add);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
add.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext();) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, add);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Inform an event occurred from device to server.
|
||||
*/
|
||||
public class AlertTag {
|
||||
|
||||
int commandId = -1;
|
||||
String data;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void buildAlertElement(Document doc, Element rootElement) {
|
||||
Element alert = doc.createElement(Constants.ALERT);
|
||||
rootElement.appendChild(alert);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
alert.appendChild(commandId);
|
||||
}
|
||||
if (getData() != null) {
|
||||
Element data = doc.createElement(Constants.DATA);
|
||||
data.appendChild(doc.createTextNode(getData()));
|
||||
alert.appendChild(data);
|
||||
}
|
||||
if (getItems() != null) {
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext();) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, alert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper for other SyncML elements.
|
||||
*/
|
||||
public class AtomicTag {
|
||||
int commandId = -1;
|
||||
List<AddTag> adds;
|
||||
List<ReplaceTag> replaces;
|
||||
|
||||
public List<ReplaceTag> getReplaces() {
|
||||
return replaces;
|
||||
}
|
||||
|
||||
public void setReplaces(List<ReplaceTag> replaces) {
|
||||
this.replaces = replaces;
|
||||
}
|
||||
|
||||
public List<AddTag> getAdds() {
|
||||
return adds;
|
||||
}
|
||||
|
||||
public void setAdds(List<AddTag> adds) {
|
||||
this.adds = adds;
|
||||
}
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public void buildAtomicElement(Document doc, Element rootElement) {
|
||||
Element atomic = doc.createElement(Constants.ATOMIC);
|
||||
if (getAdds() != null) {
|
||||
rootElement.appendChild(atomic);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
atomic.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<AddTag> addIterator = getAdds().iterator(); addIterator.hasNext(); ) {
|
||||
AddTag add = addIterator.next();
|
||||
if (add != null) {
|
||||
add.buildAddElement(doc, atomic);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getReplaces() != null) {
|
||||
for (Iterator<ReplaceTag> replaceIterator = getReplaces().iterator(); replaceIterator.hasNext(); ) {
|
||||
ReplaceTag add = replaceIterator.next();
|
||||
if (add != null) {
|
||||
add.buildReplaceElement(doc, atomic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Challenge data pass through the device and Device Management server for the security purpose.
|
||||
*/
|
||||
public class ChallengeTag {
|
||||
MetaTag meta;
|
||||
|
||||
public MetaTag getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public void setMeta(MetaTag meta) {
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public void buildChallengeElement(Document doc, Element rootElement) {
|
||||
Element challenge = doc.createElement(Constants.CHALLENGE);
|
||||
if (getMeta() != null) {
|
||||
getMeta().buildMetaElement(doc, challenge);
|
||||
}
|
||||
rootElement.appendChild(challenge);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Credentials passed between the device and the server for security purposes.
|
||||
*/
|
||||
public class CredentialTag {
|
||||
MetaTag meta;
|
||||
String data;
|
||||
|
||||
public MetaTag getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public void setMeta(MetaTag meta) {
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void buildCredentialElement(Document doc, Element rootElement) {
|
||||
Element credentials = doc.createElement(Constants.CREDENTIAL);
|
||||
rootElement.appendChild(credentials);
|
||||
if (getMeta() != null) {
|
||||
getMeta().buildMetaElement(doc, credentials);
|
||||
}
|
||||
if (getData() != null) {
|
||||
Element data = doc.createElement(Constants.DATA);
|
||||
data.appendChild(doc.createTextNode(getData()));
|
||||
credentials.appendChild(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Configurations that need to be delete on Device.
|
||||
*/
|
||||
public class DeleteTag {
|
||||
int commandId = -1;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void buildDeleteElement(Document doc, Element rootElement) {
|
||||
if (getItems() != null) {
|
||||
Element delete = doc.createElement(Constants.DELETE);
|
||||
rootElement.appendChild(delete);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
delete.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, delete);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Commands that needs to be executed on the device.
|
||||
*/
|
||||
public class ExecuteTag {
|
||||
int commandId = -1;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void buildExecElement(Document doc, Element rootElement) {
|
||||
if (getItems() != null) {
|
||||
Element exec = doc.createElement(Constants.EXECUTE);
|
||||
rootElement.appendChild(exec);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
exec.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, exec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Data that needs to be retrieved from the device.
|
||||
*/
|
||||
public class GetTag {
|
||||
int commandId = -1;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void buildGetElement(Document doc, Element rootElement) {
|
||||
if (getItems() != null) {
|
||||
Element get = doc.createElement(Constants.GET);
|
||||
rootElement.appendChild(get);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
get.appendChild(commandId);
|
||||
}
|
||||
if (getItems() != null) {
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, get);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Represents an items that should be retrieved from the device or a command.
|
||||
*/
|
||||
public class ItemTag {
|
||||
|
||||
TargetTag target;
|
||||
SourceTag source;
|
||||
String data;
|
||||
MetaTag meta;
|
||||
Element elementData;
|
||||
|
||||
public MetaTag getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public void setMeta(MetaTag meta) {
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public SourceTag getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(SourceTag source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public TargetTag getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(TargetTag target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Element getElementData() {
|
||||
return elementData;
|
||||
}
|
||||
|
||||
public void setElementData(Element elementData) {
|
||||
this.elementData = elementData;
|
||||
}
|
||||
|
||||
public void buildItemElement(Document doc, Element rootElement) {
|
||||
Element item = doc.createElement(Constants.ITEM);
|
||||
rootElement.appendChild(item);
|
||||
|
||||
if (getTarget() != null || getSource() != null) {
|
||||
|
||||
if (getTarget() != null) {
|
||||
getTarget().buildTargetElement(doc, item);
|
||||
}
|
||||
if (getSource() != null) {
|
||||
getSource().buildSourceElement(doc, item);
|
||||
}
|
||||
}
|
||||
if (getMeta() != null) {
|
||||
getMeta().buildMetaElement(doc, item);
|
||||
}
|
||||
if (getData() != null || getElementData()!= null) {
|
||||
Element data = doc.createElement(Constants.DATA);
|
||||
if (getData() != null) {
|
||||
data.appendChild(doc.createTextNode(getData()));
|
||||
}
|
||||
if (getElementData() != null) {
|
||||
Node node = doc.importNode(getElementData(), true);
|
||||
data.appendChild(node);
|
||||
}
|
||||
item.appendChild(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* MetaTag data related to credentials.
|
||||
*/
|
||||
public class MetaTag {
|
||||
|
||||
String format;
|
||||
String type;
|
||||
String nextNonce;
|
||||
|
||||
public String getNextNonce() {
|
||||
return nextNonce;
|
||||
}
|
||||
|
||||
public void setNextNonce(String nextNonce) {
|
||||
this.nextNonce = nextNonce;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void buildMetaElement(Document doc, Element rootElement) {
|
||||
Element meta = doc.createElement(Constants.META);
|
||||
rootElement.appendChild(meta);
|
||||
if (getFormat() != null) {
|
||||
Element format = doc.createElement(Constants.FORMAT);
|
||||
format.appendChild(doc.createTextNode(getFormat()));
|
||||
Attr attr = doc.createAttribute(Constants.XMLNS);
|
||||
attr.setValue(Constants.META_NAMESPACE);
|
||||
format.setAttributeNode(attr);
|
||||
meta.appendChild(format);
|
||||
}
|
||||
if (getType() != null) {
|
||||
Element type = doc.createElement(Constants.TYPE);
|
||||
type.appendChild(doc.createTextNode(getType()));
|
||||
Attr attr = doc.createAttribute(Constants.XMLNS);
|
||||
attr.setValue(Constants.META_NAMESPACE);
|
||||
type.setAttributeNode(attr);
|
||||
meta.appendChild(type);
|
||||
}
|
||||
if (getNextNonce() != null) {
|
||||
Element nextNonce = doc.createElement(Constants.NEXTNONCE);
|
||||
nextNonce.appendChild(doc.createTextNode(getNextNonce()));
|
||||
Attr attr = doc.createAttribute(Constants.XMLNS);
|
||||
attr.setValue(Constants.META_NAMESPACE);
|
||||
nextNonce.setAttributeNode(attr);
|
||||
meta.appendChild(nextNonce);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Commands sent from the device.
|
||||
*/
|
||||
public class ReplaceTag {
|
||||
int commandId = -1;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void buildReplaceElement(Document doc, Element rootElement) {
|
||||
if (getItems() != null) {
|
||||
Element replace = doc.createElement(Constants.REPLACE);
|
||||
rootElement.appendChild(replace);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
replace.appendChild(commandId);
|
||||
}
|
||||
if (getItems() != null) {
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Results sent for the requests made to the device.
|
||||
*/
|
||||
public class ResultsTag {
|
||||
int commandId = -1;
|
||||
int messageReference = -1;
|
||||
int commandReference = -1;
|
||||
List<ItemTag> item;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public int getMessageReference() {
|
||||
return messageReference;
|
||||
}
|
||||
|
||||
public void setMessageReference(int messageReference) {
|
||||
this.messageReference = messageReference;
|
||||
}
|
||||
|
||||
public int getCommandReference() {
|
||||
return commandReference;
|
||||
}
|
||||
|
||||
public void setCommandReference(int commandReference) {
|
||||
this.commandReference = commandReference;
|
||||
}
|
||||
|
||||
public List<ItemTag> getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(List<ItemTag> item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void buildResultElement(Document doc, Element rootElement) {
|
||||
Element results = doc.createElement(Constants.RESULTS);
|
||||
rootElement.appendChild(results);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
results.appendChild(commandId);
|
||||
}
|
||||
if (getMessageReference() != -1) {
|
||||
Element messageReference = doc.createElement(Constants.MESSAGE_REFERENCE);
|
||||
messageReference.appendChild(doc.createTextNode(String.valueOf(getMessageReference())));
|
||||
results.appendChild(messageReference);
|
||||
}
|
||||
if (getCommandReference() != -1) {
|
||||
Element messageReference = doc.createElement(Constants.COMMAND_REFERENCE);
|
||||
messageReference.appendChild(doc.createTextNode(String.valueOf(getCommandReference())));
|
||||
results.appendChild(messageReference);
|
||||
}
|
||||
if (getItem() != null) {
|
||||
for (Iterator<ItemTag> itemIterator = getItem().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, results);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class used to build syncml SequenceTag.
|
||||
*/
|
||||
public class SequenceTag {
|
||||
|
||||
int commandId;
|
||||
ExecuteTag exec;
|
||||
GetTag get;
|
||||
DeleteTag deleteTag;
|
||||
AtomicTag atomicTag;
|
||||
List<ReplaceTag> replaces;
|
||||
|
||||
public DeleteTag getDeleteTag() {
|
||||
return deleteTag;
|
||||
}
|
||||
|
||||
public void setDeleteTag(DeleteTag deleteTag) {
|
||||
this.deleteTag = deleteTag;
|
||||
}
|
||||
|
||||
public List<ReplaceTag> getReplaces() {
|
||||
return replaces;
|
||||
}
|
||||
|
||||
public void setReplaces(List<ReplaceTag> replaces) {
|
||||
this.replaces = replaces;
|
||||
}
|
||||
|
||||
public AtomicTag getAtomicTag() {
|
||||
return atomicTag;
|
||||
}
|
||||
|
||||
public void setAtomicTag(AtomicTag atomicTag) {
|
||||
this.atomicTag = atomicTag;
|
||||
}
|
||||
|
||||
public ExecuteTag getExec() {
|
||||
return exec;
|
||||
}
|
||||
|
||||
public void setExec(ExecuteTag exec) {
|
||||
this.exec = exec;
|
||||
}
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public GetTag getGet() {
|
||||
return get;
|
||||
}
|
||||
|
||||
public void setGet(GetTag get) {
|
||||
this.get = get;
|
||||
}
|
||||
|
||||
public void buildSequenceElement(Document doc, Element rootElement) {
|
||||
Element sequence = doc.createElement(Constants.SEQUENCE);
|
||||
rootElement.appendChild(sequence);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
sequence.appendChild(commandId);
|
||||
}
|
||||
if (getExec() != null) {
|
||||
getExec().buildExecElement(doc, sequence);
|
||||
}
|
||||
if (getGet() != null) {
|
||||
getGet().buildGetElement(doc, sequence);
|
||||
}
|
||||
if (getReplaces() != null) {
|
||||
for (Iterator<ReplaceTag> replaceIterator = getReplaces().iterator(); replaceIterator.hasNext(); ) {
|
||||
ReplaceTag replace = replaceIterator.next();
|
||||
if (replace != null) {
|
||||
replace.buildReplaceElement(doc, sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getDeleteTag() != null) {
|
||||
getDeleteTag().buildDeleteElement(doc, sequence);
|
||||
}
|
||||
if (getAtomicTag() != null) {
|
||||
getAtomicTag().buildAtomicElement(doc, sequence);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Source details of syncml header's.
|
||||
*/
|
||||
public class SourceTag {
|
||||
|
||||
private String locURI;
|
||||
private String locName;
|
||||
|
||||
public String getLocURI() {
|
||||
return locURI;
|
||||
}
|
||||
|
||||
public void setLocURI(String locURI) {
|
||||
this.locURI = locURI;
|
||||
}
|
||||
|
||||
public String getLocName() {
|
||||
return locName;
|
||||
}
|
||||
|
||||
public void setLocName(String locName) {
|
||||
this.locName = locName;
|
||||
}
|
||||
|
||||
public void buildSourceElement(Document doc, Element rootElement) {
|
||||
Element target = doc.createElement(Constants.SOURCE);
|
||||
rootElement.appendChild(target);
|
||||
if (getLocURI() != null) {
|
||||
Element locURI = doc.createElement(Constants.LOC_URI);
|
||||
locURI.appendChild(doc.createTextNode(getLocURI()));
|
||||
target.appendChild(locURI);
|
||||
}
|
||||
if (getLocName() != null) {
|
||||
Element locName = doc.createElement(Constants.LOC_NAME);
|
||||
locName.appendChild(doc.createTextNode(getLocName()));
|
||||
target.appendChild(locName);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Status of a previously sent message to device;
|
||||
*/
|
||||
public class StatusTag {
|
||||
int commandId = -1;
|
||||
int messageReference = -1;
|
||||
int commandReference = -1;
|
||||
String command;
|
||||
String targetReference;
|
||||
String data;
|
||||
ChallengeTag challenge;
|
||||
|
||||
public StatusTag(int commandId, int messageReference, int commandReference, String command,
|
||||
String targetReference, String data) {
|
||||
this.commandId = commandId;
|
||||
this.messageReference = messageReference;
|
||||
this.commandReference = commandReference;
|
||||
this.command = command;
|
||||
this.targetReference = targetReference;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public StatusTag(int commandId, int messageReference, int commandReference, String command,
|
||||
ChallengeTag challengeTag, String targetReference, String data) {
|
||||
this.commandId = commandId;
|
||||
this.messageReference = messageReference;
|
||||
this.commandReference = commandReference;
|
||||
this.command = command;
|
||||
this.challenge = challengeTag;
|
||||
this.targetReference = targetReference;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public StatusTag() {
|
||||
}
|
||||
|
||||
public ChallengeTag getChallenge() {
|
||||
return challenge;
|
||||
}
|
||||
|
||||
public void setChallenge(ChallengeTag challenge) {
|
||||
this.challenge = challenge;
|
||||
}
|
||||
|
||||
public String getTargetReference() {
|
||||
return targetReference;
|
||||
}
|
||||
|
||||
public void setTargetReference(String targetReference) {
|
||||
this.targetReference = targetReference;
|
||||
}
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public void setCommandId(int commandId) {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public int getMessageReference() {
|
||||
return messageReference;
|
||||
}
|
||||
|
||||
public void setMessageReference(int messageReference) {
|
||||
this.messageReference = messageReference;
|
||||
}
|
||||
|
||||
public int getCommandReference() {
|
||||
return commandReference;
|
||||
}
|
||||
|
||||
public void setCommandReference(int commandReference) {
|
||||
this.commandReference = commandReference;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void buildStatusElement(Document doc, Element rootElement) {
|
||||
Element status = doc.createElement(Constants.STATUS);
|
||||
rootElement.appendChild(status);
|
||||
if (getCommandId() != -1) {
|
||||
Element commandId = doc.createElement(Constants.COMMAND_ID);
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
status.appendChild(commandId);
|
||||
}
|
||||
if (getMessageReference() != -1) {
|
||||
Element msgReference = doc.createElement(Constants.MESSAGE_REFERENCE);
|
||||
msgReference.appendChild(doc.createTextNode(String.valueOf(getMessageReference())));
|
||||
status.appendChild(msgReference);
|
||||
}
|
||||
if (getCommandReference() != -1) {
|
||||
Element commandReference = doc.createElement(Constants.COMMAND_REFERENCE);
|
||||
commandReference.appendChild(doc.createTextNode(String.valueOf(getCommandReference())));
|
||||
status.appendChild(commandReference);
|
||||
}
|
||||
if (getCommand() != null) {
|
||||
Element command = doc.createElement(Constants.COMMAND);
|
||||
command.appendChild(doc.createTextNode(getCommand()));
|
||||
status.appendChild(command);
|
||||
}
|
||||
if (getTargetReference() != null) {
|
||||
Element targetReference = doc.createElement(Constants.TARGET_REFERENCE);
|
||||
targetReference.appendChild(doc.createTextNode(getTargetReference()));
|
||||
status.appendChild(targetReference);
|
||||
}
|
||||
if (getChallenge() != null) {
|
||||
getChallenge().buildChallengeElement(doc, status);
|
||||
}
|
||||
if (getData() != null) {
|
||||
Element data = doc.createElement(Constants.DATA);
|
||||
data.appendChild(doc.createTextNode(getData()));
|
||||
status.appendChild(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the body details of a syncml.
|
||||
*/
|
||||
public class SyncmlBody {
|
||||
GetTag getCommands;
|
||||
List<ExecuteTag> exec;
|
||||
List<StatusTag> status;
|
||||
AlertTag alert;
|
||||
ReplaceTag replace;
|
||||
ResultsTag results;
|
||||
SequenceTag sequence;
|
||||
AtomicTag atomicTag;
|
||||
|
||||
public AtomicTag getAtomicTag() {
|
||||
return atomicTag;
|
||||
}
|
||||
|
||||
public void setAtomicTag(AtomicTag atomicTag) {
|
||||
this.atomicTag = atomicTag;
|
||||
}
|
||||
|
||||
public SequenceTag getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(SequenceTag sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public List<ExecuteTag> getExec() {
|
||||
return exec;
|
||||
}
|
||||
|
||||
public void setExec(List<ExecuteTag> exec) {
|
||||
this.exec = exec;
|
||||
}
|
||||
|
||||
public ResultsTag getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(ResultsTag results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
public ReplaceTag getReplace() {
|
||||
return replace;
|
||||
}
|
||||
|
||||
public void setReplace(ReplaceTag replace) {
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
public List<StatusTag> getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(List<StatusTag> status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public AlertTag getAlert() {
|
||||
return alert;
|
||||
}
|
||||
|
||||
public void setAlert(AlertTag alert) {
|
||||
this.alert = alert;
|
||||
}
|
||||
|
||||
public GetTag getGet() {
|
||||
return getCommands;
|
||||
}
|
||||
|
||||
public void setGet(GetTag get) {
|
||||
this.getCommands = get;
|
||||
}
|
||||
|
||||
public void buildBodyElement(Document doc, Element rootElement) {
|
||||
|
||||
Element syncBody = doc.createElement(Constants.SYNC_BODY);
|
||||
rootElement.appendChild(syncBody);
|
||||
if (getStatus() != null) {
|
||||
for (int x = 0; x < getStatus().size(); x++) {
|
||||
if (getStatus().get(x) != null) {
|
||||
getStatus().get(x).buildStatusElement(doc, syncBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getAlert() != null) {
|
||||
getAlert().buildAlertElement(doc, syncBody);
|
||||
}
|
||||
if (getResults() != null) {
|
||||
getResults().buildResultElement(doc, syncBody);
|
||||
}
|
||||
if (getGet() != null) {
|
||||
getGet().buildGetElement(doc, syncBody);
|
||||
}
|
||||
if (getReplace() != null) {
|
||||
getReplace().buildReplaceElement(doc, syncBody);
|
||||
}
|
||||
if (getExec() != null) {
|
||||
for (Iterator<ExecuteTag> execIterator = getExec().iterator(); execIterator.hasNext(); ) {
|
||||
ExecuteTag exec = execIterator.next();
|
||||
if (exec != null) {
|
||||
exec.buildExecElement(doc, syncBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getSequence() != null) {
|
||||
getSequence().buildSequenceElement(doc, syncBody);
|
||||
}
|
||||
if (getAtomicTag() != null) {
|
||||
getAtomicTag().buildAtomicElement(doc, syncBody);
|
||||
}
|
||||
syncBody.appendChild(doc.createElement(Constants.FINAL));
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Represents a base format of a syncml document
|
||||
*/
|
||||
public class SyncmlDocument {
|
||||
SyncmlHeader header;
|
||||
SyncmlBody body;
|
||||
|
||||
public SyncmlHeader getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(SyncmlHeader header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public SyncmlBody getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(SyncmlBody body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public void buildDocument(Document doc, Element rootElement) {
|
||||
if (getHeader() != null) {
|
||||
getHeader().buildSyncmlHeaderElement(doc, rootElement);
|
||||
}
|
||||
if (getBody() != null) {
|
||||
getBody().buildBodyElement(doc, rootElement);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Represents the header details of a syncml.
|
||||
*/
|
||||
public class SyncmlHeader {
|
||||
private int sessionId = -1;
|
||||
private int MsgID = -1;
|
||||
private TargetTag target;
|
||||
private SourceTag source;
|
||||
private CredentialTag credential;
|
||||
private String hexadecimalSessionId;
|
||||
|
||||
public String getHexadecimalSessionId() {
|
||||
return hexadecimalSessionId;
|
||||
}
|
||||
|
||||
public void setHexadecimalSessionId(String hexSessionId) {
|
||||
this.hexadecimalSessionId = hexSessionId;
|
||||
}
|
||||
|
||||
public CredentialTag getCredential() {
|
||||
return credential;
|
||||
}
|
||||
|
||||
public void setCredential(CredentialTag credential) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
public int getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(int sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public int getMsgID() {
|
||||
return MsgID;
|
||||
}
|
||||
|
||||
public void setMsgID(int msgID) {
|
||||
this.MsgID = msgID;
|
||||
}
|
||||
|
||||
public TargetTag getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(TargetTag target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public SourceTag getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(SourceTag source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public void buildSyncmlHeaderElement(Document doc, Element rootElement) {
|
||||
Element syncHdr = doc.createElement(Constants.SYNC_HDR);
|
||||
rootElement.appendChild(syncHdr);
|
||||
Element verDTD = doc.createElement(Constants.VER_DTD);
|
||||
verDTD.appendChild(doc.createTextNode(Constants.VER_DTD_VALUE));
|
||||
syncHdr.appendChild(verDTD);
|
||||
|
||||
Element verProtocol = doc.createElement(Constants.VER_PROTOCOL);
|
||||
verProtocol.appendChild(doc.createTextNode(Constants.VER_PROTOCOL_VALUE));
|
||||
syncHdr.appendChild(verProtocol);
|
||||
if (getHexadecimalSessionId() != null) {
|
||||
Element sessionId = doc.createElement(Constants.SESSION_ID);
|
||||
sessionId.appendChild(doc.createTextNode(getHexadecimalSessionId()));
|
||||
syncHdr.appendChild(sessionId);
|
||||
}
|
||||
if (getMsgID() != -1) {
|
||||
Element msgId = doc.createElement(Constants.MESSAGE_ID);
|
||||
msgId.appendChild(doc.createTextNode(String.valueOf(getMsgID())));
|
||||
syncHdr.appendChild(msgId);
|
||||
}
|
||||
if (getTarget() != null) {
|
||||
getTarget().buildTargetElement(doc, syncHdr);
|
||||
}
|
||||
if (getSource() != null) {
|
||||
getSource().buildSourceElement(doc, syncHdr);
|
||||
}
|
||||
if (getCredential() != null) {
|
||||
getCredential().buildCredentialElement(doc, syncHdr);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
/**
|
||||
* Target details of syncml header's.
|
||||
*/
|
||||
public class TargetTag {
|
||||
|
||||
private String LocURI;
|
||||
private String LocName;
|
||||
|
||||
public String getLocURI() {
|
||||
return LocURI;
|
||||
}
|
||||
|
||||
public void setLocURI(String locURI) {
|
||||
LocURI = locURI;
|
||||
}
|
||||
|
||||
public String getLocName() {
|
||||
return LocName;
|
||||
}
|
||||
|
||||
public void setLocName(String locName) {
|
||||
LocName = locName;
|
||||
}
|
||||
|
||||
public void buildTargetElement(Document doc, Element rootElement) {
|
||||
Element target = doc.createElement(Constants.TARGET);
|
||||
rootElement.appendChild(target);
|
||||
if (getLocURI() != null) {
|
||||
Element locURI = doc.createElement(Constants.LOC_URI);
|
||||
locURI.appendChild(doc.createTextNode(getLocURI()));
|
||||
target.appendChild(locURI);
|
||||
}
|
||||
if (getLocName() != null) {
|
||||
Element locName = doc.createElement(Constants.LOC_NAME);
|
||||
locName.appendChild(doc.createTextNode(getLocName()));
|
||||
target.appendChild(locName);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations;
|
||||
|
||||
/**
|
||||
* Exceptions related to operation retrieval and syncml generation
|
||||
*/
|
||||
public class WindowsOperationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 5435636243242623629L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public WindowsOperationException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
public WindowsOperationException(String errorMessage, Throwable throwable) {
|
||||
super(errorMessage, throwable);
|
||||
setErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
public WindowsOperationException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public WindowsOperationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WindowsOperationException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
/**
|
||||
* Constant values used in syncml generator.
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String PROVIDER_ID = "MobiCDMServer";
|
||||
public static final String SERVER_SECRET = "dummy";
|
||||
public static final String INITIAL_NONCE = "ZHVtbXk=";
|
||||
public static final String DISENROLL_ALERT_DATA = "1226";
|
||||
public static final String INITIAL_ALERT_DATA = "1201";
|
||||
public static final String INITIAL_WIN10_ALERT_DATA = "1224";
|
||||
public static final int EMPTY = 0;
|
||||
|
||||
public static final String SYNCML_ROOT_ELEMENT_NAME = "SyncML";
|
||||
public static final String XMLNS_SYNCML = "SYNCML:SYNCML1.2";
|
||||
public static final String UTF_8 = "UTF-8";
|
||||
public static final String MD5 = "MD5";
|
||||
public static final String YES = "yes";
|
||||
|
||||
public static final String EXECUTE = "Exec";
|
||||
public static final String ATOMIC = "Atomic";
|
||||
public static final String ADD = "Add";
|
||||
public static final String COMMAND_ID = "CmdID";
|
||||
public static final String GET = "Get";
|
||||
public static final String DELETE = "Delete";
|
||||
public static final String ITEM = "Item";
|
||||
public static final String SOURCE = "Source";
|
||||
public static final String LOC_URI = "LocURI";
|
||||
public static final String LOC_NAME = "LocName";
|
||||
public static final String MESSAGE_REFERENCE = "MsgRef";
|
||||
public static final String COMMAND_REFERENCE = "CmdRef";
|
||||
public static final String COMMAND = "Cmd";
|
||||
public static final String TARGET_REFERENCE = "TargetRef";
|
||||
public static final String DATA = "Data";
|
||||
public static final String STATUS = "Status";
|
||||
public static final String SYNC_BODY = "SyncBody";
|
||||
public static final String SYNC_HDR = "SyncHdr";
|
||||
public static final String VER_DTD = "VerDTD";
|
||||
public static final String VER_PROTOCOL = "VerProto";
|
||||
public static final String SESSION_ID = "SessionID";
|
||||
public static final String MESSAGE_ID = "MsgID";
|
||||
public static final String TARGET = "Target";
|
||||
public static final String VER_DTD_VALUE = "1.2";
|
||||
public static final String VER_PROTOCOL_VALUE = "DM/1.2";
|
||||
public static final String ALERT = "Alert";
|
||||
public static final String FINAL = "Final";
|
||||
public static final String REPLACE = "Replace";
|
||||
public static final String META = "Meta";
|
||||
public static final String CREDENTIAL = "Cred";
|
||||
public static final String FORMAT = "Format";
|
||||
public static final String TYPE = "Type";
|
||||
public static final String NEXTNONCE = "NextNonce";
|
||||
public static final String CHALLENGE = "chal";
|
||||
public static final String META_NAMESPACE = "syncml:metinf";
|
||||
public static final String XMLNS = "xmlns";
|
||||
public static final String RESULTS = "Results";
|
||||
public static final String CRED_FORMAT = "b64";
|
||||
public static final String CRED_TYPE = "syncml:auth-md5";
|
||||
public static final String SEQUENCE = "Sequence";
|
||||
public static final String META_FORMAT_INT = "int";
|
||||
public static final String META_FORMAT_CHARACTER = "chr";
|
||||
public static final String META_FORMAT_XML = "xml";
|
||||
public static final String META_FORMAT_B64 = "b64";
|
||||
public static final String META_TYPE_TEXT_PLAIN = "text/plain";
|
||||
|
||||
public static final String SCOPE = "scope";
|
||||
|
||||
public static final String FORWARD_SLASH = "/";
|
||||
|
||||
/**
|
||||
* SynclML service related constants.
|
||||
*/
|
||||
public final class SyncMLResponseCodes {
|
||||
public static final String AUTHENTICATION_ACCEPTED = "212";
|
||||
public static final String ACCEPTED = "200";
|
||||
public static final String UNAUTHORIZED = "401";
|
||||
public static final String ACCEPTED_FOR_PROCESSING = "202";
|
||||
public static final String PIN_NOTFOUND = "405";
|
||||
public static final String LOCK_RESET_NOTIFICATION = "Error occurred in Device Lock Operation. " +
|
||||
"Please trigger lock-reset operation.";
|
||||
public static final String POSITIVE_CSP_DATA = "1";
|
||||
public static final String NEGATIVE_CSP_DATA = "0";
|
||||
}
|
||||
|
||||
/**
|
||||
* SyncmML message related constants.
|
||||
*/
|
||||
public final class SyncmlMessageCodes {
|
||||
public static final int replaceCommandId = 300;
|
||||
public static final int elementCommandId = 75;
|
||||
public static final int atomicCommandId = 400;
|
||||
public static final int addCommandId = 90;
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class generate Info type operation list.
|
||||
*/
|
||||
public class DeviceInfo {
|
||||
public List<Operation> getDeviceInfo() {
|
||||
|
||||
List<Operation> deviceInfoOperations = new ArrayList<>();
|
||||
|
||||
Operation osVersion = new Operation();
|
||||
osVersion.setCode(PluginConstants.SyncML.SOFTWARE_VERSION);
|
||||
osVersion.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(osVersion);
|
||||
|
||||
Operation imsi = new Operation();
|
||||
imsi.setCode(PluginConstants.SyncML.IMSI);
|
||||
imsi.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(imsi);
|
||||
|
||||
Operation imei = new Operation();
|
||||
imei.setCode(PluginConstants.SyncML.IMEI);
|
||||
imei.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(imei);
|
||||
|
||||
Operation deviceID = new Operation();
|
||||
deviceID.setCode(PluginConstants.SyncML.DEV_ID);
|
||||
deviceID.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(deviceID);
|
||||
|
||||
Operation manufacturer = new Operation();
|
||||
manufacturer.setCode(PluginConstants.SyncML.MANUFACTURER);
|
||||
manufacturer.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(manufacturer);
|
||||
|
||||
Operation model = new Operation();
|
||||
model.setCode(PluginConstants.SyncML.MODEL);
|
||||
model.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(model);
|
||||
|
||||
Operation language = new Operation();
|
||||
language.setCode(PluginConstants.SyncML.LANGUAGE);
|
||||
language.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(language);
|
||||
|
||||
Operation vendor = new Operation();
|
||||
vendor.setCode(PluginConstants.SyncML.VENDOR);
|
||||
vendor.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(vendor);
|
||||
|
||||
Operation macaddress = new Operation();
|
||||
macaddress.setCode(PluginConstants.SyncML.MAC_ADDRESS);
|
||||
macaddress.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(macaddress);
|
||||
|
||||
Operation resolution = new Operation();
|
||||
resolution.setCode(PluginConstants.SyncML.RESOLUTION);
|
||||
resolution.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(resolution);
|
||||
|
||||
Operation deviceName = new Operation();
|
||||
deviceName.setCode(PluginConstants.SyncML.DEVICE_NAME);
|
||||
deviceName.setType(Operation.Type.INFO);
|
||||
deviceInfoOperations.add(deviceName);
|
||||
|
||||
return deviceInfoOperations;
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HeartBeatDeviceInfo {
|
||||
public List<Operation> getDeviceInfo() {
|
||||
|
||||
List<Operation> deviceInfoOperations = new ArrayList<>();
|
||||
|
||||
Operation osVersion = new Operation();
|
||||
osVersion.setCode(PluginConstants.SyncML.SOFTWARE_VERSION);
|
||||
deviceInfoOperations.add(osVersion);
|
||||
|
||||
Operation imsi = new Operation();
|
||||
imsi.setCode(PluginConstants.SyncML.IMSI);
|
||||
deviceInfoOperations.add(imsi);
|
||||
|
||||
Operation imei = new Operation();
|
||||
imei.setCode(PluginConstants.SyncML.IMEI);
|
||||
deviceInfoOperations.add(imei);
|
||||
|
||||
Operation deviceID = new Operation();
|
||||
deviceID.setCode(PluginConstants.SyncML.DEV_ID);
|
||||
deviceInfoOperations.add(deviceID);
|
||||
|
||||
Operation manufacturer = new Operation();
|
||||
manufacturer.setCode(PluginConstants.SyncML.MANUFACTURER);
|
||||
deviceInfoOperations.add(manufacturer);
|
||||
|
||||
Operation model = new Operation();
|
||||
model.setCode(PluginConstants.SyncML.MODEL);
|
||||
deviceInfoOperations.add(model);
|
||||
|
||||
Operation language = new Operation();
|
||||
language.setCode(PluginConstants.SyncML.LANGUAGE);
|
||||
deviceInfoOperations.add(language);
|
||||
|
||||
Operation vendor = new Operation();
|
||||
vendor.setCode(PluginConstants.SyncML.VENDOR);
|
||||
deviceInfoOperations.add(vendor);
|
||||
|
||||
Operation macaddress = new Operation();
|
||||
macaddress.setCode(PluginConstants.SyncML.MAC_ADDRESS);
|
||||
deviceInfoOperations.add(macaddress);
|
||||
|
||||
Operation resolution = new Operation();
|
||||
resolution.setCode(PluginConstants.SyncML.RESOLUTION);
|
||||
deviceInfoOperations.add(resolution);
|
||||
|
||||
Operation deviceName = new Operation();
|
||||
deviceName.setCode(PluginConstants.SyncML.DEVICE_NAME);
|
||||
deviceInfoOperations.add(deviceName);
|
||||
|
||||
Operation totalRam = new Operation();
|
||||
totalRam.setCode(PluginConstants.SyncML.TOTAL_RAM);
|
||||
deviceInfoOperations.add(totalRam);
|
||||
|
||||
Operation availableStorage = new Operation();
|
||||
availableStorage.setCode(PluginConstants.SyncML.TOTAL_STORAGE);
|
||||
deviceInfoOperations.add(availableStorage);
|
||||
|
||||
Operation remainingBattery = new Operation();
|
||||
remainingBattery.setCode(PluginConstants.SyncML.BATTERY_CHARGE_REMAINING);
|
||||
deviceInfoOperations.add(remainingBattery);
|
||||
|
||||
return deviceInfoOperations;
|
||||
}
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
/**
|
||||
* Maps operation codes to device specific format.
|
||||
*/
|
||||
public class OperationCode {
|
||||
public static enum Info {
|
||||
DEV_ID("./DevInfo/DevId"),
|
||||
MANUFACTURER("./DevInfo/Man"),
|
||||
DEVICE_MODEL("./DevInfo/Mod"),
|
||||
DM_VERSION("./DevInfo/DmV"),
|
||||
LANGUAGE("./DevInfo/Lang"),
|
||||
IMSI("./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMSI"),
|
||||
IMEI("./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMEI"),
|
||||
SOFTWARE_VERSION("./DevDetail/SwV"),
|
||||
VENDOR("./DevDetail/OEM"),
|
||||
MAC_ADDRESS("./DevDetail/Ext/WLANMACAddress"),
|
||||
RESOLUTION("./DevDetail/Ext/Microsoft/Resolution"),
|
||||
DEVICE_NAME("./DevDetail/Ext/Microsoft/DeviceName"),
|
||||
CHANNEL_URI("./Vendor/MSFT/DMClient/Provider/MobiCDMServer/Push/ChannelURI"),
|
||||
LOCK_PIN("./Vendor/MSFT/RemoteLock/NewPINValue"),
|
||||
LOCK_RESET("./Vendor/MSFT/RemoteLock/LockAndResetPIN"),
|
||||
CAMERA("./Vendor/MSFT/PolicyManager/My/Camera/AllowCamera"),
|
||||
CAMERA_STATUS("./Vendor/MSFT/PolicyManager/Device/Camera/AllowCamera"),
|
||||
ENCRYPT_STORAGE_STATUS("./Vendor/MSFT/PolicyManager/Device/Security/RequireDeviceEncryption"),
|
||||
DEVICE_PASSWORD_STATUS("./Vendor/MSFT/PolicyManager/Device/DeviceLock/DevicePasswordEnabled"),
|
||||
DEVICE_PASSCODE_DELETE("./Vendor/MSFT/PolicyManager/My/DeviceLock"),
|
||||
|
||||
// Windows10 operation codes
|
||||
TOTAL_RAM("./DevDetail/Ext/Microsoft/TotalRAM"),
|
||||
TOTAL_STORAGE("./DevDetail/Ext/Microsoft/TotalStorage"),
|
||||
OS_PLATFORM("./DevDetail/Ext/Microsoft/OSPlatform"),
|
||||
MOBILE_ID("./DevDetail/Ext/Microsoft/MobileID"),
|
||||
DEVICE_TYPE("./DevDetail/DevTyp"),
|
||||
BATTERY_QUERY("./Vendor/MSFT/DeviceStatus/Battery"),
|
||||
BATTERY_STATUS("./Vendor/MSFT/DeviceStatus/Battery/Status"),
|
||||
BATTERY_CHARGE_REMAINING("./Vendor/MSFT/DeviceStatus/Battery/EstimatedChargeRemaining"),
|
||||
BATTERY_ESTIMATED_RUNTIME("./Vendor/MSFT/DeviceStatus/Battery/EstimatedRuntime"),
|
||||
LONGITUDE("./Vendor/MSFT/RemoteFind/Location/Longitude"),
|
||||
LATITUDE("./Vendor/MSFT/RemoteFind/Location/Latitude"),
|
||||
TEST("./Vendor/MSFT/DiagnosticLog/EtwLog/Collectors");
|
||||
private final String code;
|
||||
|
||||
Info(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static enum Command {
|
||||
DEVICE_RING("./Vendor/MSFT/RemoteRing/Ring"),
|
||||
DEVICE_LOCK("./Vendor/MSFT/RemoteLock/Lock"),
|
||||
WIPE_DATA("./Vendor/MSFT/RemoteWipe/doWipe"),
|
||||
DISENROLL("./Vendor/MSFT/DMClient/Unenroll"),
|
||||
LOCK_RESET("./Vendor/MSFT/RemoteLock/LockAndResetPIN"),
|
||||
CAMERA("./Vendor/MSFT/PolicyManager/My/Camera/AllowCamera"),
|
||||
ENCRYPT_STORAGE("./Vendor/MSFT/PolicyManager/My/Security/RequireDeviceEncryption"),
|
||||
CAMERA_STATUS("./Vendor/MSFT/PolicyManager/Device/Camera/AllowCamera"),
|
||||
ENCRYPT_STORAGE_STATUS("./Vendor/MSFT/PolicyManager/Device/Security/RequireDeviceEncryption"),
|
||||
DEVICE_PASSWORD_ENABLE("./Vendor/MSFT/PolicyManager/My/DeviceLock/DevicePasswordEnabled"),
|
||||
DEVICE_PASSCODE_DELETE("./Vendor/MSFT/PolicyManager/My/DeviceLock"),
|
||||
// Windows10 operation codes
|
||||
TOTAL_RAM("./DevDetail/Ext/Microsoft/TotalRAM"),
|
||||
TOTAL_STORAGE("./DevDetail/Ext/Microsoft/TotalStorage"),
|
||||
OS_PLATFORM("./DevDetail/Ext/Microsoft/OSPlatform"),
|
||||
MOBILE_ID("./DevDetail/Ext/Microsoft/MobileID"),
|
||||
DEVICE_TYPE("./DevDetail/DevTyp"),
|
||||
BATTERY_QUERY("./Vendor/MSFT/DeviceStatus/Battery"),
|
||||
BATTERY_STATUS("./Vendor/MSFT/DeviceStatus/Battery/Status"),
|
||||
BATTERY_CHARGE_REMAINING("./Vendor/MSFT/DeviceStatus/Battery/EstimatedChargeRemaining"),
|
||||
BATTERY_ESTIMATED_RUNTIME("./Vendor/MSFT/DeviceStatus/Battery/EstimatedRuntime"),
|
||||
LONGITUDE("./Vendor/MSFT/RemoteFind/Location/Longitude"),
|
||||
LATITUDE("./Vendor/MSFT/RemoteFind/Location/Latitude"),
|
||||
TEST("./Vendor/MSFT/DiagnosticLog/EtwLog/Collectors"),
|
||||
DEVICE_REBOOT("./Vendor/MSFT/Reboot/RebootNow"),
|
||||
INSTALL_ENTERPRISE_APPX_APPLICATION("./Device/Vendor/MSFT/EnterpriseModernAppManagement/AppInstallation/{PackageFamilyName}"),
|
||||
INSTALL_ENTERPRISE_APPX_CERTIFICATE("./Device/Vendor/MSFT/RootCATrustedCertificates/Root/{CertHash}/EncodedCertificate"),
|
||||
INSTALL_ENTERPRISE_MSI_APPLICATION("./Device/Vendor/MSFT/EnterpriseDesktopAppManagement/MSI/%7B{ProductId}%7D/DownloadInstall");
|
||||
|
||||
private final String code;
|
||||
|
||||
Command(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static enum Configure {
|
||||
WIFI("./Vendor/MSFT/WiFi/Profile/MyNetwork/WlanXml"),
|
||||
CAMERA("./Vendor/MSFT/PolicyManager/My/Camera/AllowCamera"),
|
||||
CAMERA_STATUS("./Vendor/MSFT/PolicyManager/Device/Camera/AllowCamera"),
|
||||
ENCRYPT_STORAGE("./Vendor/MSFT/PolicyManager/My/Security/RequireDeviceEncryption"),
|
||||
ENCRYPT_STORAGE_STATUS("./Vendor/MSFT/PolicyManager/Device/Security/RequireDeviceEncryption"),
|
||||
PASSWORD_MAX_FAIL_ATTEMPTS("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/MaxDevicePasswordFailedAttempts"),
|
||||
DEVICE_PASSWORD_ENABLE("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/DevicePasswordEnabled"),
|
||||
SIMPLE_PASSWORD("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/AllowSimpleDevicePassword"),
|
||||
MIN_PASSWORD_LENGTH("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/MinDevicePasswordLength"),
|
||||
ALPHANUMERIC_PASSWORD("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/AlphanumericDevicePasswordRequired"),
|
||||
PASSWORD_EXPIRE("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/DevicePasswordExpiration"),
|
||||
PASSWORD_HISTORY("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/DevicePasswordHistory"),
|
||||
MAX_PASSWORD_INACTIVE_TIME("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/MaxInactivityTimeDeviceLock"),
|
||||
MIN_PASSWORD_COMPLEX_CHARACTERS("./Vendor/MSFT/DeviceLock/Provider/TestMDMServer/MinDevicePasswordComplexCharacters");
|
||||
|
||||
|
||||
private final String code;
|
||||
|
||||
Configure(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,678 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.StatusTag;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlDocument;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlHeader;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.ItemTag;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.WindowsOperationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.ResultsTag;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlBody;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils.convertToDeviceIdentifierObject;
|
||||
|
||||
/**
|
||||
* This class is used to handle pending operations of the device.
|
||||
*/
|
||||
public class OperationHandler {
|
||||
private static Log log = LogFactory.getLog(
|
||||
org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.OperationHandler.class);
|
||||
|
||||
|
||||
/**
|
||||
* Update the operations using device status payload.
|
||||
*
|
||||
* @param status Client side status for the specific operations.
|
||||
* @param syncmlDocument syncml payload for operation status which parse through the syncml engine.
|
||||
* @param deviceIdentifier specific device identifier for each device.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void updateDeviceOperations(StatusTag status, SyncmlDocument syncmlDocument,
|
||||
DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
try {
|
||||
pendingDataOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
|
||||
if (Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData()) ||
|
||||
(Constants.SyncMLResponseCodes.ACCEPTED_FOR_PROCESSING.equals(status.getData()))) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
if (syncmlDocument.getHeader().getSource().getLocURI() != null) {
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
|
||||
}
|
||||
} else if (Constants.SyncMLResponseCodes.PIN_NOTFOUND.equals(status.getData())) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getId() == status.getCommandReference() &&
|
||||
(PluginConstants.OperationCodes.DEVICE_LOCK.equals(operation.getCode()))) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
if (syncmlDocument.getHeader().getSource().getLocURI() != null) {
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
|
||||
}
|
||||
NotificationManagementService nmService = WindowsAPIUtils.getNotificationManagementService();
|
||||
Notification lockResetNotification = new Notification();
|
||||
lockResetNotification.setOperationId(status.getCommandReference());
|
||||
lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW));
|
||||
|
||||
lockResetNotification.setDescription(
|
||||
Constants.SyncMLResponseCodes.LOCK_RESET_NOTIFICATION);
|
||||
nmService.addNotification(deviceIdentifier, lockResetNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in getting pending operations.");
|
||||
} catch (NotificationManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while adding notification", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update operation statuses.
|
||||
*
|
||||
* @param deviceId specific device Id.
|
||||
* @param operations operation list to be update.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public static void updateStatus(String deviceId, List<? extends Operation> operations)
|
||||
throws OperationManagementException {
|
||||
for (Operation operation : operations) {
|
||||
WindowsAPIUtils.updateOperation(deviceId, operation);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updating operation '" + operation.toString() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Status of the lock operation.
|
||||
*
|
||||
* @param status Status of the operation.
|
||||
* @param syncmlDocument parsed syncml payload.
|
||||
* @param deviceIdentifier Device Id.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void updateLockOperation(StatusTag status, SyncmlDocument syncmlDocument, DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
try {
|
||||
pendingDataOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
if (Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData())) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if ((OperationCode.Command.DEVICE_LOCK.getCode().equals(operation.getCode()))
|
||||
&& operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Constants.SyncMLResponseCodes.PIN_NOTFOUND.equals(status.getData())) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
|
||||
if ((OperationCode.Command.DEVICE_LOCK.getCode().equals(operation.getCode()) &&
|
||||
operation.getId() == status.getCommandReference())) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
|
||||
|
||||
NotificationManagementService nmService = WindowsAPIUtils.getNotificationManagementService();
|
||||
Notification lockResetNotification = new Notification();
|
||||
lockResetNotification.setOperationId(status.getCommandReference());
|
||||
lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW));
|
||||
lockResetNotification.setDescription(Constants.SyncMLResponseCodes.LOCK_RESET_NOTIFICATION);
|
||||
|
||||
nmService.addNotification(deviceIdentifier, lockResetNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in getting pending operations.");
|
||||
} catch (NotificationManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in adding notifications.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status of the ring operation.
|
||||
*
|
||||
* @param status Ring status of the device.
|
||||
* @param syncmlDocument Parsed syncml payload from the syncml engine.
|
||||
* @param deviceIdentifier specific device id to be update.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void ring(StatusTag status, SyncmlDocument syncmlDocument, DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
try {
|
||||
if ((Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData()))) {
|
||||
pendingDataOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if ((OperationCode.Command.DEVICE_RING.getCode().equals(operation.getCode())) &&
|
||||
(operation.getId() == status.getCommandReference())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in getting pending operation.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status of the DataWipe operation.
|
||||
*
|
||||
* @param status Status of the data wipe.
|
||||
* @param syncmlDocument Parsed syncml payload from the syncml engine.
|
||||
* @param deviceIdentifier specific device id to be wiped.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void dataWipe(StatusTag status, SyncmlDocument syncmlDocument, DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
if ((Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData()))) {
|
||||
try {
|
||||
pendingDataOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in getting pending operation.");
|
||||
}
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
|
||||
if ((OperationCode.Command.WIPE_DATA.getCode().equals(operation.getCode())) &&
|
||||
(operation.getId() == status.getCommandReference())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDisenrollOperationStatus(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||
List<? extends Operation> pendingDeviceInfoOperations;
|
||||
try {
|
||||
pendingDeviceInfoOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while getting pending operations.");
|
||||
}
|
||||
for (Operation operation : pendingDeviceInfoOperations) {
|
||||
if (PluginConstants.OperationCodes.DISENROLL.equals(operation.getCode())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDeviceInfoStatus(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||
List<? extends Operation> pendingDeviceInfoOperations;
|
||||
try {
|
||||
pendingDeviceInfoOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while getting pending operations.");
|
||||
}
|
||||
for (Operation operation : pendingDeviceInfoOperations) {
|
||||
if (PluginConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDeviceLocationStatus(SyncmlDocument syncmlDocument) throws OperationManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
try {
|
||||
pendingDataOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in getting pending operation.");
|
||||
}
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (PluginConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
|
||||
if (syncmlDocument.getBody().getResults() != null) {
|
||||
List<ItemTag> items = syncmlDocument.getBody().getResults().getItem();
|
||||
for (ItemTag itemTag : items) {
|
||||
if (OperationCode.Command.LATITUDE.getCode().equals(itemTag.getSource().getLocURI())) {
|
||||
// at this moment we can't get accepted value 200 from the device.
|
||||
if (itemTag.getData() != null) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
} else {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pending operations.
|
||||
*
|
||||
* @param syncmlDocument SyncmlDocument object which creates from the syncml engine using syncml payload
|
||||
* @return Return list of pending operations.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public List<? extends Operation> getPendingOperations(SyncmlDocument syncmlDocument)
|
||||
throws OperationManagementException, WindowsOperationException {
|
||||
SyncmlHeader syncmlHeader = syncmlDocument.getHeader();
|
||||
SyncmlBody syncmlBody = syncmlDocument.getBody();
|
||||
List<? extends Operation> pendingOperations;
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource().getLocURI());
|
||||
if (syncmlBody.getResults() != null) {
|
||||
List<ItemTag> items = syncmlBody.getResults().getItem();
|
||||
for (ItemTag itemTag : items) {
|
||||
if (OperationCode.Command.LATITUDE.getCode().equals(itemTag.getSource().getLocURI())) {
|
||||
updateLocation(syncmlDocument);
|
||||
}
|
||||
if (OperationCode.Command.TOTAL_RAM.getCode().equals(itemTag.getSource().getLocURI())) {
|
||||
updateDeviceInfo(syncmlDocument);
|
||||
}
|
||||
if (OperationCode.Command.BATTERY_CHARGE_REMAINING.equals(itemTag.getSource().getLocURI())) {
|
||||
updateDeviceInfo(syncmlDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateUriOperations(syncmlDocument);
|
||||
generateComplianceFeatureStatus(syncmlDocument);
|
||||
pendingOperations = WindowsAPIUtils.getDeviceManagementService().getPendingOperations(deviceIdentifier);
|
||||
return pendingOperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set compliance of the feature according to the device status for the specific feature.
|
||||
*
|
||||
* @param activeFeature Features to be applied on the device.
|
||||
* @param deviceFeature Actual features applied on the device.
|
||||
* @return Returns setting up compliance feature.
|
||||
*/
|
||||
public ComplianceFeature setComplianceFeatures(ProfileFeature activeFeature, Profile deviceFeature) {
|
||||
ComplianceFeature complianceFeature = new ComplianceFeature();
|
||||
complianceFeature.setFeature(activeFeature);
|
||||
complianceFeature.setFeatureCode(activeFeature.getFeatureCode());
|
||||
complianceFeature.setCompliance(deviceFeature.isCompliance());
|
||||
return complianceFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the completed/Error status of the operation which have the URI of the operation code in the syncml payload.
|
||||
*
|
||||
* @param syncmlDocument SyncmlDocument object generated from the the syncml engine.
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void UpdateUriOperations(SyncmlDocument syncmlDocument) throws OperationManagementException,
|
||||
WindowsOperationException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
|
||||
List<StatusTag> statuses = syncmlDocument.getBody().getStatus();
|
||||
try {
|
||||
pendingDataOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred in getting pending operation.");
|
||||
}
|
||||
for (StatusTag status : statuses) {
|
||||
|
||||
if ((Constants.EXECUTE.equals(status.getCommand()))) {
|
||||
if (status.getTargetReference() == null) {
|
||||
updateDeviceOperations(status, syncmlDocument, deviceIdentifier);
|
||||
} else {
|
||||
if ((OperationCode.Command.DEVICE_LOCK.getCode().equals(status.getTargetReference()))) {
|
||||
updateLockOperation(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
if ((OperationCode.Command.DEVICE_RING.getCode().equals(status.getTargetReference()))) {
|
||||
ring(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
if ((OperationCode.Command.WIPE_DATA.getCode().equals(status.getTargetReference()))) {
|
||||
dataWipe(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((Constants.SEQUENCE.equals(status.getCommand()))) {
|
||||
if ((Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData()))) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if ((PluginConstants.OperationCodes.POLICY_BUNDLE.equals(operation.getCode())) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.MONITOR.equals(operation.getCode())) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
if (PluginConstants.OperationCodes.POLICY_REVOKE.equals(operation.getCode())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
} else {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
|
||||
if ((PluginConstants.OperationCodes.POLICY_BUNDLE.equals(operation.getCode())) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.MONITOR.equals(operation.getCode())) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
}
|
||||
if (PluginConstants.OperationCodes.POLICY_REVOKE.equals(operation.getCode())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate status of the features that have been activated on the device.
|
||||
*
|
||||
* @param syncmlDocument syncmlDocument object pasrsed from the syncml engine.
|
||||
* @return device statuses for the activated features
|
||||
* @throws WindowsOperationException
|
||||
*/
|
||||
public List<Profile> generateDeviceOperationStatusObject(SyncmlDocument syncmlDocument) throws
|
||||
WindowsOperationException {
|
||||
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
String lockUri = null;
|
||||
ResultsTag result = syncmlDocument.getBody().getResults();
|
||||
|
||||
List<Profile> profiles = new ArrayList<>();
|
||||
if (result != null) {
|
||||
List<ItemTag> results = result.getItem();
|
||||
for (OperationCode.Info info : OperationCode.Info.values()) {
|
||||
if (PluginConstants.OperationCodes.PIN_CODE.equals(info
|
||||
.name())) {
|
||||
lockUri = info.getCode();
|
||||
}
|
||||
}
|
||||
for (ItemTag item : results) {
|
||||
for (OperationCode.Info info : OperationCode.Info.values()) {
|
||||
if (item.getSource().getLocURI().equals(info.getCode()) &&
|
||||
PluginConstants.OperationCodes.CAMERA_STATUS.equals(info.name())) {
|
||||
Profile cameraProfile = new Profile();
|
||||
cameraProfile.setFeatureCode(PluginConstants.OperationCodes.CAMERA);
|
||||
cameraProfile.setData(item.getData());
|
||||
if ((PluginConstants.SyncML.SYNCML_DATA_ONE.equals(item.getData()))) {
|
||||
cameraProfile.setEnable(true);
|
||||
} else {
|
||||
cameraProfile.setEnable(false);
|
||||
}
|
||||
profiles.add(cameraProfile);
|
||||
}
|
||||
if (item.getSource().getLocURI().equals(info.getCode()) &&
|
||||
PluginConstants.OperationCodes.ENCRYPT_STORAGE_STATUS.equals(info.name())) {
|
||||
Profile encryptStorage = new Profile();
|
||||
encryptStorage.setFeatureCode(PluginConstants.OperationCodes.ENCRYPT_STORAGE);
|
||||
encryptStorage.setData(item.getData());
|
||||
if ((PluginConstants.SyncML.SYNCML_DATA_ONE.equals(item.getData()))) {
|
||||
encryptStorage.setEnable(true);
|
||||
} else {
|
||||
encryptStorage.setEnable(false);
|
||||
}
|
||||
profiles.add(encryptStorage);
|
||||
}
|
||||
if (item.getSource().getLocURI().equals(info.getCode()) &&
|
||||
PluginConstants.OperationCodes.DEVICE_PASSWORD_STATUS.equals(info.name())) {
|
||||
Profile encryptStorage = new Profile();
|
||||
encryptStorage.setFeatureCode(PluginConstants.OperationCodes.PASSCODE_POLICY);
|
||||
encryptStorage.setData(item.getData());
|
||||
if ((PluginConstants.SyncML.SYNCML_DATA_ZERO.equals(item.getData()))) {
|
||||
encryptStorage.setEnable(true);
|
||||
} else {
|
||||
encryptStorage.setEnable(false);
|
||||
}
|
||||
profiles.add(encryptStorage);
|
||||
}
|
||||
if (!item.getData().isEmpty() && item.getSource().getLocURI().equals(lockUri)) {
|
||||
String pinValue = item.getData();
|
||||
NotificationManagementService nmService = WindowsAPIUtils.getNotificationManagementService();
|
||||
Notification notification = new Notification();
|
||||
notification.setDescription("Auto generated DevicePin : " + pinValue);
|
||||
notification.setOperationId(result.getCommandReference());
|
||||
notification.setStatus(String.valueOf(Notification.Status.NEW));
|
||||
try {
|
||||
nmService.addNotification(deviceIdentifier, notification);
|
||||
} catch (NotificationManagementException e) {
|
||||
throw new WindowsOperationException("Failure Occurred while getting notification" +
|
||||
" service.", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Compliance Features.
|
||||
*
|
||||
* @param syncmlDocument syncmlDocument object parsed from the syncml engine.
|
||||
* @throws WindowsOperationException
|
||||
*/
|
||||
public void generateComplianceFeatureStatus(SyncmlDocument syncmlDocument) throws WindowsOperationException {
|
||||
List<Profile> profiles = generateDeviceOperationStatusObject(syncmlDocument);
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
boolean isCompliance = false;
|
||||
if (profiles.size() != Constants.EMPTY) {
|
||||
try {
|
||||
if (WindowsAPIUtils.getPolicyManagerService().getAppliedPolicyToDevice(deviceIdentifier).getProfile().
|
||||
getProfileFeaturesList() != null) {
|
||||
List<ProfileFeature> profileFeatures = WindowsAPIUtils.getPolicyManagerService().
|
||||
getAppliedPolicyToDevice(deviceIdentifier).getProfile().getProfileFeaturesList();
|
||||
List<ComplianceFeature> complianceFeatures = new ArrayList<>();
|
||||
for (ProfileFeature activeFeature : profileFeatures) {
|
||||
JSONObject policyContent = new JSONObject(activeFeature.getContent().toString());
|
||||
|
||||
for (Profile deviceFeature : profiles) {
|
||||
if (deviceFeature.getFeatureCode().equals(activeFeature.getFeatureCode()) &&
|
||||
(PluginConstants.OperationCodes.CAMERA.equals(deviceFeature.getFeatureCode()))) {
|
||||
if (policyContent.getBoolean(PluginConstants.PolicyConfigProperties.
|
||||
POLICY_ENABLE) == (deviceFeature.isEnable())) {
|
||||
isCompliance = true;
|
||||
deviceFeature.setCompliance(isCompliance);
|
||||
} else {
|
||||
deviceFeature.setCompliance(isCompliance);
|
||||
}
|
||||
ComplianceFeature complianceFeature = setComplianceFeatures(activeFeature,
|
||||
deviceFeature);
|
||||
complianceFeatures.add(complianceFeature);
|
||||
}
|
||||
if (deviceFeature.getFeatureCode().equals(activeFeature.getFeatureCode()) &&
|
||||
(PluginConstants.OperationCodes.
|
||||
ENCRYPT_STORAGE.equals(deviceFeature.getFeatureCode()))) {
|
||||
if (policyContent.getBoolean(PluginConstants.PolicyConfigProperties.
|
||||
ENCRYPTED_ENABLE) == (deviceFeature.isEnable())) {
|
||||
isCompliance = true;
|
||||
deviceFeature.setCompliance(isCompliance);
|
||||
} else {
|
||||
deviceFeature.setCompliance(isCompliance);
|
||||
}
|
||||
ComplianceFeature complianceFeature = setComplianceFeatures(activeFeature,
|
||||
deviceFeature);
|
||||
complianceFeatures.add(complianceFeature);
|
||||
}
|
||||
if (deviceFeature.getFeatureCode().equals(activeFeature.getFeatureCode()) &&
|
||||
(PluginConstants.OperationCodes.
|
||||
PASSCODE_POLICY.equals(deviceFeature.getFeatureCode()))) {
|
||||
if (policyContent.getBoolean(PluginConstants.PolicyConfigProperties.
|
||||
ENABLE_PASSWORD) == (deviceFeature.isEnable())) {
|
||||
isCompliance = true;
|
||||
deviceFeature.setCompliance(isCompliance);
|
||||
} else {
|
||||
deviceFeature.setCompliance(isCompliance);
|
||||
}
|
||||
ComplianceFeature complianceFeature = setComplianceFeatures(activeFeature,
|
||||
deviceFeature);
|
||||
complianceFeatures.add(complianceFeature);
|
||||
}
|
||||
}
|
||||
}
|
||||
WindowsAPIUtils.getPolicyManagerService().checkPolicyCompliance(deviceIdentifier,
|
||||
complianceFeatures);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new WindowsOperationException("Error occurred while parsing json object.", e);
|
||||
} catch (PolicyComplianceException e) {
|
||||
throw new WindowsOperationException("Error occurred while setting up policy compliance.", e);
|
||||
} catch (PolicyManagementException e) {
|
||||
throw new WindowsOperationException("Error occurred while getting effective policy.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateDeviceInfo(SyncmlDocument syncmlDocument) throws WindowsOperationException {
|
||||
String softwareVersion;
|
||||
String imsi;
|
||||
String imei;
|
||||
String model;
|
||||
String vendor;
|
||||
String totalRAM;
|
||||
String deviceID = null;
|
||||
String totalStorage;
|
||||
Double battery;
|
||||
|
||||
List<ItemTag> deviceInformations = syncmlDocument.getBody().getResults().getItem();
|
||||
DeviceInfo deviceInfo = new DeviceInfo();
|
||||
for (ItemTag item : deviceInformations) {
|
||||
String source = item.getSource().getLocURI();
|
||||
if (OperationCode.Info.SOFTWARE_VERSION.getCode().equals(source)) {
|
||||
softwareVersion = item.getData();
|
||||
deviceInfo.setOsVersion(softwareVersion);
|
||||
}
|
||||
if (OperationCode.Info.IMSI.getCode().equals(source)) {
|
||||
imsi = item.getData();
|
||||
deviceInfo.getDeviceDetailsMap().put("IMSI", imsi);
|
||||
}
|
||||
if (OperationCode.Info.IMEI.getCode().equals(source)) {
|
||||
imei = item.getData();
|
||||
deviceInfo.getDeviceDetailsMap().put("IMEI", imei);
|
||||
}
|
||||
if (OperationCode.Info.DEVICE_MODEL.getCode().equals(source)) {
|
||||
model = item.getData();
|
||||
deviceInfo.setDeviceModel(model);
|
||||
}
|
||||
if (OperationCode.Info.VENDOR.getCode().equals(source)) {
|
||||
vendor = item.getData();
|
||||
deviceInfo.setVendor(vendor);
|
||||
}
|
||||
if (OperationCode.Info.TOTAL_RAM.getCode().equals(source)) {
|
||||
totalRAM = item.getData();
|
||||
deviceInfo.setAvailableRAMMemory(Double.parseDouble(totalRAM));
|
||||
}
|
||||
if (OperationCode.Info.TOTAL_STORAGE.getCode().equals(source)) {
|
||||
totalStorage = item.getData();
|
||||
deviceInfo.setInternalAvailableMemory(Double.parseDouble(totalStorage));
|
||||
}
|
||||
if (OperationCode.Info.DEV_ID.getCode().equals(source)) {
|
||||
deviceID = item.getData();
|
||||
}
|
||||
if (OperationCode.Info.BATTERY_CHARGE_REMAINING.getCode().equals(source)) {
|
||||
battery = Double.valueOf(item.getData());
|
||||
deviceInfo.setBatteryLevel(battery);
|
||||
}
|
||||
}
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(deviceID);
|
||||
try {
|
||||
WindowsAPIUtils.updateDeviceInfo(deviceIdentifier, deviceInfo);
|
||||
updateDeviceInfoStatus(deviceIdentifier);
|
||||
} catch (org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException e) {
|
||||
throw new WindowsOperationException("Error occurred while adding Device info.");
|
||||
} catch (OperationManagementException e) {
|
||||
throw new WindowsOperationException("Error occurred while updating Device info operation status.");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLocation(SyncmlDocument syncmlDocument) throws WindowsOperationException {
|
||||
List<ItemTag> deviceInformations = syncmlDocument.getBody().getResults().getItem();
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
|
||||
DeviceLocation deviceLocation = new DeviceLocation();
|
||||
deviceLocation.setDeviceIdentifier(deviceIdentifier);
|
||||
for (ItemTag item : deviceInformations) {
|
||||
String source = item.getSource().getLocURI();
|
||||
if (OperationCode.Info.LONGITUDE.getCode().equals(source)) {
|
||||
String longitude = item.getData();
|
||||
deviceLocation.setLongitude(Double.parseDouble(longitude));
|
||||
}
|
||||
if (OperationCode.Info.LATITUDE.getCode().equals(source)) {
|
||||
Double latitude = Double.parseDouble(item.getData());
|
||||
deviceLocation.setLatitude(latitude);
|
||||
}
|
||||
}
|
||||
try {
|
||||
WindowsAPIUtils.updateDeviceLocation(deviceLocation);
|
||||
updateDeviceLocationStatus(syncmlDocument);
|
||||
} catch (DeviceDetailsMgtException e) {
|
||||
throw new WindowsOperationException("Error occurred while updating Device Location.");
|
||||
} catch (OperationManagementException e) {
|
||||
throw new WindowsOperationException("Error occurred while updating Device Location operation status.");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForDeviceWipe(List<? extends Operation> pendingDeviceInfoOperations
|
||||
, DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||
for (Operation operation : pendingDeviceInfoOperations) {
|
||||
if (PluginConstants.OperationCodes.WIPE_DATA.equals(operation.getCode())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,884 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.bean.EnterpriseApplication;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.SyncmlCommandType;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.SyncmlMessageFormatException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.SyncmlOperationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.PasscodePolicy;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.Wifi;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.*;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils.convertToDeviceIdentifierObject;
|
||||
import static org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.OperationCode.*;
|
||||
|
||||
/**
|
||||
* Used to generate a reply to a receiving syncml from a device.
|
||||
*/
|
||||
public class OperationReply {
|
||||
|
||||
private SyncmlDocument syncmlDocument;
|
||||
private SyncmlDocument replySyncmlDocument;
|
||||
private int headerCommandId = 1;
|
||||
private static final int HEADER_STATUS_ID = 0;
|
||||
private static final String RESULTS_COMMAND_TEXT = "Results";
|
||||
private static final String HEADER_COMMAND_TEXT = "SyncHdr";
|
||||
private static final String ALERT_COMMAND_TEXT = "Alert";
|
||||
private static final String REPLACE_COMMAND_TEXT = "Replace";
|
||||
private static final String GET_COMMAND_TEXT = "Get";
|
||||
private static final String EXEC_COMMAND_TEXT = "Exec";
|
||||
private List<? extends Operation> operations;
|
||||
Gson gson = new Gson();
|
||||
|
||||
public OperationReply(SyncmlDocument syncmlDocument, List<? extends Operation> operations) {
|
||||
this.syncmlDocument = syncmlDocument;
|
||||
replySyncmlDocument = new SyncmlDocument();
|
||||
this.operations = operations;
|
||||
}
|
||||
|
||||
public OperationReply(SyncmlDocument syncmlDocument) {
|
||||
this.syncmlDocument = syncmlDocument;
|
||||
replySyncmlDocument = new SyncmlDocument();
|
||||
}
|
||||
|
||||
public OperationReply() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Device payloads.
|
||||
*
|
||||
* @param syncmlDocument Parsed syncml payload from the syncml engine.
|
||||
* @param operations Operations for generate payload.
|
||||
* @return String type syncml payload.
|
||||
* @throws WindowsOperationException
|
||||
* @throws PolicyManagementException
|
||||
* @throws org.wso2.carbon.policy.mgt.common.FeatureManagementException
|
||||
*/
|
||||
public String generateReply(SyncmlDocument syncmlDocument, List<? extends Operation> operations)
|
||||
throws SyncmlMessageFormatException, SyncmlOperationException, WindowsOperationException {
|
||||
|
||||
OperationReply operationReply;
|
||||
SyncmlGenerator generator;
|
||||
SyncmlDocument syncmlResponse;
|
||||
if (operations == null) {
|
||||
operationReply = new OperationReply(syncmlDocument);
|
||||
} else {
|
||||
operationReply = new OperationReply(syncmlDocument, operations);
|
||||
}
|
||||
syncmlResponse = operationReply.generateReply();
|
||||
generator = new SyncmlGenerator();
|
||||
return generator.generatePayload(syncmlResponse);
|
||||
}
|
||||
|
||||
public SyncmlDocument generateReply()
|
||||
throws SyncmlMessageFormatException, SyncmlOperationException, WindowsOperationException {
|
||||
generateHeader();
|
||||
generateBody();
|
||||
return replySyncmlDocument;
|
||||
}
|
||||
|
||||
private void generateHeader() throws SyncmlMessageFormatException {
|
||||
String nextNonceValue = Constants.INITIAL_NONCE;
|
||||
SyncmlHeader sourceHeader = syncmlDocument.getHeader();
|
||||
SyncmlHeader header = new SyncmlHeader();
|
||||
header.setMsgID(sourceHeader.getMsgID());
|
||||
header.setHexadecimalSessionId(Integer.toHexString(sourceHeader.getSessionId()));
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(sourceHeader.getSource().getLocURI());
|
||||
header.setTarget(target);
|
||||
|
||||
SourceTag source = new SourceTag();
|
||||
source.setLocURI(sourceHeader.getTarget().getLocURI());
|
||||
header.setSource(source);
|
||||
|
||||
CredentialTag cred = new CredentialTag();
|
||||
if (sourceHeader.getCredential() == null) {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.CRED_FORMAT);
|
||||
meta.setType(Constants.CRED_TYPE);
|
||||
cred.setMeta(meta);
|
||||
} else {
|
||||
cred.setMeta(sourceHeader.getCredential().getMeta());
|
||||
}
|
||||
SyncmlBody sourcebody = syncmlDocument.getBody();
|
||||
List<StatusTag> statuses = sourcebody.getStatus();
|
||||
|
||||
for (StatusTag status : statuses) {
|
||||
if (HEADER_COMMAND_TEXT.equals(status.getCommand()) &&
|
||||
status.getChallenge() != null) {
|
||||
nextNonceValue = status.getChallenge().getMeta().getNextNonce();
|
||||
}
|
||||
}
|
||||
cred.setData(SyncmlCredentialUtil.generateCredData(nextNonceValue));
|
||||
header.setCredential(cred);
|
||||
|
||||
replySyncmlDocument.setHeader(header);
|
||||
}
|
||||
|
||||
private void generateBody()
|
||||
throws SyncmlMessageFormatException, SyncmlOperationException, WindowsOperationException {
|
||||
SyncmlBody syncmlBody = generateStatuses();
|
||||
try {
|
||||
appendOperations(syncmlBody);
|
||||
} catch (JSONException e) {
|
||||
throw new SyncmlMessageFormatException("Error Occurred while parsing operation object.", e);
|
||||
}
|
||||
replySyncmlDocument.setBody(syncmlBody);
|
||||
}
|
||||
|
||||
private SyncmlBody generateStatuses() {
|
||||
SyncmlBody sourceSyncmlBody = syncmlDocument.getBody();
|
||||
SyncmlHeader sourceHeader = syncmlDocument.getHeader();
|
||||
StatusTag headerStatus;
|
||||
ChallengeTag challengeTag = new ChallengeTag();
|
||||
MetaTag metaTag = new MetaTag();
|
||||
metaTag.setFormat(Constants.CRED_FORMAT);
|
||||
metaTag.setType(Constants.CRED_TYPE);
|
||||
metaTag.setNextNonce(Constants.INITIAL_NONCE);
|
||||
challengeTag.setMeta(metaTag);
|
||||
SyncmlBody syncmlBodyReply = new SyncmlBody();
|
||||
List<StatusTag> statuses = new ArrayList<>();
|
||||
List<StatusTag> sourceStatuses = sourceSyncmlBody.getStatus();
|
||||
if (sourceStatuses.isEmpty()) {
|
||||
headerStatus =
|
||||
new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID,
|
||||
HEADER_COMMAND_TEXT, challengeTag,sourceHeader.getSource().getLocURI(),
|
||||
String.valueOf(Constants.SyncMLResponseCodes.UNAUTHORIZED));
|
||||
statuses.add(headerStatus);
|
||||
} else {
|
||||
for (StatusTag sourceStatus : sourceStatuses) {
|
||||
if (sourceStatus.getChallenge() != null && HEADER_COMMAND_TEXT.equals(sourceStatus.getCommand())) {
|
||||
headerStatus =
|
||||
new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID,
|
||||
HEADER_COMMAND_TEXT, challengeTag, sourceHeader.getSource().getLocURI(),
|
||||
String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED));
|
||||
statuses.add(headerStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sourceSyncmlBody.getResults() != null) {
|
||||
int ResultCommandId = ++headerCommandId;
|
||||
StatusTag resultStatus = new StatusTag(ResultCommandId, sourceHeader.getMsgID(),
|
||||
sourceSyncmlBody.getResults().getCommandId(), RESULTS_COMMAND_TEXT, null,
|
||||
String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
|
||||
statuses.add(resultStatus);
|
||||
}
|
||||
if (sourceSyncmlBody.getAlert() != null) {
|
||||
int alertCommandId = ++headerCommandId;
|
||||
StatusTag alertStatus = new StatusTag(alertCommandId,
|
||||
sourceHeader.getMsgID(),
|
||||
sourceSyncmlBody.getAlert().getCommandId(),
|
||||
ALERT_COMMAND_TEXT, null,
|
||||
String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
|
||||
statuses.add(alertStatus);
|
||||
}
|
||||
if (sourceSyncmlBody.getReplace() != null) {
|
||||
int replaceCommandId = ++headerCommandId;
|
||||
StatusTag replaceStatus = new StatusTag(replaceCommandId, sourceHeader.getMsgID(),
|
||||
sourceSyncmlBody.getReplace().getCommandId(), REPLACE_COMMAND_TEXT, null,
|
||||
String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED)
|
||||
);
|
||||
statuses.add(replaceStatus);
|
||||
}
|
||||
if (sourceSyncmlBody.getExec() != null) {
|
||||
List<ExecuteTag> Executes = sourceSyncmlBody.getExec();
|
||||
for (ExecuteTag exec : Executes) {
|
||||
int execCommandId = ++headerCommandId;
|
||||
StatusTag execStatus = new StatusTag(execCommandId, sourceHeader.getMsgID(),
|
||||
exec.getCommandId(), EXEC_COMMAND_TEXT, null, String.valueOf(
|
||||
Constants.SyncMLResponseCodes.ACCEPTED));
|
||||
statuses.add(execStatus);
|
||||
}
|
||||
}
|
||||
if (sourceSyncmlBody.getGet() != null) {
|
||||
int getCommandId = ++headerCommandId;
|
||||
StatusTag execStatus = new StatusTag(getCommandId, sourceHeader.getMsgID(), sourceSyncmlBody
|
||||
.getGet().getCommandId(), GET_COMMAND_TEXT, null, String.valueOf(
|
||||
Constants.SyncMLResponseCodes.ACCEPTED));
|
||||
statuses.add(execStatus);
|
||||
}
|
||||
syncmlBodyReply.setStatus(statuses);
|
||||
return syncmlBodyReply;
|
||||
}
|
||||
|
||||
private void appendOperations(SyncmlBody syncmlBody)
|
||||
throws JSONException, SyncmlOperationException, WindowsOperationException {
|
||||
GetTag getElement = new GetTag();
|
||||
List<ItemTag> getElements = new ArrayList<>();
|
||||
List<ExecuteTag> executeElements = new ArrayList<>();
|
||||
AtomicTag atomicTagElement = new AtomicTag();
|
||||
List<AddTag> addElements = new ArrayList<>();
|
||||
ReplaceTag replaceElement = new ReplaceTag();
|
||||
List<ItemTag> replaceItems = new ArrayList<>();
|
||||
SequenceTag monitorSequence = new SequenceTag();
|
||||
List<Operation> deviceInfoOperations;
|
||||
if (operations != null) {
|
||||
for (Operation operation : operations) {
|
||||
Operation.Type type = operation.getType();
|
||||
switch (type) {
|
||||
case POLICY:
|
||||
if (this.syncmlDocument.getBody().getAlert() != null) {
|
||||
if ((Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody().getAlert()
|
||||
.getData())) || Constants.INITIAL_WIN10_ALERT_DATA.
|
||||
equals(this.syncmlDocument.getBody()
|
||||
.getAlert().getData())) {
|
||||
SequenceTag policySequence = new SequenceTag();
|
||||
policySequence = buildSequence(operation, policySequence);
|
||||
syncmlBody.setSequence(policySequence);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CONFIG:
|
||||
List<AddTag> addConfigurations = appendAddConfiguration(operation);
|
||||
for (AddTag addConfiguration : addConfigurations) {
|
||||
addElements.add(addConfiguration);
|
||||
}
|
||||
break;
|
||||
case MESSAGE:
|
||||
|
||||
break;
|
||||
case INFO:
|
||||
ItemTag itemGet = appendGetInfo(operation);
|
||||
getElements.add(itemGet);
|
||||
break;
|
||||
case COMMAND:
|
||||
ExecuteTag execElement;
|
||||
if ((PluginConstants.OperationCodes.DEVICE_LOCK.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.DEVICE_RING.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.DISENROLL.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.WIPE_DATA.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.LOCK_RESET.equals(operation.getCode()))) {
|
||||
SequenceTag sequenceElement = new SequenceTag();
|
||||
SequenceTag sequence = buildSequence(operation, sequenceElement);
|
||||
syncmlBody.setSequence(sequence);
|
||||
}
|
||||
if (PluginConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
|
||||
Operation longitudeOperation = new Operation();
|
||||
Operation latitudeOperation = new Operation();
|
||||
longitudeOperation.setCode(PluginConstants.OperationCodes.LONGITUDE);
|
||||
latitudeOperation.setCode(PluginConstants.OperationCodes.LATITUDE);
|
||||
List<Operation> deviceLocationOperations = new ArrayList<>();
|
||||
deviceLocationOperations.add(latitudeOperation);
|
||||
deviceLocationOperations.add(longitudeOperation);
|
||||
for (Operation infoOperation : deviceLocationOperations) {
|
||||
ItemTag deviceInfo = appendGetInfo(infoOperation);
|
||||
getElements.add(deviceInfo);
|
||||
}
|
||||
}
|
||||
if (PluginConstants.OperationCodes.DEVICE_REBOOT.equals(operation.getCode())) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.MONITOR.equals(operation.getCode()))) {
|
||||
GetTag monitorGetElement = new GetTag();
|
||||
List<ItemTag> monitorItems;
|
||||
List<ProfileFeature> profileFeatures;
|
||||
|
||||
if (this.syncmlDocument.getBody().getAlert() != null) {
|
||||
if (Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody().
|
||||
getAlert().getData()) || Constants.INITIAL_WIN10_ALERT_DATA.
|
||||
equals(this.syncmlDocument.getBody()
|
||||
.getAlert().getData())) {
|
||||
|
||||
monitorSequence.setCommandId(operation.getId());
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
try {
|
||||
profileFeatures = WindowsAPIUtils.getPolicyManagerService().
|
||||
getEffectiveFeatures(deviceIdentifier);
|
||||
} catch (FeatureManagementException e) {
|
||||
throw new SyncmlOperationException("Error in getting effective policy.", e);
|
||||
}
|
||||
monitorItems = buildMonitorOperation(profileFeatures);
|
||||
if (!monitorItems.isEmpty()) {
|
||||
monitorGetElement.setCommandId(operation.getId());
|
||||
monitorGetElement.setItems(monitorItems);
|
||||
}
|
||||
monitorSequence.setGet(monitorGetElement);
|
||||
syncmlBody.setSequence(monitorSequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PluginConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
|
||||
if (this.syncmlDocument.getBody().getAlert() != null) {
|
||||
if ((Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody().getAlert()
|
||||
.getData())) || Constants.INITIAL_WIN10_ALERT_DATA.
|
||||
equals(this.syncmlDocument.getBody()
|
||||
.getAlert().getData())) {
|
||||
HeartBeatDeviceInfo heartBeatDeviceInfo = new HeartBeatDeviceInfo();
|
||||
deviceInfoOperations = heartBeatDeviceInfo.getDeviceInfo();
|
||||
for (Operation infoOperation : deviceInfoOperations) {
|
||||
ItemTag deviceInfo = appendGetInfo(infoOperation);
|
||||
getElements.add(deviceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PROFILE:
|
||||
if (PluginConstants.OperationCodes.INSTALL_ENTERPRISE_APPLICATION.equals(operation.getCode())) {
|
||||
EnterpriseApplication enterpriseApplication = gson
|
||||
.fromJson((String) operation.getPayLoad(), EnterpriseApplication.class);
|
||||
List<Object> enterpriseApplicationContent = enterpriseApplication
|
||||
.createOperationContent(operation);
|
||||
for (Object object : enterpriseApplicationContent) {
|
||||
if (object instanceof AddTag) {
|
||||
addElements.add((AddTag) object);
|
||||
} else if (object instanceof ExecuteTag) {
|
||||
executeElements.add((ExecuteTag) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!replaceItems.isEmpty()) {
|
||||
replaceElement.setCommandId(Constants.SyncmlMessageCodes.replaceCommandId);
|
||||
replaceElement.setItems(replaceItems);
|
||||
}
|
||||
if (!getElements.isEmpty()) {
|
||||
getElement.setCommandId(Constants.SyncmlMessageCodes.elementCommandId);
|
||||
getElement.setItems(getElements);
|
||||
}
|
||||
if (!addElements.isEmpty()) {
|
||||
atomicTagElement.setCommandId(Constants.SyncmlMessageCodes.atomicCommandId);
|
||||
atomicTagElement.setAdds(addElements);
|
||||
}
|
||||
syncmlBody.setGet(getElement);
|
||||
syncmlBody.setExec(executeElements);
|
||||
syncmlBody.setAtomicTag(atomicTagElement);
|
||||
syncmlBody.setReplace(replaceElement);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemTag appendExecInfo(Operation operation) {
|
||||
ItemTag item = new ItemTag();
|
||||
String operationCode = operation.getCode();
|
||||
for (Command command : Command.values()) {
|
||||
if (operationCode != null && operationCode.equals(command.name())) {
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(command.getCode());
|
||||
if ((PluginConstants
|
||||
.OperationCodes.DISENROLL.equals(operation.getCode()))) {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_CHARACTER);
|
||||
item.setMeta(meta);
|
||||
item.setData(Constants.PROVIDER_ID);
|
||||
}
|
||||
item.setTarget(target);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private ItemTag appendGetInfo(Operation operation) {
|
||||
ItemTag item = new ItemTag();
|
||||
String operationCode = operation.getCode();
|
||||
for (Info info : Info.values()) {
|
||||
if (operationCode != null && operationCode.equals(info.name())) {
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(info.getCode());
|
||||
item.setTarget(target);
|
||||
}
|
||||
}
|
||||
if ((operationCode != null) &&
|
||||
PluginConstants.OperationCodes.LOCK_RESET.equals(operationCode)) {
|
||||
operation.setCode(PluginConstants.OperationCodes.PIN_CODE);
|
||||
for (Info getInfo : Info.values()) {
|
||||
if (operation.getCode().equals(getInfo.name())) {
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(getInfo.getCode());
|
||||
item.setTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private ItemTag appendReplaceInfo(Operation operation) throws JSONException {
|
||||
String policyAllowData = "1";
|
||||
String policyDisallowData = "0";
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag target = new TargetTag();
|
||||
String operationCode = operation.getCode();
|
||||
JSONObject payload = new JSONObject(operation.getPayLoad().toString());
|
||||
for (Command command : Command.values()) {
|
||||
|
||||
if (operationCode != null && operationCode.equals(command.name())) {
|
||||
target.setLocURI(command.getCode());
|
||||
|
||||
if ((PluginConstants.OperationCodes.CAMERA.equals(operation.getCode()))) {
|
||||
|
||||
if (payload.getBoolean("enabled")) {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData(policyAllowData);
|
||||
} else {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData(policyDisallowData);
|
||||
}
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.ENCRYPT_STORAGE.
|
||||
equals(operation.getCode()))) {
|
||||
|
||||
if (payload.getBoolean("encrypted")) {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData(policyAllowData);
|
||||
} else {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData(policyDisallowData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private List<AddTag> appendAddInfo(Operation operation) throws WindowsOperationException {
|
||||
|
||||
List<AddTag> addList = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
|
||||
if ((PluginConstants.OperationCodes.PASSCODE_POLICY.equals(operation.getCode()))) {
|
||||
|
||||
PasscodePolicy passcodeObject = gson.fromJson((String) operation.getPayLoad(), PasscodePolicy.class);
|
||||
|
||||
for (Configure configure : Configure.values()) {
|
||||
|
||||
if (operation.getCode() != null && PluginConstants.OperationCodes.PASSWORD_MAX_FAIL_ATTEMPTS.
|
||||
equals(configure.name())) {
|
||||
AddTag add = generatePasscodePolicyData(configure, passcodeObject.getMaxFailedAttempts());
|
||||
addList.add(add);
|
||||
}
|
||||
if (operation.getCode() != null && (PluginConstants.OperationCodes.DEVICE_PASSWORD_ENABLE.
|
||||
equals(configure.name()) || PluginConstants.OperationCodes.SIMPLE_PASSWORD.
|
||||
equals(configure.name()) || PluginConstants.OperationCodes.ALPHANUMERIC_PASSWORD.
|
||||
equals(configure.name()))) {
|
||||
AddTag add = generatePasscodeBooleanData(operation, configure);
|
||||
addList.add(add);
|
||||
}
|
||||
if (operation.getCode() != null && PluginConstants.OperationCodes.MIN_PASSWORD_LENGTH.
|
||||
equals(configure.name())) {
|
||||
AddTag add = generatePasscodePolicyData(configure, passcodeObject.getMinLength());
|
||||
addList.add(add);
|
||||
}
|
||||
if (operation.getCode() != null && PluginConstants.OperationCodes.PASSWORD_EXPIRE.
|
||||
equals(configure.name())) {
|
||||
AddTag add = generatePasscodePolicyData(configure, passcodeObject.getMaxPINAgeInDays());
|
||||
addList.add(add);
|
||||
}
|
||||
if (operation.getCode() != null && PluginConstants.OperationCodes.PASSWORD_HISTORY.
|
||||
equals(configure.name())) {
|
||||
int pinHistory = passcodeObject.getPinHistory();
|
||||
AddTag add = generatePasscodePolicyData(configure, pinHistory);
|
||||
addList.add(add);
|
||||
}
|
||||
if (operation.getCode() != null && PluginConstants.OperationCodes.MAX_PASSWORD_INACTIVE_TIME.
|
||||
equals(configure.name())) {
|
||||
AddTag add = generatePasscodePolicyData(configure, passcodeObject.getMaxInactiveTime());
|
||||
addList.add(add);
|
||||
}
|
||||
if (operation.getCode() != null && PluginConstants.OperationCodes.MIN_PASSWORD_COMPLEX_CHARACTERS.
|
||||
equals(configure.name())) {
|
||||
int complexChars = passcodeObject.getMinComplexChars();
|
||||
AddTag add = generatePasscodePolicyData(configure, complexChars);
|
||||
addList.add(add);
|
||||
}
|
||||
}
|
||||
}
|
||||
return addList;
|
||||
}
|
||||
|
||||
private List<AddTag> appendAddConfiguration(Operation operation) {
|
||||
|
||||
List<AddTag> addList = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
|
||||
if (SyncmlCommandType.WIFI.getValue().equals(operation.getCode())) {
|
||||
AddTag add = new AddTag();
|
||||
String operationCode = operation.getCode();
|
||||
Wifi wifiObject = gson.fromJson((String) operation.getPayLoad(), Wifi.class);
|
||||
String data = "<?xml version="1.0"?><WLANProfile" +
|
||||
"xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"><name>" +
|
||||
wifiObject.getNetworkName() + "</name><SSIDConfig><SSID><name>" +
|
||||
wifiObject.getSsid() + "</name></SSID></SSIDConfig><connectionType>" +
|
||||
wifiObject.getConnectionType() + "</connectionType><connectionMode>" +
|
||||
wifiObject.getConnectionMode() + "</connectionMode><MSM><security><" +
|
||||
"authEncryption><authentication>" + wifiObject.getAuthentication() +
|
||||
"</authentication><encryption>" + wifiObject.getEncryption() +
|
||||
"</encryption></authEncryption><sharedKey><keyType>" +
|
||||
wifiObject.getKeyType() + "</keyType><protected>" + wifiObject.getProtection() +
|
||||
"</protected><keyMaterial>" + wifiObject.getKeyMaterial() +
|
||||
"</keyMaterial></sharedKey></security></MSM></WLANProfile>";
|
||||
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_CHARACTER);
|
||||
List<ItemTag> items = new ArrayList<>();
|
||||
|
||||
for (Configure configure : Configure.values()) {
|
||||
if (operationCode != null && operationCode.equals(configure.name())) {
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(configure.getCode());
|
||||
items.get(0).setTarget(target);
|
||||
}
|
||||
}
|
||||
items.get(0).setMeta(meta);
|
||||
items.get(0).setData(data);
|
||||
|
||||
add.setCommandId(301);
|
||||
add.setItems(items);
|
||||
addList.add(add);
|
||||
return addList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExecuteTag executeCommand(Operation operation) {
|
||||
ExecuteTag execElement = new ExecuteTag();
|
||||
execElement.setCommandId(operation.getId());
|
||||
List<ItemTag> itemsExec = new ArrayList<>();
|
||||
ItemTag itemExec = appendExecInfo(operation);
|
||||
itemsExec.add(itemExec);
|
||||
execElement.setItems(itemsExec);
|
||||
return execElement;
|
||||
}
|
||||
|
||||
public SequenceTag buildSequence(Operation operation, SequenceTag sequenceElement) throws JSONException,
|
||||
SyncmlOperationException {
|
||||
|
||||
sequenceElement.setCommandId(operation.getId());
|
||||
List<ReplaceTag> replaceItems = new ArrayList<>();
|
||||
|
||||
if ((PluginConstants.OperationCodes.LOCK_RESET.equals(operation.getCode()))) {
|
||||
ExecuteTag execElement = executeCommand(operation);
|
||||
GetTag getElements = new GetTag();
|
||||
getElements.setCommandId(operation.getId());
|
||||
List<ItemTag> getItems = new ArrayList<>();
|
||||
ItemTag itemGets = appendGetInfo(operation);
|
||||
getItems.add(itemGets);
|
||||
getElements.setItems(getItems);
|
||||
|
||||
sequenceElement.setExec(execElement);
|
||||
sequenceElement.setGet(getElements);
|
||||
return sequenceElement;
|
||||
} else if ((PluginConstants.OperationCodes.POLICY_BUNDLE.equals(operation.getCode()))) {
|
||||
List<? extends Operation> policyOperations;
|
||||
try {
|
||||
policyOperations = (List<? extends Operation>) operation.getPayLoad();
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException();
|
||||
}
|
||||
for (Operation policy : policyOperations) {
|
||||
|
||||
if (PluginConstants.OperationCodes.CAMERA.equals(policy.getCode())) {
|
||||
ReplaceTag replaceCameraConfig = new ReplaceTag();
|
||||
ItemTag cameraItem;
|
||||
List<ItemTag> cameraItems = new ArrayList<>();
|
||||
|
||||
try {
|
||||
cameraItem = appendReplaceInfo(policy);
|
||||
cameraItems.add(cameraItem);
|
||||
} catch (JSONException e) {
|
||||
throw new SyncmlOperationException("Error occurred while parsing payload object to json.", e);
|
||||
}
|
||||
replaceCameraConfig.setCommandId(operation.getId());
|
||||
replaceCameraConfig.setItems(cameraItems);
|
||||
replaceItems.add(replaceCameraConfig);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.ENCRYPT_STORAGE.equals(policy.getCode()))) {
|
||||
|
||||
ReplaceTag replaceStorageConfig = new ReplaceTag();
|
||||
ItemTag storageItem;
|
||||
List<ItemTag> storageItems = new ArrayList<>();
|
||||
try {
|
||||
storageItem = appendReplaceInfo(policy);
|
||||
storageItems.add(storageItem);
|
||||
} catch (JSONException e) {
|
||||
throw new SyncmlOperationException("Error occurred while parsing payload object to json.", e);
|
||||
}
|
||||
replaceStorageConfig.setCommandId(operation.getId());
|
||||
replaceStorageConfig.setItems(storageItems);
|
||||
replaceItems.add(replaceStorageConfig);
|
||||
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.PASSCODE_POLICY.equals(policy.getCode()))) {
|
||||
AtomicTag atomicTagElement = new AtomicTag();
|
||||
List<AddTag> addConfig;
|
||||
DeleteTag deleteTag = new DeleteTag();
|
||||
try {
|
||||
addConfig = appendAddInfo(policy);
|
||||
atomicTagElement.setAdds(addConfig);
|
||||
atomicTagElement.setCommandId(operation.getId());
|
||||
List<ItemTag> deleteTagItems = buildDeletePasscodeData(policy);
|
||||
deleteTag.setCommandId(operation.getId());
|
||||
deleteTag.setItems(deleteTagItems);
|
||||
sequenceElement.setDeleteTag(deleteTag);
|
||||
sequenceElement.setAtomicTag(atomicTagElement);
|
||||
} catch (WindowsOperationException e) {
|
||||
throw new SyncmlOperationException("Error occurred while generating operation payload.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!replaceItems.isEmpty()) {
|
||||
sequenceElement.setReplaces(replaceItems);
|
||||
}
|
||||
return sequenceElement;
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemTag> buildMonitorOperation(List<ProfileFeature> effectiveMonitoringFeature) {
|
||||
List<ItemTag> monitorItems = new ArrayList<>();
|
||||
Operation monitorOperation;
|
||||
for (ProfileFeature profileFeature : effectiveMonitoringFeature) {
|
||||
|
||||
if ((PluginConstants.OperationCodes.CAMERA.equals
|
||||
(profileFeature.getFeatureCode()))) {
|
||||
String cameraStatus = PluginConstants
|
||||
.OperationCodes.CAMERA_STATUS;
|
||||
|
||||
monitorOperation = new Operation();
|
||||
monitorOperation.setCode(cameraStatus);
|
||||
ItemTag item = appendGetInfo(monitorOperation);
|
||||
monitorItems.add(item);
|
||||
}
|
||||
if (PluginConstants.OperationCodes.ENCRYPT_STORAGE.equals
|
||||
(profileFeature.getFeatureCode())) {
|
||||
String encryptStorageStatus = PluginConstants
|
||||
.OperationCodes.ENCRYPT_STORAGE_STATUS;
|
||||
|
||||
monitorOperation = new Operation();
|
||||
monitorOperation.setCode(encryptStorageStatus);
|
||||
ItemTag item = appendGetInfo(monitorOperation);
|
||||
monitorItems.add(item);
|
||||
}
|
||||
if ((PluginConstants.OperationCodes.PASSCODE_POLICY.equals
|
||||
(profileFeature.getFeatureCode()))) {
|
||||
String passcodeStatus = PluginConstants
|
||||
.OperationCodes.DEVICE_PASSWORD_STATUS;
|
||||
|
||||
monitorOperation = new Operation();
|
||||
monitorOperation.setCode(passcodeStatus);
|
||||
ItemTag item = appendGetInfo(monitorOperation);
|
||||
monitorItems.add(item);
|
||||
}
|
||||
}
|
||||
return monitorItems;
|
||||
}
|
||||
|
||||
|
||||
public List<ItemTag> buildDeletePasscodeData(Operation operation) {
|
||||
List<ItemTag> deleteTagItems = new ArrayList<>();
|
||||
ItemTag itemTag = new ItemTag();
|
||||
TargetTag target = new TargetTag();
|
||||
if ((PluginConstants.OperationCodes.PASSCODE_POLICY.equals(operation.getCode()))) {
|
||||
operation.setCode(PluginConstants.OperationCodes.DEVICE_PASSCODE_DELETE);
|
||||
for (Command command : Command.values()) {
|
||||
if (operation.getCode() != null && operation.getCode().equals(command.name())) {
|
||||
target.setLocURI(command.getCode());
|
||||
itemTag.setTarget(target);
|
||||
deleteTagItems.add(itemTag);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return deleteTagItems;
|
||||
}
|
||||
|
||||
public AddTag generatePasscodePolicyData(Configure configure, int policyData) {
|
||||
String attempt = String.valueOf(policyData);
|
||||
AddTag add = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(configure.getCode());
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData(attempt);
|
||||
itemList.add(item);
|
||||
add.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
add.setItems(itemList);
|
||||
return add;
|
||||
}
|
||||
|
||||
public AddTag generatePasscodeBooleanData(Operation operation, Configure configure) {
|
||||
AddTag addTag = null;
|
||||
|
||||
PasscodePolicy passcodePolicy = gson.fromJson((String) operation.getPayLoad(), PasscodePolicy.class);
|
||||
if (operation.getCode() != null && (PluginConstants.OperationCodes.DEVICE_PASSWORD_ENABLE.
|
||||
equals(configure.name()))) {
|
||||
if (passcodePolicy.isEnablePassword()) {
|
||||
addTag = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
targetTag.setLocURI(configure.getCode());
|
||||
MetaTag metaag = new MetaTag();
|
||||
metaag.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(targetTag);
|
||||
item.setMeta(metaag);
|
||||
item.setData(Constants.SyncMLResponseCodes.NEGATIVE_CSP_DATA);
|
||||
itemList.add(item);
|
||||
addTag.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
addTag.setItems(itemList);
|
||||
} else {
|
||||
addTag = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
targetTag.setLocURI(configure.getCode());
|
||||
MetaTag metaag = new MetaTag();
|
||||
metaag.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(targetTag);
|
||||
item.setMeta(metaag);
|
||||
item.setData(Constants.SyncMLResponseCodes.POSITIVE_CSP_DATA);
|
||||
itemList.add(item);
|
||||
addTag.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
addTag.setItems(itemList);
|
||||
}
|
||||
}
|
||||
if (PluginConstants.OperationCodes.ALPHANUMERIC_PASSWORD.
|
||||
equals(configure.name())) {
|
||||
if (passcodePolicy.isRequireAlphanumeric()) {
|
||||
addTag = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
targetTag.setLocURI(configure.getCode());
|
||||
MetaTag metaag = new MetaTag();
|
||||
metaag.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(targetTag);
|
||||
item.setMeta(metaag);
|
||||
item.setData(Constants.SyncMLResponseCodes.POSITIVE_CSP_DATA);
|
||||
itemList.add(item);
|
||||
addTag.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
addTag.setItems(itemList);
|
||||
} else {
|
||||
addTag = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
targetTag.setLocURI(configure.getCode());
|
||||
MetaTag metaag = new MetaTag();
|
||||
metaag.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(targetTag);
|
||||
item.setMeta(metaag);
|
||||
item.setData(Constants.SyncMLResponseCodes.NEGATIVE_CSP_DATA);
|
||||
itemList.add(item);
|
||||
addTag.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
addTag.setItems(itemList);
|
||||
}
|
||||
}
|
||||
if (PluginConstants.OperationCodes.SIMPLE_PASSWORD.
|
||||
equals(configure.name())) {
|
||||
if (passcodePolicy.isAllowSimple()) {
|
||||
addTag = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
targetTag.setLocURI(configure.getCode());
|
||||
MetaTag metaag = new MetaTag();
|
||||
metaag.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(targetTag);
|
||||
item.setMeta(metaag);
|
||||
item.setData(Constants.SyncMLResponseCodes.POSITIVE_CSP_DATA);
|
||||
itemList.add(item);
|
||||
addTag.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
addTag.setItems(itemList);
|
||||
|
||||
} else {
|
||||
addTag = new AddTag();
|
||||
List<ItemTag> itemList = new ArrayList<>();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag targetTag = new TargetTag();
|
||||
targetTag.setLocURI(configure.getCode());
|
||||
MetaTag metaag = new MetaTag();
|
||||
metaag.setFormat(Constants.META_FORMAT_INT);
|
||||
item.setTarget(targetTag);
|
||||
item.setMeta(metaag);
|
||||
item.setData(Constants.SyncMLResponseCodes.NEGATIVE_CSP_DATA);
|
||||
itemList.add(item);
|
||||
addTag.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
addTag.setItems(itemList);
|
||||
|
||||
}
|
||||
}
|
||||
return addTag;
|
||||
}
|
||||
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.SyncmlMessageFormatException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Generate security token to client and server.
|
||||
*/
|
||||
public class SyncmlCredentialUtil {
|
||||
|
||||
public static String generateCredData(String nextNonce) throws SyncmlMessageFormatException {
|
||||
MessageDigest digest;
|
||||
String usrPwdNonceHash;
|
||||
String nonce;
|
||||
try {
|
||||
nonce = new String(Base64.decodeBase64(nextNonce), Constants.UTF_8);
|
||||
digest = MessageDigest.getInstance(Constants.MD5);
|
||||
String usrPwd = Constants.PROVIDER_ID + ":" + Constants.SERVER_SECRET;
|
||||
String usrPwdHash = Base64.encodeBase64String(digest.digest(usrPwd.getBytes(Constants.UTF_8)));
|
||||
String usrPwdNonce = usrPwdHash + ":" + nonce;
|
||||
usrPwdNonceHash = Base64.encodeBase64String(digest.digest(usrPwdNonce.getBytes(Constants.UTF_8)));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new SyncmlMessageFormatException("Problem occurred while decoding credentials data.", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SyncmlMessageFormatException("Application environment does not have an implementation " +
|
||||
"available/configured for the requested algorithm", e);
|
||||
}
|
||||
return usrPwdNonceHash;
|
||||
}
|
||||
|
||||
public static String generateRST(String username, String password) throws SyncmlMessageFormatException {
|
||||
MessageDigest digest;
|
||||
String usrPwdNonceHash;
|
||||
String nonce;
|
||||
try {
|
||||
nonce = new String(Base64.decodeBase64(Constants.INITIAL_NONCE), Constants.UTF_8);
|
||||
digest = MessageDigest.getInstance(Constants.MD5);
|
||||
String usrPwd = username + ":" + password;
|
||||
String usrPwdHash = Base64.encodeBase64String(digest.digest(usrPwd.getBytes(Constants.UTF_8)));
|
||||
String usrPwdNonce = usrPwdHash + ":" + nonce;
|
||||
usrPwdNonceHash = Base64.encodeBase64String(digest.digest(usrPwdNonce.getBytes(Constants.UTF_8)));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new SyncmlMessageFormatException("Problem occurred while decoding credentials data.", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SyncmlMessageFormatException("Application environment does not have an implementation " +
|
||||
"available/configured for the requested algorithm", e);
|
||||
}
|
||||
return usrPwdNonceHash;
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.SyncmlOperationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlDocument;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlHeader;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlBody;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* Generates the response syncml xml file that should be sent to the Device.
|
||||
*/
|
||||
public class SyncmlGenerator {
|
||||
|
||||
public static String generatePayload(SyncmlDocument syncmlDocument) throws SyncmlOperationException {
|
||||
Document doc = generateDocument();
|
||||
Element rootElement = createRootElement(doc);
|
||||
SyncmlHeader header = syncmlDocument.getHeader();
|
||||
header.buildSyncmlHeaderElement(doc, rootElement);
|
||||
SyncmlBody body = syncmlDocument.getBody();
|
||||
body.buildBodyElement(doc, rootElement);
|
||||
return transformDocument(doc);
|
||||
}
|
||||
|
||||
public static Document generateDocument() throws SyncmlOperationException {
|
||||
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder;
|
||||
try {
|
||||
docBuilder = documentFactory.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new SyncmlOperationException("Error occurred while generating a new document of syncml", e);
|
||||
}
|
||||
return docBuilder.newDocument();
|
||||
}
|
||||
|
||||
private static Element createRootElement(Document document) {
|
||||
Element rootElement = document.createElementNS(Constants.XMLNS_SYNCML,
|
||||
Constants.SYNCML_ROOT_ELEMENT_NAME);
|
||||
document.appendChild(rootElement);
|
||||
return rootElement;
|
||||
}
|
||||
|
||||
private static String transformDocument(Document document) throws SyncmlOperationException {
|
||||
DOMSource domSource = new DOMSource(document);
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer;
|
||||
try {
|
||||
transformer = transformerFactory.newTransformer();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
throw new SyncmlOperationException("Error occurred while retrieving a new transformer", e);
|
||||
}
|
||||
transformer.setOutputProperty(OutputKeys.ENCODING, Constants.UTF_8);
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, Constants.YES);
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
StreamResult streamResult = new StreamResult(stringWriter);
|
||||
try {
|
||||
transformer.transform(domSource, streamResult);
|
||||
} catch (TransformerException e) {
|
||||
throw new SyncmlOperationException("Error occurred while transforming document to a string", e);
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
}
|
@ -1,496 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util;
|
||||
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.bean.EnterpriseApplication;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Parses the receiving SyncML payload and generates the SyncML document object from it.
|
||||
*/
|
||||
public class SyncmlParser {
|
||||
|
||||
private static String commandId;
|
||||
private static String messageReference;
|
||||
private static String commandReference;
|
||||
private static final String SYNC_HEADER = "SyncHdr";
|
||||
private static final String SYNC_BODY = "SyncBody";
|
||||
|
||||
private enum SyncMLHeaderParameter {
|
||||
MSG_ID("MsgID"),
|
||||
SESSION_ID("SessionID"),
|
||||
TARGET("Target"),
|
||||
SOURCE("Source"),
|
||||
CRED("Cred");
|
||||
private final String parameterName;
|
||||
|
||||
SyncMLHeaderParameter(final String parameterName) {
|
||||
this.parameterName = parameterName;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.parameterName;
|
||||
}
|
||||
}
|
||||
|
||||
private enum SycMLCommandType {
|
||||
ALERT("Alert"),
|
||||
REPLACE("Replace"),
|
||||
STATUS("Status"),
|
||||
RESULTS("Results");
|
||||
private final String commandName;
|
||||
|
||||
SycMLCommandType(final String commandName) {
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.commandName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the raw SyncML payload and generates a SyncmlDocument object using the parsed XML contents.
|
||||
*
|
||||
* @param syncmlPayload - Received SyncML XML payload
|
||||
* @return - SyncmlDocument object generated from the received payload
|
||||
*/
|
||||
public static SyncmlDocument parseSyncmlPayload(Document syncmlPayload) {
|
||||
SyncmlDocument syncmlDocument = new SyncmlDocument();
|
||||
if (syncmlPayload.getElementsByTagName(SYNC_HEADER) == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
NodeList syncHeaderList = syncmlPayload.getElementsByTagName(SYNC_HEADER);
|
||||
Node syncHeader = syncHeaderList.item(0);
|
||||
SyncmlHeader header = generateSyncmlHeader(syncHeader);
|
||||
if (syncmlPayload.getElementsByTagName(SYNC_BODY) == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
NodeList syncBodyList = syncmlPayload.getElementsByTagName(SYNC_BODY);
|
||||
Node syncBody = syncBodyList.item(0);
|
||||
SyncmlBody body = generateSyncmlBody(syncBody);
|
||||
|
||||
syncmlDocument.setHeader(header);
|
||||
syncmlDocument.setBody(body);
|
||||
return syncmlDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates SyncmlHeader object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param syncHeader - XML node which represents SyncML header
|
||||
* @return - SyncmlHeader object
|
||||
*/
|
||||
private static SyncmlHeader generateSyncmlHeader(Node syncHeader) {
|
||||
|
||||
String sessionID = null;
|
||||
String messageID = null;
|
||||
TargetTag target = null;
|
||||
SourceTag source = null;
|
||||
CredentialTag credential = null;
|
||||
SyncmlHeader header = new SyncmlHeader();
|
||||
|
||||
NodeList headerElements = syncHeader.getChildNodes();
|
||||
for (int i = 0; i < headerElements.getLength(); i++) {
|
||||
Node node = headerElements.item(i);
|
||||
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
String nodeName = node.getNodeName();
|
||||
|
||||
if (SyncMLHeaderParameter.MSG_ID.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
messageID = node.getTextContent().trim();
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.SESSION_ID.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
sessionID = node.getTextContent().trim();
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.TARGET.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
target = generateTarget(node);
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.SOURCE.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
source = generateSource(node);
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.CRED.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
credential = generateCredential(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
header.setMsgID(Integer.valueOf(messageID));
|
||||
// Syncml message contains a sessionID which is Hexadecimal value.Hexadecimal sessionID parse as a integer value.
|
||||
header.setSessionId(Integer.valueOf(sessionID, 16));
|
||||
header.setTarget(target);
|
||||
header.setSource(source);
|
||||
header.setCredential(credential);
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates SyncmlBody object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param syncBody - XML node which represents SyncML body
|
||||
* @return - SyncmlBody object
|
||||
*/
|
||||
private static SyncmlBody generateSyncmlBody(Node syncBody) {
|
||||
|
||||
AlertTag alert = null;
|
||||
ReplaceTag replace = null;
|
||||
ResultsTag results = null;
|
||||
List<StatusTag> status = new ArrayList<>();
|
||||
NodeList bodyElements = syncBody.getChildNodes();
|
||||
|
||||
for (int i = 0; i < bodyElements.getLength(); i++) {
|
||||
Node node = bodyElements.item(i);
|
||||
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
String nodeName = node.getNodeName();
|
||||
|
||||
if (SycMLCommandType.ALERT.getValue().equals(nodeName)) {
|
||||
alert = generateAlert(node);
|
||||
} else if (SycMLCommandType.REPLACE.getValue().equals(nodeName)) {
|
||||
replace = generateReplace(node);
|
||||
} else if (SycMLCommandType.STATUS.getValue().equals(nodeName)) {
|
||||
status.add(generateStatus(node));
|
||||
} else if (SycMLCommandType.RESULTS.getValue().equals(nodeName)) {
|
||||
results = generateResults(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
SyncmlBody body = new SyncmlBody();
|
||||
body.setAlert(alert);
|
||||
body.setReplace(replace);
|
||||
body.setStatus(status);
|
||||
body.setResults(results);
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Source object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Source
|
||||
* @return - Source object
|
||||
*/
|
||||
private static SourceTag generateSource(Node node) {
|
||||
|
||||
SourceTag source = new SourceTag();
|
||||
Node sourceURIItem = node.getChildNodes().item(0);
|
||||
Node sourceNameItem = node.getChildNodes().item(1);
|
||||
String sourceURI = null;
|
||||
String sourceName = null;
|
||||
|
||||
if (sourceURIItem != null) {
|
||||
sourceURI = sourceURIItem.getTextContent().trim();
|
||||
}
|
||||
if (sourceNameItem != null) {
|
||||
sourceName = sourceNameItem.getTextContent().trim();
|
||||
}
|
||||
source.setLocURI(sourceURI);
|
||||
source.setLocName(sourceName);
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Target object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Target
|
||||
* @return - Target object
|
||||
*/
|
||||
private static TargetTag generateTarget(Node node) {
|
||||
|
||||
TargetTag target = new TargetTag();
|
||||
Node targetURIItem = node.getChildNodes().item(0);
|
||||
Node targetNameItem = node.getChildNodes().item(1);
|
||||
String targetURI = null;
|
||||
String targetName = null;
|
||||
|
||||
if (targetURIItem != null) {
|
||||
targetURI = targetURIItem.getTextContent().trim();
|
||||
}
|
||||
if (targetNameItem != null) {
|
||||
targetName = targetNameItem.getTextContent().trim();
|
||||
}
|
||||
target.setLocURI(targetURI);
|
||||
target.setLocName(targetName);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Results object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Results
|
||||
* @return - Results object
|
||||
*/
|
||||
private static ResultsTag generateResults(Node node) {
|
||||
|
||||
ResultsTag results = new ResultsTag();
|
||||
List<ItemTag> item = new ArrayList<>();
|
||||
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
|
||||
NodeList nodelist = node.getChildNodes();
|
||||
|
||||
for (int i = 0; i < nodelist.getLength(); i++) {
|
||||
String nodeName = nodelist.item(i).getNodeName();
|
||||
|
||||
switch (nodeName) {
|
||||
case Constants.COMMAND_ID:
|
||||
commandId = node.getChildNodes().item(i).getTextContent().trim();
|
||||
break;
|
||||
case Constants.MESSAGE_REFERENCE:
|
||||
messageReference = node.getChildNodes().item(i).getTextContent().trim();
|
||||
break;
|
||||
case Constants.COMMAND_REFERENCE:
|
||||
commandReference = node.getChildNodes().item(i).getTextContent().trim();
|
||||
break;
|
||||
case Constants.ITEM:
|
||||
item.add(generateItem(node.getChildNodes().item(i)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
results.setCommandId(Integer.valueOf(commandId));
|
||||
results.setMessageReference(Integer.valueOf(messageReference));
|
||||
results.setCommandReference(Integer.valueOf(commandReference));
|
||||
results.setItem(item);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Status object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Status
|
||||
* @return - Status object
|
||||
*/
|
||||
private static StatusTag generateStatus(Node node) {
|
||||
|
||||
StatusTag status = new StatusTag();
|
||||
for (int x = 0; x < node.getChildNodes().getLength(); x++) {
|
||||
String nodeName = node.getChildNodes().item(x).getNodeName();
|
||||
switch (nodeName) {
|
||||
case PluginConstants.SyncML.SYNCML_CMD_ID:
|
||||
String commandId = node.getChildNodes().item(x).getTextContent().trim();
|
||||
status.setCommandId(Integer.valueOf(commandId));
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_MESSAGE_REF:
|
||||
String messageReference = node.getChildNodes().item(x).getTextContent().trim();
|
||||
status.setMessageReference(Integer.valueOf(messageReference));
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_CMD_REF:
|
||||
String commandReference = node.getChildNodes().item(x).getTextContent().trim();
|
||||
status.setCommandReference(Integer.valueOf(commandReference));
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_CMD:
|
||||
String command = node.getChildNodes().item(x).getTextContent().trim();
|
||||
status.setCommand(command);
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_CHAL:
|
||||
NodeList childNodes = node.getChildNodes().item(x).getChildNodes();
|
||||
MetaTag meta = new MetaTag();
|
||||
ChallengeTag challengeTag = new ChallengeTag();
|
||||
String format = childNodes.item(0).getFirstChild().getTextContent();
|
||||
meta.setFormat(format);
|
||||
String type = childNodes.item(0).getFirstChild().getNextSibling().getTextContent();
|
||||
meta.setType(type);
|
||||
String nonce = childNodes.item(0).getFirstChild().getNextSibling().getNextSibling().getTextContent();
|
||||
meta.setNextNonce(nonce);
|
||||
challengeTag.setMeta(meta);
|
||||
status.setChallenge(challengeTag);
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_DATA:
|
||||
String data = node.getChildNodes().item(x).getTextContent().trim();
|
||||
status.setData(data);
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_TARGET_REF:
|
||||
String targetReference = node.getChildNodes().item(x).getTextContent().trim();
|
||||
status.setTargetReference(targetReference);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Replace object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Replace
|
||||
* @return - Replace object
|
||||
*/
|
||||
private static ReplaceTag generateReplace(Node node) {
|
||||
|
||||
ReplaceTag replace = new ReplaceTag();
|
||||
String commandId = node.getChildNodes().item(0).getTextContent().trim();
|
||||
List<ItemTag> items = new ArrayList<>();
|
||||
for (int i = 0; i < node.getChildNodes().getLength() - 1; i++) {
|
||||
items.add(generateItem(node.getChildNodes().item(i + 1)));
|
||||
}
|
||||
replace.setCommandId(Integer.valueOf(commandId));
|
||||
replace.setItems(items);
|
||||
return replace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Alert object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Alert
|
||||
* @return - Alert object
|
||||
*/
|
||||
private static AlertTag generateAlert(Node node) {
|
||||
AlertTag alert = new AlertTag();
|
||||
String commandID = node.getChildNodes().item(0).getTextContent().trim();
|
||||
String data = node.getChildNodes().item(1).getTextContent().trim();
|
||||
List<ItemTag> items = new ArrayList<>();
|
||||
for (int i = 1; i < node.getChildNodes().getLength() - 1; i++) {
|
||||
items.add(generateItem(node.getChildNodes().item(i + 1)));
|
||||
}
|
||||
alert.setCommandId(Integer.valueOf(commandID));
|
||||
alert.setData(data);
|
||||
if (!items.isEmpty()) {
|
||||
alert.setItems(items);
|
||||
}
|
||||
return alert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Item object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Item
|
||||
* @return - Item object
|
||||
*/
|
||||
private static ItemTag generateItem(Node node) {
|
||||
ItemTag item = new ItemTag();
|
||||
SourceTag source = new SourceTag();
|
||||
String data;
|
||||
String nodeName;
|
||||
String childNodeName;
|
||||
String locUri;
|
||||
for (int x = 0; x < node.getChildNodes().getLength(); x++) {
|
||||
Node itemNode;
|
||||
itemNode = node.getChildNodes().item(x);
|
||||
if (itemNode.getNodeName() != null) {
|
||||
nodeName = node.getChildNodes().item(x).getNodeName();
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (PluginConstants.SyncML.SYNCML_SOURCE.equals(nodeName)) {
|
||||
if (itemNode.getChildNodes().item(x).getNodeName() != null) {
|
||||
childNodeName = itemNode.getChildNodes().item(x).getNodeName();
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if ((PluginConstants.SyncML.SYNCML_LOCATION_URI.equals(childNodeName))) {
|
||||
if (itemNode.getChildNodes().item(x).getTextContent().trim() != null) {
|
||||
locUri = itemNode.getChildNodes().item(x).getTextContent().trim();
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
source.setLocURI(locUri);
|
||||
item.setSource(source);
|
||||
}
|
||||
} else if (PluginConstants.SyncML.SYNCML_DATA.equals(nodeName)) {
|
||||
if (itemNode.getTextContent().trim() != null) {
|
||||
data = itemNode.getTextContent().trim();
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
item.setData(data);
|
||||
} else if (PluginConstants.SyncML.SYNCML_META.equals(nodeName)) {
|
||||
MetaTag metaTag = new MetaTag();
|
||||
if (itemNode.getChildNodes().item(0) != null) {
|
||||
metaTag.setType(itemNode.getChildNodes().item(0).getTextContent().trim());
|
||||
}
|
||||
if (itemNode.getChildNodes().item(1) != null) {
|
||||
metaTag.setFormat(itemNode.getChildNodes().item(1).getTextContent().trim());
|
||||
}
|
||||
item.setMeta(metaTag);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Credential object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents Credential
|
||||
* @return - Credential object
|
||||
*/
|
||||
private static CredentialTag generateCredential(Node node) {
|
||||
CredentialTag credential = new CredentialTag();
|
||||
MetaTag meta = generateMeta(node.getChildNodes().item(0));
|
||||
String data = node.getChildNodes().item(1).getTextContent().trim();
|
||||
credential.setMeta(meta);
|
||||
credential.setData(data);
|
||||
return credential;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates MetaTag object by extracting properties of passed XML node.
|
||||
*
|
||||
* @param node - XML node which represents MetaTag
|
||||
* @return - MetaTag object
|
||||
*/
|
||||
private static MetaTag generateMeta(Node node) {
|
||||
MetaTag meta = new MetaTag();
|
||||
String format = node.getChildNodes().item(0).getTextContent().trim();
|
||||
String type = node.getChildNodes().item(1).getTextContent().trim();
|
||||
meta.setFormat(format);
|
||||
meta.setType(type);
|
||||
return meta;
|
||||
}
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services;
|
||||
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.Tag;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.AuthorizationScope;
|
||||
import io.swagger.annotations.Authorization;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import io.swagger.annotations.ResponseHeader;
|
||||
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Windows Platform Configuration REST-API implementation.
|
||||
* All end points supports JSON, XMl with content negotiation.
|
||||
*/
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "Windows Configuration Management"),
|
||||
@ExtensionProperty(name = "context",
|
||||
value = "/api/device-mgt/windows/v1.0/configuration"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "windows,device_management", description = "")
|
||||
}
|
||||
)
|
||||
@Api(value = "Windows Configuration Management",
|
||||
description = "This carries all the resources related to Windows configurations management functionality")
|
||||
@WebService
|
||||
@Path("/configuration")
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Enroll Device",
|
||||
description = "Register an Windows device",
|
||||
key = "perm:windows:enroll",
|
||||
permissions = {"/device-mgt/devices/enroll/windows"}
|
||||
),
|
||||
@Scope(
|
||||
name = "View Configurations",
|
||||
description = "Getting Windows Platform Configurations",
|
||||
key = "perm:windows:view-configuration",
|
||||
permissions = {"/device-mgt/platform-configurations/view"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Manage Configurations",
|
||||
description = "Updating Windows Platform Configurations",
|
||||
key = "perm:windows:manage-configuration",
|
||||
permissions = {"/device-mgt/platform-configurations/manage"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public interface ConfigurationMgtService {
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting Windows Platform Configurations",
|
||||
notes = "Get the Windows platform configuration details using this REST API.",
|
||||
response = PlatformConfiguration.class,
|
||||
tags = "Windows Configuration Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:view-configuration")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched Windows platform configuration.",
|
||||
response = PlatformConfiguration.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Applications can be blacklisted via the application restriction policy too.."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n Th resource to be deleted does not exist."),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the Windows platform configuration.")
|
||||
})
|
||||
Response getConfiguration(@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Checks if the requested variant was modified, since the specified date-time.\n" +
|
||||
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
|
||||
"Example: Mon, 05 Jan 2014 15:10:00 +0200",
|
||||
required = false) @HeaderParam("If-Modified-Since") String ifModifiedSince);
|
||||
|
||||
/**
|
||||
* Update Tenant Configurations for the specific Device type.
|
||||
*
|
||||
* @param configuration Tenant configurations to be updated.
|
||||
* @return Response message.
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@PUT
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Updating Windows Platform Configurations",
|
||||
notes = "Update the Windows platform configurations using this REST API.",
|
||||
tags = "Windows Configuration Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:manage-configuration")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully updated the Windows platform configurations.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the updated Windows platform configuration."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified resource does not exist."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while modifying the Windows platform configurations.")
|
||||
})
|
||||
Response updateConfiguration
|
||||
(@ApiParam(
|
||||
name = "configuration",
|
||||
value = "The properties to update the Windows platform configurations.")
|
||||
PlatformConfiguration configuration) throws WindowsConfigurationException;
|
||||
|
||||
@GET
|
||||
@Path("license")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@ApiOperation(
|
||||
produces = MediaType.TEXT_PLAIN,
|
||||
httpMethod = "GET",
|
||||
value = "Getting the License Agreement to Register a Windows Device",
|
||||
notes = "Use this REST API to retrieve the license agreement that is used for the Windows device " +
|
||||
"registration process.",
|
||||
response = String.class,
|
||||
tags = "Windows Configuration Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:enroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched Windows license configuration.",
|
||||
response = String.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified resource does not exist."),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the Windows license configuration.")
|
||||
})
|
||||
Response getLicense(
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Checks if the requested variant was modified, since the specified date-time.\n" +
|
||||
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
|
||||
"Example: Mon, 05 Jan 2014 15:10:00 +0200.",
|
||||
required = false)
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) throws WindowsConfigurationException;
|
||||
|
||||
}
|
@ -1,624 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.bean.wrapper.EnterpriseApplicationBeanWrapper;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for Admin operations persisting. This interface accepts operations added via UI.
|
||||
*/
|
||||
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name",
|
||||
value = "Windows Device Management Administrative Service"),
|
||||
@ExtensionProperty(name = "context",
|
||||
value = "/api/device-mgt/windows/v1.0/admin/devices"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "windows,device_management", description = "")
|
||||
}
|
||||
)
|
||||
@Api(value = "Windows Device Management Administrative Service",
|
||||
description = "Device management related admin APIs.")
|
||||
@WebService
|
||||
@Path("/admin/devices")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Lock Device",
|
||||
description = "Adding a Device Lock on Windows devices.",
|
||||
key = "perm:windows:lock-devices",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/lock"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Un-enroll Device",
|
||||
description = "Unregister an Windows device",
|
||||
key = "perm:windows:disenroll",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/disenroll"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Factory Reset",
|
||||
description = "Factory Resetting Windows Devices",
|
||||
key = "perm:windows:wipe",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/wipe"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Ring Device",
|
||||
description = "Ring Windows devices",
|
||||
key = "perm:windows:ring",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/ring"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Lock Reset",
|
||||
description = "Lock reset on Windows devices",
|
||||
key = "perm:windows:lock-reset",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/lock-reset"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Reboot",
|
||||
description = "Lock reset on Windows devices",
|
||||
key = "perm:windows:reboot",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/reboot"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Device Location",
|
||||
description = "Lock reset on Windows devices",
|
||||
key = "perm:windows:location",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/location"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Install Enterprise Application",
|
||||
description = "Installing an Enterprise Application",
|
||||
key = "perm:windows:enterprise-app",
|
||||
permissions = {"/device-mgt/devices/owning-device/operations/windows/enterprise-application"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public interface DeviceManagementAdminService {
|
||||
|
||||
@POST
|
||||
@Path("/lock-devices")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Adding a Device Lock on Windows devices.",
|
||||
notes = "Using this API you have the option of Device Windows device.",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:lock-devices")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully scheduled the device lock operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified. \n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported.\n"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while locking the device.")
|
||||
})
|
||||
Response lock(@HeaderParam("Accept") String headerParam, @ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the AWindows device. Multiple device IDs can be added by " +
|
||||
"using comma separated values. ",
|
||||
required = true) List<String> deviceIds) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/disenroll-devices")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Dis-enrol the windows Devices",
|
||||
notes = "Dis-enroll on Android devices",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:disenroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully scheduled the Dis-enroll operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding a Dis-enroll operation.")
|
||||
})
|
||||
Response disenroll(@HeaderParam("Accept") String headerParam, @ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the A Windows device. Multiple device IDs can be added by " +
|
||||
"using comma separated values. ",
|
||||
required = true) List<String> deviceIds) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/wipe-devices")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Factory Resetting an Windows Device",
|
||||
notes = "Factory rest or erase all the data stored on the Windows devices" +
|
||||
"to restore them back to the original system.",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:wipe")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully scheduled the Data wipe operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified." +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding the Data wipe operation.")})
|
||||
Response wipe(@HeaderParam("Accept") String headerParam, @ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the A Windows device. Multiple device IDs can be added by " +
|
||||
"using comma separated values. ",
|
||||
required = true) List<String> deviceIds) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/ring-devices")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Ringing Windows Devices",
|
||||
notes = "Ring Windows devices.",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:ring")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully scheduled the device ring operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported.\n"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding a new device ring operation.")
|
||||
})
|
||||
Response ring(@HeaderParam("Accept") String headerParam, @ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the A Windows device. Multiple device IDs can be added by " +
|
||||
"using comma separated values. ",
|
||||
required = true) List<String> deviceIds) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/lock-reset-devices")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Lock reset on Windows devices",
|
||||
notes = "Lock reset on Windows devices.Its use to reset the device pass code",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:lock-reset")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully scheduled the lock-reset operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding adding a lock-reset operation.")
|
||||
})
|
||||
Response lockReset(@HeaderParam("Accept") String acceptHeader, @ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the A Windows device. Multiple device IDs can be added by " +
|
||||
"using comma separated values. ",
|
||||
required = true) List<String> deviceIds) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/location")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Requesting Location Coordinates",
|
||||
responseContainer = "List",
|
||||
notes = "Request location coordinates of Windows devices. \n" +
|
||||
"Example: In situations where you have lost your device and need to find out where it is, " +
|
||||
"you can use this REST API to get the location of the device.",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:location")
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Get-location operation has successfully been scheduled",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the " +
|
||||
"scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the" +
|
||||
" location header.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding a new get-location operation.")})
|
||||
Response getDeviceLocation(
|
||||
@ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the Windows device. Multiple device IDs can be added by " +
|
||||
"using comma separated values. ",
|
||||
required = true)
|
||||
List<String> deviceIDs);
|
||||
|
||||
@POST
|
||||
@Path("/reboot")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Rebooting Windows Devices",
|
||||
notes = "Reboot or restart your Windows devices.",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:reboot")
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully scheduled the device reboot operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported.\n"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding the new device reboot operation.")
|
||||
})
|
||||
Response rebootDevice(
|
||||
@ApiParam(
|
||||
name = "deviceIDs",
|
||||
value = "Provide the ID of the Android device. Multiple device IDs can be added using comma separated values. ",
|
||||
required = true)
|
||||
List<String> deviceIDs);
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/enterprise-application")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Installing an Enterprise Application",
|
||||
notes = "Install an enterprise application on Windows devices.",
|
||||
response = Activity.class,
|
||||
tags = "Windows Device Management Administrative Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:enterprise-app")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully added Enterprise application operation.",
|
||||
response = Activity.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "URL of the activity instance that refers to the scheduled operation."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "Content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported.\n"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while adding the enterprise application operation.")
|
||||
})
|
||||
Response installEnterpriseApplication(
|
||||
@ApiParam(
|
||||
name = "enterpriseApplicationBeanWrapper",
|
||||
value = "Enterprise application configuration and Device IDs",
|
||||
required = true)
|
||||
EnterpriseApplicationBeanWrapper enterpriseApplicationBeanWrapper);
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.WindowsOperationException;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
|
||||
/**
|
||||
* Interface for Windows 10 Device management phase.
|
||||
*/
|
||||
@Path("/devicemgt")
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Pending operations",
|
||||
description = "Register an Windows device",
|
||||
key = "perm:windows:enroll",
|
||||
permissions = {"/device-mgt/devices/enroll/windows"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public interface DeviceManagementService {
|
||||
@Path("/pending-operations")
|
||||
@POST
|
||||
@Consumes({PluginConstants.SYNCML_MEDIA_TYPE, MediaType.APPLICATION_XML})
|
||||
@Produces(PluginConstants.SYNCML_MEDIA_TYPE)
|
||||
Response getResponse(Document request) throws WindowsDeviceEnrolmentException, WindowsOperationException,
|
||||
NotificationManagementException, WindowsConfigurationException;
|
||||
|
||||
}
|
||||
|
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.Constants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst.beans.Credentials;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Interface for handling authentication request comes via MDM login page.
|
||||
*/
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "Windows Binary Security Token Service"),
|
||||
@ExtensionProperty(name = "context",
|
||||
value = "/api/device-mgt/windows/v1.0/federated"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "windows,device_management", description = "")
|
||||
}
|
||||
)
|
||||
@Api(value = "Windows Binary Security Token Service",
|
||||
description = "This carries all the resources related to Windows Binary security token management.")
|
||||
@WebService
|
||||
@Path("/bst")
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Enroll Device",
|
||||
description = "Register Windows device",
|
||||
key = "perm:windows:enroll",
|
||||
permissions = {"/device-mgt/devices/enroll/windows"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public interface BSTProvider {
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/authentication")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Getting Binary security token.",
|
||||
notes = "Using this API to fetch Binary security token to call window enrollment and policy endpoints.",
|
||||
tags = "BST Provider",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:windows:enroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(code = 200, message = "Ok. \n Successfully fetching the binary security token.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The URL of the added policy."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests.")
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while fetching Binary security token.")
|
||||
})
|
||||
Response getBST(Credentials credentials)
|
||||
throws WindowsDeviceEnrolmentException;
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* This bean class is for credentials coming from wab page at federated authentication step.
|
||||
*/
|
||||
@XmlRootElement(name = "credentials")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class Credentials {
|
||||
|
||||
@XmlElement(required = true, name = "username")
|
||||
private String username;
|
||||
@XmlElement(required = true, name = "email")
|
||||
private String email;
|
||||
@XmlElement(required = true, name = "password")
|
||||
private String password;
|
||||
@XmlElement(required = true, name = "ownership")
|
||||
private String ownership;
|
||||
@XmlElement(required = true, name = "token")
|
||||
private String usertoken;
|
||||
|
||||
public Credentials() {
|
||||
|
||||
}
|
||||
|
||||
public String getUsertoken() {
|
||||
return usertoken;
|
||||
}
|
||||
|
||||
public void setUsertoken(String usertoken) {
|
||||
this.usertoken = usertoken;
|
||||
}
|
||||
|
||||
public String getOwnership() {
|
||||
return ownership;
|
||||
}
|
||||
|
||||
public void setOwnership(String ownership) {
|
||||
this.ownership = ownership;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst.impl;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.Token;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.AuthenticationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.DeviceUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst.BSTProvider;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.authbst.beans.Credentials;
|
||||
import org.wso2.carbon.user.api.UserRealm;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Implementation class of BSTProvider interface which authenticates the credentials comes via MDM login page.
|
||||
*/
|
||||
public class BSTProviderImpl implements BSTProvider {
|
||||
|
||||
/**
|
||||
* This method validates the device user, checking passed credentials and returns the corresponding
|
||||
* binary security token which is used in XCEP and WSTEP stages for authentication.
|
||||
*
|
||||
* @param credentials - Credential object passes from the wab page.
|
||||
* @return - Response with binary security token.
|
||||
*/
|
||||
@Override
|
||||
public Response getBST(Credentials credentials) throws WindowsDeviceEnrolmentException {
|
||||
|
||||
String domainUser = credentials.getUsername();
|
||||
String userToken = credentials.getUsertoken();
|
||||
String encodedToken;
|
||||
try {
|
||||
Token tokenBean = new Token();
|
||||
tokenBean.setChallengeToken(userToken);
|
||||
Base64 base64 = new Base64();
|
||||
encodedToken = base64.encodeToString(userToken.getBytes());
|
||||
DeviceUtil.persistChallengeToken(encodedToken, null, domainUser);
|
||||
JSONObject tokenContent = new JSONObject();
|
||||
tokenContent.put("UserToken", userToken);
|
||||
return Response.ok().entity(tokenContent.toString()).build();
|
||||
} catch (JSONException e) {
|
||||
throw new WindowsDeviceEnrolmentException(
|
||||
"Failure occurred in generating Json payload for challenge token.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method authenticate the user checking the carbon default user store.
|
||||
*
|
||||
* @param username - Username in username token
|
||||
* @param password - Password in username token
|
||||
* @param tenantDomain - Tenant domain is extracted from the username
|
||||
* @return - Returns boolean representing authentication result
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
private boolean authenticate(String username, String password, String tenantDomain) throws
|
||||
AuthenticationException {
|
||||
|
||||
try {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||
|
||||
if (realmService == null) {
|
||||
throw new AuthenticationException("RealmService not initialized.");
|
||||
}
|
||||
|
||||
int tenantId;
|
||||
if (tenantDomain == null || tenantDomain.trim().isEmpty()) {
|
||||
tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
||||
} else {
|
||||
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
|
||||
}
|
||||
|
||||
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
|
||||
throw new AuthenticationException("Invalid tenant domain " + tenantDomain);
|
||||
}
|
||||
UserRealm userRealm = realmService.getTenantUserRealm(tenantId);
|
||||
|
||||
return userRealm.getUserStoreManager().authenticate(username, password);
|
||||
} catch (UserStoreException e) {
|
||||
throw new AuthenticationException("User store is not initialized.", e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans.DiscoveryRequest;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans.DiscoveryResponse;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.RequestWrapper;
|
||||
import javax.xml.ws.ResponseWrapper;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
|
||||
/**
|
||||
* Interface for Discovery service related operations.
|
||||
*/
|
||||
|
||||
@WebService(targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE,
|
||||
name = "IDiscoveryService")
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public interface DiscoveryService {
|
||||
@POST
|
||||
|
||||
@RequestWrapper(localName = "Discover", targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE)
|
||||
@WebMethod(operationName = "Discover")
|
||||
@ResponseWrapper(localName = "DiscoverResponse", targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE)
|
||||
void discover(
|
||||
@WebParam(name = "request", targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE)
|
||||
DiscoveryRequest request,
|
||||
@WebParam(mode = WebParam.Mode.OUT, name = "DiscoverResult",
|
||||
targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE)
|
||||
javax.xml.ws.Holder<DiscoveryResponse> response
|
||||
) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "DiscoveryRequest", namespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
@SuppressWarnings("unused")
|
||||
public class DiscoveryRequest implements Serializable {
|
||||
|
||||
@XmlElement(name = "EmailAddress", required = true)
|
||||
private String emailId;
|
||||
|
||||
@XmlElement(name = "RequestVersion")
|
||||
private String version;
|
||||
|
||||
@XmlElement(name = "DeviceType")
|
||||
private String deviceType;
|
||||
|
||||
@XmlElement(name = "OSEdition")
|
||||
private String osEdition;
|
||||
|
||||
@XmlElement(name = "ApplicationVersion")
|
||||
private String applicationVersion;
|
||||
|
||||
@XmlElementWrapper(name = "AuthPolicies")
|
||||
@XmlElement(name = "AuthPolicy", required = true)
|
||||
private List<String> authenticationPolicies;
|
||||
|
||||
public String getEmailId() {
|
||||
return emailId;
|
||||
}
|
||||
|
||||
public void setEmailId(String emailId) {
|
||||
this.emailId = emailId;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public List<String> getAuthenticationPolicies() {
|
||||
return authenticationPolicies;
|
||||
}
|
||||
|
||||
public void setAuthenticationPolicies(List<String> authenticationPolicies) {
|
||||
this.authenticationPolicies = authenticationPolicies;
|
||||
}
|
||||
|
||||
public String getOsEdition() {
|
||||
return osEdition;
|
||||
}
|
||||
|
||||
public void setOsEdition(String osEdition) {
|
||||
this.osEdition = osEdition;
|
||||
}
|
||||
|
||||
public String getApplicationVersion() {
|
||||
return applicationVersion;
|
||||
}
|
||||
|
||||
public void setApplicationVersion(String applicationVersion) {
|
||||
this.applicationVersion = applicationVersion;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import java.io.Serializable;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "DiscoveryResponse")
|
||||
@SuppressWarnings("unused")
|
||||
public class DiscoveryResponse implements Serializable {
|
||||
|
||||
@XmlElement(name = "AuthPolicy")
|
||||
private String authPolicy;
|
||||
|
||||
@XmlElement(name = "EnrollmentPolicyServiceUrl")
|
||||
private String enrollmentPolicyServiceUrl;
|
||||
|
||||
@XmlElement(name = "EnrollmentServiceUrl")
|
||||
private String enrollmentServiceUrl;
|
||||
|
||||
@XmlElement(name = "AuthenticationServiceUrl")
|
||||
private String authenticationServiceUrl;
|
||||
|
||||
@XmlElement(name = "EnrollmentVersion")
|
||||
private String enrollmentVersion;
|
||||
|
||||
public void setAuthenticationServiceUrl(String authenticationServiceUrl) {
|
||||
this.authenticationServiceUrl = authenticationServiceUrl;
|
||||
}
|
||||
|
||||
public String getAuthenticationServiceUrl() {
|
||||
return authenticationServiceUrl;
|
||||
}
|
||||
|
||||
public String getAuthPolicy() {
|
||||
return authPolicy;
|
||||
}
|
||||
|
||||
public String getEnrollmentPolicyServiceUrl() {
|
||||
return enrollmentPolicyServiceUrl;
|
||||
}
|
||||
|
||||
public String getEnrollmentServiceUrl() {
|
||||
return enrollmentServiceUrl;
|
||||
}
|
||||
|
||||
public void setAuthPolicy(String authPolicy) {
|
||||
this.authPolicy = authPolicy;
|
||||
}
|
||||
|
||||
public void setEnrollmentPolicyServiceUrl(String enrollmentPolicyServiceUrl) {
|
||||
this.enrollmentPolicyServiceUrl = enrollmentPolicyServiceUrl;
|
||||
}
|
||||
|
||||
public void setEnrollmentServiceUrl(String enrollmentServiceUrl) {
|
||||
this.enrollmentServiceUrl = enrollmentServiceUrl;
|
||||
}
|
||||
|
||||
public String getEnrollmentVersion() {
|
||||
return enrollmentVersion;
|
||||
}
|
||||
|
||||
public void setEnrollmentVersion(String enrollmentVersion) {
|
||||
this.enrollmentVersion = enrollmentVersion;
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@javax.xml.bind.annotation.XmlSchema(namespace =
|
||||
"http://schemas.microsoft.com/windows/management/2012/01/enrollment",
|
||||
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans;
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.DiscoveryService;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans.DiscoveryRequest;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.beans.DiscoveryResponse;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.Holder;
|
||||
import javax.xml.ws.soap.Addressing;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation class of Discovery Request. This class implements the first two services
|
||||
* of device enrolment stage.
|
||||
*/
|
||||
@WebService(endpointInterface = PluginConstants.DISCOVERY_SERVICE_ENDPOINT, targetNamespace = PluginConstants
|
||||
.DISCOVERY_SERVICE_TARGET_NAMESPACE)
|
||||
@Addressing(enabled = true, required = true)
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public class DiscoveryServiceImpl implements DiscoveryService {
|
||||
|
||||
public static final String FEDERATED = "Federated";
|
||||
private static final String DELIMITER = "@";
|
||||
private static Log log = LogFactory.getLog(
|
||||
org.wso2.carbon.device.mgt.mobile.windows.api.services.discovery.impl.DiscoveryServiceImpl.class);
|
||||
|
||||
/**
|
||||
* This method returns the OnPremise AuthPolicy and next two endpoint the mobile device should
|
||||
* call if this response to received successfully at the device end. This method is called by
|
||||
* device immediately after the first GET method calling for the same endpoint.
|
||||
*
|
||||
* @param discoveryRequest - Request bean comes via mobile phone
|
||||
* @param response - DiscoveryResponse bean for response
|
||||
*/
|
||||
@Override
|
||||
public void discover(DiscoveryRequest discoveryRequest, Holder<DiscoveryResponse> response)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
|
||||
String emailId = discoveryRequest.getEmailId();
|
||||
String[] userDomains = emailId.split(DELIMITER);
|
||||
String domain = userDomains[(userDomains.length)-1];
|
||||
DiscoveryResponse discoveryResponse;
|
||||
|
||||
if (!PluginConstants.WindowsVersionProperties.REQUESTED_WIN81_VERSION.equals(discoveryRequest.getVersion())
|
||||
&& FEDERATED.equals(getAuthPolicy())) {
|
||||
discoveryResponse = new DiscoveryResponse();
|
||||
discoveryResponse.setAuthPolicy(FEDERATED);
|
||||
discoveryResponse.setEnrollmentVersion(PluginConstants.WindowsVersionProperties.REQUESTED_WIN10_VERSION);
|
||||
discoveryResponse.setEnrollmentPolicyServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.
|
||||
CERTIFICATE_ENROLLMENT_POLICY_SERVICE_URL);
|
||||
discoveryResponse.setEnrollmentServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.
|
||||
ENROLLMENT_SERVICE_URL);
|
||||
discoveryResponse.setAuthenticationServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.WAB_URL);
|
||||
} else {
|
||||
discoveryResponse = new DiscoveryResponse();
|
||||
discoveryResponse.setAuthPolicy(FEDERATED);
|
||||
discoveryResponse.setEnrollmentPolicyServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.
|
||||
CERTIFICATE_ENROLLMENT_POLICY_SERVICE_URL);
|
||||
discoveryResponse.setEnrollmentServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.
|
||||
CERTIFICATE_ENROLLMENT_SERVICE_URL);
|
||||
discoveryResponse.setAuthenticationServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.WAB_URL);
|
||||
}
|
||||
response.value = discoveryResponse;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Discovery service end point was triggered via POST method");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authentication policy from the tenant configuration, otherwise set default value as Federated.
|
||||
*
|
||||
* @return Authentication policy.
|
||||
* @throws WindowsDeviceEnrolmentException
|
||||
*/
|
||||
public String getAuthPolicy() throws WindowsDeviceEnrolmentException {
|
||||
String authPolicy = null;
|
||||
List<ConfigurationEntry> tenantConfigurations;
|
||||
try {
|
||||
if (WindowsAPIUtils.getTenantConfigurationData() != null) {
|
||||
tenantConfigurations = WindowsAPIUtils.getTenantConfigurationData();
|
||||
|
||||
for (ConfigurationEntry configurationEntry : tenantConfigurations) {
|
||||
if (PluginConstants.TenantConfigProperties.AUTH_POLICY.equals(configurationEntry.getName())) {
|
||||
authPolicy = configurationEntry.getValue().toString();
|
||||
} else {
|
||||
authPolicy = PluginConstants.TenantConfigProperties.DEFAULT_AUTH_POLICY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
authPolicy = PluginConstants.TenantConfigProperties.DEFAULT_AUTH_POLICY;
|
||||
String msg = "Tenant configurations are not initialized yet.";
|
||||
log.error(msg);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while getting tenant configurations.";
|
||||
log.error(msg);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
}
|
||||
return authPolicy;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WAPProvisioningException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.AdditionalContext;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.RequestSecurityTokenResponse;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.RequestWrapper;
|
||||
import javax.xml.ws.ResponseWrapper;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@WebService(targetNamespace = PluginConstants.DEVICE_ENROLLMENT_SERVICE_TARGET_NAMESPACE, name = "enrollment")
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public interface EnrollmentService {
|
||||
|
||||
@RequestWrapper(localName = "RequestSecurityToken", targetNamespace = PluginConstants
|
||||
.WS_TRUST_TARGET_NAMESPACE)
|
||||
@WebMethod(operationName = "RequestSecurityToken")
|
||||
@ResponseWrapper(localName = "RequestSecurityTokenResponseCollection", targetNamespace =
|
||||
PluginConstants.WS_TRUST_TARGET_NAMESPACE)
|
||||
@POST
|
||||
void requestSecurityToken(
|
||||
@WebParam(name = "TokenType", targetNamespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE)
|
||||
String tokenType,
|
||||
@WebParam(name = "RequestType", targetNamespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE)
|
||||
String requestType,
|
||||
@WebParam(name = "BinarySecurityToken", targetNamespace = PluginConstants
|
||||
.WS_SECURITY_TARGET_NAMESPACE)
|
||||
String binarySecurityToken,
|
||||
@WebParam(name = "AdditionalContext", targetNamespace = PluginConstants
|
||||
.SOAP_AUTHORIZATION_TARGET_NAMESPACE)
|
||||
AdditionalContext additionalContext,
|
||||
@WebParam(mode = WebParam.Mode.OUT, name = "RequestSecurityTokenResponse",
|
||||
targetNamespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE)
|
||||
javax.xml.ws.Holder<RequestSecurityTokenResponse> response) throws
|
||||
WindowsDeviceEnrolmentException, UnsupportedEncodingException,
|
||||
WAPProvisioningException;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "OIDCollection", namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE,
|
||||
propOrder = {"contextitem"})
|
||||
@SuppressWarnings("unused")
|
||||
public class AdditionalContext {
|
||||
|
||||
@XmlElement(name = "ContextItem", required = true,
|
||||
namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE)
|
||||
|
||||
protected List<ContextItem> contextitem;
|
||||
|
||||
public List<ContextItem> getcontextitem() {
|
||||
if (contextitem == null) {
|
||||
contextitem = new ArrayList<ContextItem>();
|
||||
}
|
||||
return this.contextitem;
|
||||
}
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "BinarySecurityToken", namespace = PluginConstants.WS_SECURITY_TARGET_NAMESPACE,
|
||||
propOrder = {"ValueType", "EncodingType"})
|
||||
@SuppressWarnings("unused")
|
||||
public class BinarySecurityToken {
|
||||
|
||||
@XmlAttribute(name = "ValueType")
|
||||
protected String ValueType;
|
||||
@XmlAttribute(name = "EncodingType")
|
||||
protected String EncodingType;
|
||||
@XmlValue
|
||||
protected String Token;
|
||||
|
||||
public void setValueType(String valuetype) {
|
||||
this.ValueType = valuetype;
|
||||
}
|
||||
|
||||
public String getValueType() {
|
||||
return this.ValueType;
|
||||
}
|
||||
|
||||
public void setEncodingType(String encodingtype) {
|
||||
this.EncodingType = encodingtype;
|
||||
}
|
||||
|
||||
public String getEncodingType() {
|
||||
return this.EncodingType;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.Token = token;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return this.Token;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "ContextItem", namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE,
|
||||
propOrder = {"Value"})
|
||||
public class ContextItem {
|
||||
|
||||
@XmlAttribute(name = "Name")
|
||||
protected String Name;
|
||||
@XmlElement(name = "Value", required = true,
|
||||
namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE)
|
||||
protected String Value;
|
||||
|
||||
public String getValue() {
|
||||
return Value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "RequestedSecurityToken", namespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE,
|
||||
propOrder = {"binarySecurityToken"})
|
||||
@SuppressWarnings("unused")
|
||||
public class RequestSecurityToken {
|
||||
|
||||
@XmlElement(name = "BinarySecurityToken", required = true,
|
||||
namespace = PluginConstants.WS_SECURITY_TARGET_NAMESPACE)
|
||||
|
||||
protected BinarySecurityToken binarySecurityToken;
|
||||
|
||||
public void setBinarySecurityToken(BinarySecurityToken binarysecuritytoken) {
|
||||
this.binarySecurityToken = binarysecuritytoken;
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import java.io.Serializable;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "RequestSecurityTokenResponse", namespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE,
|
||||
propOrder = {"TokenType", "DispositionMessage", "RequestedSecurityToken", "RequestID"})
|
||||
@SuppressWarnings("unused")
|
||||
public class RequestSecurityTokenResponse implements Serializable {
|
||||
|
||||
@XmlElement(name = "TokenType", namespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE)
|
||||
private String TokenType;
|
||||
|
||||
// Windows 10 property
|
||||
@XmlElement(name = "DispositionMessage", namespace = PluginConstants.ENROLLMENT_POLICY_TARGET_NAMESPACE)
|
||||
private String DispositionMessage;
|
||||
|
||||
@XmlElement(name = "RequestedSecurityToken", required = true,
|
||||
namespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE)
|
||||
private org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.RequestedSecurityToken RequestedSecurityToken;
|
||||
|
||||
@XmlElement(name = "RequestID", namespace = PluginConstants.ENROLLMENT_POLICY_TARGET_NAMESPACE)
|
||||
private int RequestID;
|
||||
|
||||
public String getTokenType() {
|
||||
return TokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(String tokenType) {
|
||||
TokenType = tokenType;
|
||||
}
|
||||
|
||||
public org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.RequestedSecurityToken getRequestedSecurityToken() {
|
||||
return RequestedSecurityToken;
|
||||
}
|
||||
|
||||
public void setRequestedSecurityToken(org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.RequestedSecurityToken
|
||||
requestedSecurityToken) {
|
||||
RequestedSecurityToken = requestedSecurityToken;
|
||||
}
|
||||
|
||||
public int getRequestID() {
|
||||
return RequestID;
|
||||
}
|
||||
|
||||
public void setRequestID(int requestID) {
|
||||
RequestID = requestID;
|
||||
}
|
||||
|
||||
public String getDispositionMessage() {
|
||||
return DispositionMessage;
|
||||
}
|
||||
|
||||
public void setDispositionMessage(String dispositionMessage) {
|
||||
DispositionMessage = dispositionMessage;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "RequestedSecurityToken", namespace = PluginConstants.WS_TRUST_TARGET_NAMESPACE,
|
||||
propOrder = {"binarySecurityToken"})
|
||||
public class RequestedSecurityToken {
|
||||
|
||||
@XmlElement(name = "BinarySecurityToken", required = true,
|
||||
namespace = PluginConstants.WS_SECURITY_TARGET_NAMESPACE)
|
||||
|
||||
protected BinarySecurityToken binarySecurityToken;
|
||||
|
||||
public void setBinarySecurityToken(BinarySecurityToken binarysecuritytoken) {
|
||||
this.binarySecurityToken = binarysecuritytoken;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@XmlSchema(namespace = "http://www.w3.org/2003/05/soap-envelope",
|
||||
xmlns = {
|
||||
@XmlNs(prefix = "", namespaceURI = "http://www.w3.org/2003/05/soap-envelope")
|
||||
}, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNs;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
@ -1,451 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.cxf.headers.Header;
|
||||
import org.apache.cxf.helpers.CastUtils;
|
||||
import org.apache.cxf.jaxws.context.WrappedMessageContext;
|
||||
import org.apache.cxf.message.Message;
|
||||
import org.w3c.dom.*;
|
||||
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.CertificateGenerationException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.SyncmlMessageFormatException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WAPProvisioningException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.DeviceUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.SyncmlCredentialUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.EnrollmentService;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.*;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.WindowsDevice;
|
||||
import org.wso2.carbon.device.mgt.mobile.windows.impl.dto.MobileCacheEntry;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.jws.WebService;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.Holder;
|
||||
import javax.xml.ws.WebServiceContext;
|
||||
import javax.xml.ws.handler.MessageContext;
|
||||
import javax.xml.ws.soap.Addressing;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation class of Windows10 Enrollment process.
|
||||
*/
|
||||
@WebService(endpointInterface = PluginConstants.ENROLLMENT_SERVICE_ENDPOINT,
|
||||
targetNamespace = PluginConstants.DEVICE_ENROLLMENT_SERVICE_TARGET_NAMESPACE)
|
||||
@Addressing(enabled = true, required = true)
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public class EnrollmentServiceImpl implements EnrollmentService {
|
||||
private static Log log = LogFactory.getLog(EnrollmentServiceImpl.class);
|
||||
private String pollingFrequency;
|
||||
private String provisioningURL;
|
||||
private String domain;
|
||||
|
||||
@Resource
|
||||
private WebServiceContext context;
|
||||
|
||||
@Override
|
||||
public void requestSecurityToken(String tokenType, String requestType, String binarySecurityToken,
|
||||
AdditionalContext additionalContext,
|
||||
Holder<RequestSecurityTokenResponse> response)
|
||||
throws WindowsDeviceEnrolmentException, UnsupportedEncodingException, WAPProvisioningException {
|
||||
String headerBinarySecurityToken = null;
|
||||
String headerTo = null;
|
||||
String encodedWap;
|
||||
List<Header> headers = getHeaders();
|
||||
for (Header headerElement : headers) {
|
||||
String nodeName = headerElement.getName().getLocalPart();
|
||||
if (PluginConstants.SECURITY.equals(nodeName)) {
|
||||
Element element = (Element) headerElement.getObject();
|
||||
headerBinarySecurityToken = element.getFirstChild().getFirstChild().getTextContent();
|
||||
}
|
||||
if (PluginConstants.TO.equals(nodeName)) {
|
||||
Element toElement = (Element) headerElement.getObject();
|
||||
headerTo = toElement.getFirstChild().getTextContent();
|
||||
}
|
||||
}
|
||||
try {
|
||||
enrollDevice(additionalContext, headerBinarySecurityToken);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new WindowsDeviceEnrolmentException("Error occurred while enrolling the device.");
|
||||
} catch (PolicyManagementException e) {
|
||||
throw new WindowsDeviceEnrolmentException("Error occurred while enforcing windows policies.");
|
||||
}
|
||||
String[] splitEmail = headerTo.split("(/ENROLLMENTSERVER)");
|
||||
String email = splitEmail[PluginConstants.CertificateEnrolment.EMAIL_SEGMENT];
|
||||
|
||||
String[] splitDomain = email.split("(EnterpriseEnrollment.)");
|
||||
domain = splitDomain[PluginConstants.CertificateEnrolment.DOMAIN_SEGMENT];
|
||||
provisioningURL = PluginConstants.CertificateEnrolment.ENROLL_SUBDOMAIN + domain +
|
||||
PluginConstants.CertificateEnrolment.SYNCML_PROVISIONING_WIN10_SERVICE_URL;
|
||||
|
||||
List<ConfigurationEntry> tenantConfigurations;
|
||||
try {
|
||||
if ((tenantConfigurations = WindowsAPIUtils.getTenantConfigurationData()) != null) {
|
||||
for (ConfigurationEntry configurationEntry : tenantConfigurations) {
|
||||
if ((PluginConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(
|
||||
configurationEntry.getName()))) {
|
||||
pollingFrequency = configurationEntry.getValue().toString();
|
||||
} else {
|
||||
pollingFrequency = PluginConstants.TenantConfigProperties.DEFAULT_FREQUENCY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pollingFrequency = PluginConstants.TenantConfigProperties.DEFAULT_FREQUENCY;
|
||||
String msg = "Tenant configurations are not initialized yet.";
|
||||
log.error(msg);
|
||||
}
|
||||
ServletContext ctx = (ServletContext) context.getMessageContext().
|
||||
get(MessageContext.SERVLET_CONTEXT);
|
||||
File wapProvisioningFile = (File) ctx.getAttribute(PluginConstants.CONTEXT_WAP_PROVISIONING_FILE);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Received CSR from Device:" + binarySecurityToken);
|
||||
}
|
||||
|
||||
String wapProvisioningFilePath = wapProvisioningFile.getPath();
|
||||
RequestSecurityTokenResponse requestSecurityTokenResponse = new RequestSecurityTokenResponse();
|
||||
requestSecurityTokenResponse.setTokenType(PluginConstants.CertificateEnrolment.TOKEN_TYPE);
|
||||
|
||||
encodedWap = prepareWapProvisioningXML(binarySecurityToken, wapProvisioningFilePath,
|
||||
headerBinarySecurityToken);
|
||||
RequestedSecurityToken requestedSecurityToken = new RequestedSecurityToken();
|
||||
BinarySecurityToken binarySecToken = new BinarySecurityToken();
|
||||
binarySecToken.setValueType(PluginConstants.CertificateEnrolment.VALUE_TYPE);
|
||||
binarySecToken.setEncodingType(PluginConstants.CertificateEnrolment.ENCODING_TYPE);
|
||||
binarySecToken.setToken(encodedWap);
|
||||
requestedSecurityToken.setBinarySecurityToken(binarySecToken);
|
||||
requestSecurityTokenResponse.setRequestedSecurityToken(requestedSecurityToken);
|
||||
requestSecurityTokenResponse.setRequestID(PluginConstants.CertificateEnrolment.REQUEST_ID);
|
||||
response.value = requestSecurityTokenResponse;
|
||||
} catch (CertificateGenerationException e) {
|
||||
String msg = "Problem occurred while generating certificate.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
} catch (WAPProvisioningException e) {
|
||||
String msg = "Problem occurred while generating wap-provisioning file.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while getting tenant configurations.";
|
||||
log.error(msg);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to Convert the Document object into a String.
|
||||
*
|
||||
* @param document - Wap provisioning XML document
|
||||
* @return - String representation of wap provisioning XML document
|
||||
* @throws TransformerException
|
||||
*/
|
||||
private String convertDocumentToString(Document document) throws TransformerException {
|
||||
DOMSource DOMSource = new DOMSource(document);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
StreamResult streamResult = new StreamResult(stringWriter);
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.transform(DOMSource, streamResult);
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method prepares the wap-provisioning file by including relevant certificates etc.
|
||||
*
|
||||
* @param binarySecurityToken - CSR from device
|
||||
* @param wapProvisioningFilePath - File path of wap-provisioning file
|
||||
* @return - base64 encoded final wap-provisioning file as a String
|
||||
* @throws CertificateGenerationException
|
||||
* @throws org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WAPProvisioningException
|
||||
*/
|
||||
private String prepareWapProvisioningXML(String binarySecurityToken, String wapProvisioningFilePath,
|
||||
String headerBst) throws CertificateGenerationException,
|
||||
WAPProvisioningException,
|
||||
WindowsDeviceEnrolmentException {
|
||||
String rootCertEncodedString;
|
||||
String signedCertEncodedString;
|
||||
X509Certificate signedCertificate;
|
||||
String provisioningXmlString;
|
||||
CertificateManagementServiceImpl certMgtServiceImpl = CertificateManagementServiceImpl.getInstance();
|
||||
Base64 base64Encoder = new Base64();
|
||||
try {
|
||||
X509Certificate rootCACertificate = (X509Certificate) certMgtServiceImpl.getCACertificate();
|
||||
rootCertEncodedString = base64Encoder.encodeAsString(rootCACertificate.getEncoded());
|
||||
|
||||
signedCertificate = certMgtServiceImpl.getSignedCertificateFromCSR(binarySecurityToken);
|
||||
signedCertEncodedString = base64Encoder.encodeAsString(signedCertificate.getEncoded());
|
||||
|
||||
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
|
||||
domFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
domFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
DocumentBuilder builder;
|
||||
|
||||
builder = domFactory.newDocumentBuilder();
|
||||
Document document = builder.parse(wapProvisioningFilePath);
|
||||
NodeList wapParm = document.getElementsByTagName(PluginConstants.CertificateEnrolment.PARM);
|
||||
Node caCertificatePosition = wapParm.item(PluginConstants.CertificateEnrolment.CA_CERTIFICATE_POSITION);
|
||||
|
||||
//Adding SHA1 CA certificate finger print to wap-provisioning xml.
|
||||
caCertificatePosition.getParentNode().getAttributes().getNamedItem(PluginConstants.
|
||||
CertificateEnrolment.TYPE).setTextContent(String.valueOf(
|
||||
DigestUtils.sha1Hex(rootCACertificate.getEncoded())).toUpperCase());
|
||||
//Adding encoded CA certificate to wap-provisioning file after removing new line
|
||||
// characters.
|
||||
NamedNodeMap rootCertAttributes = caCertificatePosition.getAttributes();
|
||||
Node rootCertNode =
|
||||
rootCertAttributes.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
rootCertEncodedString = rootCertEncodedString.replaceAll("\n", "");
|
||||
rootCertNode.setTextContent(rootCertEncodedString);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Root certificate: " + rootCertEncodedString);
|
||||
}
|
||||
|
||||
Node signedCertificatePosition = wapParm.item(PluginConstants.CertificateEnrolment.
|
||||
SIGNED_CERTIFICATE_POSITION);
|
||||
|
||||
//Adding SHA1 signed certificate finger print to wap-provisioning xml.
|
||||
signedCertificatePosition.getParentNode().getAttributes().getNamedItem(PluginConstants.
|
||||
CertificateEnrolment.TYPE).setTextContent(String.valueOf(
|
||||
DigestUtils.sha1Hex(signedCertificate.getEncoded())).toUpperCase());
|
||||
|
||||
//Adding encoded signed certificate to wap-provisioning file after removing new line
|
||||
// characters.
|
||||
NamedNodeMap clientCertAttributes = signedCertificatePosition.getAttributes();
|
||||
Node clientEncodedNode =
|
||||
clientCertAttributes.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
signedCertEncodedString = signedCertEncodedString.replaceAll("\n", "");
|
||||
|
||||
clientEncodedNode.setTextContent(signedCertEncodedString);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Signed certificate: " + signedCertEncodedString);
|
||||
}
|
||||
|
||||
//Adding domainName to wap-provisioning xml.
|
||||
Node domainPosition = wapParm.item(PluginConstants.CertificateEnrolment.DOMAIN_POSITION);
|
||||
NamedNodeMap domainAttribute = domainPosition.getAttributes();
|
||||
Node domainNode = domainAttribute.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
domainNode.setTextContent(domain);
|
||||
|
||||
//Adding Next provisioning service URL to wap-provisioning xml.
|
||||
Node syncmlServicePosition = wapParm.item(PluginConstants.CertificateEnrolment.
|
||||
SYNCML_PROVISIONING_ADDR_POSITION);
|
||||
NamedNodeMap syncmlServiceAttribute = syncmlServicePosition.getAttributes();
|
||||
Node syncmlServiceNode = syncmlServiceAttribute.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
syncmlServiceNode.setTextContent(provisioningURL);
|
||||
|
||||
// Adding user name auth token to wap-provisioning xml.
|
||||
Node userNameAuthPosition = wapParm.item(PluginConstants.CertificateEnrolment.APPAUTH_USERNAME_POSITION);
|
||||
NamedNodeMap appServerAttribute = userNameAuthPosition.getAttributes();
|
||||
Node authNameNode = appServerAttribute.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
String userName = getRequestedUser(headerBst);
|
||||
//CacheEntry cacheEntry = (CacheEntry) DeviceUtil.getCacheEntry(headerBst);
|
||||
// String userName = cacheEntry.getUsername();
|
||||
authNameNode.setTextContent(userName);
|
||||
DeviceUtil.removeTokenEntry(headerBst);
|
||||
String password = DeviceUtil.generateRandomToken();
|
||||
Node passwordAuthPosition = wapParm.item(PluginConstants.CertificateEnrolment.APPAUTH_PASSWORD_POSITION);
|
||||
NamedNodeMap appSrvPasswordAttribute = passwordAuthPosition.getAttributes();
|
||||
Node authPasswordNode = appSrvPasswordAttribute.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
authPasswordNode.setTextContent(password);
|
||||
String requestSecurityTokenResponse = SyncmlCredentialUtil.generateRST(userName, password);
|
||||
DeviceUtil.persistChallengeToken(requestSecurityTokenResponse, null, userName);
|
||||
|
||||
// Get device polling frequency from the tenant Configurations.
|
||||
Node numberOfFirstRetries = wapParm.item(PluginConstants.CertificateEnrolment.POLLING_FREQUENCY_POSITION);
|
||||
NamedNodeMap pollingAttributes = numberOfFirstRetries.getAttributes();
|
||||
Node pollValue = pollingAttributes.getNamedItem(PluginConstants.CertificateEnrolment.VALUE);
|
||||
pollValue.setTextContent(pollingFrequency);
|
||||
provisioningXmlString = convertDocumentToString(document);
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new WAPProvisioningException("Problem occurred while creating configuration request", e);
|
||||
} catch (CertificateEncodingException e) {
|
||||
throw new WindowsDeviceEnrolmentException("Error occurred while encoding certificates.", e);
|
||||
} catch (SAXException e) {
|
||||
throw new WAPProvisioningException("Error occurred while parsing wap-provisioning.xml file.", e);
|
||||
} catch (TransformerException e) {
|
||||
throw new WAPProvisioningException("Error occurred while transforming wap-provisioning.xml file.", e);
|
||||
} catch (IOException e) {
|
||||
throw new WAPProvisioningException("Error occurred while getting wap-provisioning.xml file.", e);
|
||||
} catch (SyncmlMessageFormatException e) {
|
||||
throw new WindowsDeviceEnrolmentException("Error occurred while generating password hash value.", e);
|
||||
} catch (KeystoreException e) {
|
||||
throw new CertificateGenerationException("CA certificate cannot be generated.", e);
|
||||
}
|
||||
return base64Encoder.encodeAsString(provisioningXmlString.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method get the soap request header contents.
|
||||
*
|
||||
* @return List of SOAP headers.
|
||||
*/
|
||||
private List<Header> getHeaders() {
|
||||
MessageContext messageContext = context.getMessageContext();
|
||||
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
|
||||
return null;
|
||||
}
|
||||
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
|
||||
return CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method to getting RSTR requested user from the Cache.
|
||||
*
|
||||
* @param bst Binary Security token which has given from BST Endpoint.
|
||||
* @return User for given token.
|
||||
*/
|
||||
private String getRequestedUser(String bst) {
|
||||
MobileCacheEntry cacheEntry = null;
|
||||
try {
|
||||
cacheEntry = DeviceUtil.getTokenEntry(bst);
|
||||
} catch (WindowsDeviceEnrolmentException e) {
|
||||
|
||||
}
|
||||
return cacheEntry.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* This Method to generate windows device.
|
||||
*
|
||||
* @param windowsDevice Requested Device with properties.
|
||||
* @return Value added Device.
|
||||
*/
|
||||
private Device generateDevice(WindowsDevice windowsDevice) {
|
||||
Gson gson = new Gson();
|
||||
Device generatedDevice = new Device();
|
||||
|
||||
Device.Property OSVersionProperty = new Device.Property();
|
||||
OSVersionProperty.setName(PluginConstants.SyncML.OS_VERSION);
|
||||
OSVersionProperty.setValue(windowsDevice.getOsVersion());
|
||||
|
||||
Device.Property IMSEIProperty = new Device.Property();
|
||||
IMSEIProperty.setName(PluginConstants.SyncML.IMSI);
|
||||
IMSEIProperty.setValue(windowsDevice.getImsi());
|
||||
|
||||
Device.Property IMEIProperty = new Device.Property();
|
||||
IMEIProperty.setName(PluginConstants.SyncML.IMEI);
|
||||
IMEIProperty.setValue(windowsDevice.getImei());
|
||||
|
||||
Device.Property deviceInfoProperties = new Device.Property();
|
||||
deviceInfoProperties.setName(PluginConstants.WindowsEnrollmentProperties.TYPE);
|
||||
deviceInfoProperties.setValue(windowsDevice.getWindowsType());
|
||||
String deviceInfo = gson.toJson(deviceInfoProperties);
|
||||
|
||||
Device.Property winDeviceType = new Device.Property();
|
||||
winDeviceType.setName(PluginConstants.SyncML.DEVICE_INFO);
|
||||
winDeviceType.setValue(deviceInfo);
|
||||
|
||||
List<Device.Property> propertyList = new ArrayList<>();
|
||||
propertyList.add(OSVersionProperty);
|
||||
propertyList.add(IMSEIProperty);
|
||||
propertyList.add(IMEIProperty);
|
||||
propertyList.add(winDeviceType);
|
||||
|
||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||
enrolmentInfo.setOwner(windowsDevice.getUser());
|
||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||
|
||||
generatedDevice.setEnrolmentInfo(enrolmentInfo);
|
||||
generatedDevice.setDeviceIdentifier(windowsDevice.getDeviceId());
|
||||
generatedDevice.setProperties(propertyList);
|
||||
generatedDevice.setType(windowsDevice.getDeviceType());
|
||||
generatedDevice.setName(windowsDevice.getDeviceName());
|
||||
|
||||
return generatedDevice;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method to enroll windows10 Device.
|
||||
*
|
||||
* @param requestContextItems Context values to enroll the device.
|
||||
* @param headerBinarySecurityToken SOAP request header value to identify the user.
|
||||
* @throws DeviceManagementException Exception occurs while enrolling the Device.
|
||||
* @throws PolicyManagementException Exception occurs while getting effective policies.
|
||||
*/
|
||||
private void enrollDevice(AdditionalContext requestContextItems, String headerBinarySecurityToken)
|
||||
throws DeviceManagementException, PolicyManagementException {
|
||||
WindowsDevice windowsDevice = new WindowsDevice();
|
||||
windowsDevice.setDeviceType(DeviceManagementConstants.MobileDeviceTypes.
|
||||
MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
windowsDevice.setUser(getRequestedUser(headerBinarySecurityToken));
|
||||
List<ContextItem> contextItems = requestContextItems.getcontextitem();
|
||||
for(ContextItem contextItem : contextItems) {
|
||||
if (PluginConstants.WindowsEnrollmentProperties.DEVICE_ID.equals(contextItem.getName())) {
|
||||
windowsDevice.setDeviceId(contextItem.getValue());
|
||||
}
|
||||
if (PluginConstants.WindowsEnrollmentProperties.DEVICE_NAME.equals(contextItem.getName())) {
|
||||
windowsDevice.setDeviceName(contextItem.getValue());
|
||||
}
|
||||
if (PluginConstants.WindowsEnrollmentProperties.IMEI.equals(contextItem.getName())) {
|
||||
windowsDevice.setImei(contextItem.getValue());
|
||||
}
|
||||
if (PluginConstants.WindowsEnrollmentProperties.DEVICE_VERSION.equals(contextItem.getName())) {
|
||||
windowsDevice.setOsVersion(contextItem.getValue());
|
||||
}
|
||||
if (PluginConstants.WindowsEnrollmentProperties.TYPE.equals(contextItem.getName())) {
|
||||
windowsDevice.setWindowsType(contextItem.getValue());
|
||||
}
|
||||
}
|
||||
Device device = generateDevice(windowsDevice);
|
||||
WindowsAPIUtils.getDeviceManagementService().enrollDevice(device);
|
||||
PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService();
|
||||
policyManagerService.getEffectivePolicy(new DeviceIdentifier(windowsDevice.getDeviceId(), device.getType()));
|
||||
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue