mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
fixing windows plugin relalted slf4j issue
This commit is contained in:
parent
97eac5064e
commit
86056df434
@ -260,6 +260,17 @@
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</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>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
|
||||
@ -281,6 +292,12 @@
|
||||
<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>
|
||||
@ -318,6 +335,12 @@
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -28,11 +28,9 @@ public final class PluginConstants {
|
||||
public static final String DISCOVERY_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.mdm.mobileservices.windows.services.discovery.DiscoveryService";
|
||||
public static final String CERTIFICATE_ENROLLMENT_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.mdm.mobileservices.windows.services.wstep" +
|
||||
".CertificateEnrollmentService";
|
||||
"org.wso2.carbon.mdm.mobileservices.windows.services.wstep.CertificateEnrollmentService";
|
||||
public static final String CERTIFICATE_ENROLLMENT_POLICY_SERVICE_ENDPOINT =
|
||||
"org.wso2.carbon.mdm.mobileservices.windows.services.xcep" +
|
||||
".CertificateEnrollmentPolicyService";
|
||||
"org.wso2.carbon.mdm.mobileservices.windows.services.xcep.CertificateEnrollmentPolicyService";
|
||||
|
||||
//Services' target namespaces
|
||||
public static final String DISCOVERY_SERVICE_TARGET_NAMESPACE =
|
||||
@ -60,11 +58,11 @@ public final class PluginConstants {
|
||||
|
||||
//Servlet Context attributes names
|
||||
public static final String CONTEXT_WAP_PROVISIONING_FILE = "WAP_PROVISIONING_FILE";
|
||||
public static final String WINDOWS_PLUGIN_PROPERTIES = "WINDOWS_PLUGIN_PROPERTIES";
|
||||
|
||||
//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
|
||||
@ -78,20 +76,16 @@ public final class PluginConstants {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String ENROLL_SUBDOMAIN = "https://EnterpriseEnrollment.";
|
||||
public static final String DEVICE_ENROLLMENT_SUBDOMAIN = "https://EnterpriseEnrollment.";
|
||||
public static final String CERTIFICATE_ENROLLMENT_POLICY_SERVICE_URL =
|
||||
"/ENROLLMENTSERVER/PolicyEnrollmentWebservice" +
|
||||
".svc";
|
||||
"/ENROLLMENTSERVER/PolicyEnrollmentWebservice.svc";
|
||||
public static final String CERTIFICATE_ENROLLMENT_SERVICE_URL =
|
||||
"/ENROLLMENTSERVER/DeviceEnrollmentWebservice" +
|
||||
".svc";
|
||||
"/ENROLLMENTSERVER/DeviceEnrollmentWebservice.svc";
|
||||
public static final String ONPREMISE_CERTIFICATE_ENROLLMENT_POLICY =
|
||||
"/ENROLLMENTSERVER/ONPREMISE/" +
|
||||
"PolicyEnrollmentWebservice.svc";
|
||||
"/ENROLLMENTSERVER/ONPREMISE/PolicyEnrollmentWebservice.svc";
|
||||
public static final String ONPREMISE_CERTIFICATE_ENROLLMENT_SERVICE_URL =
|
||||
"/ENROLLMENTSERVER/ONPREMISE/DeviceEnrollmentWebservice.svc";
|
||||
public static final String WAB_URL = "/mdm/enrollments/windows/login-agent";
|
||||
|
||||
public static final String WAB_URL = "/emm-web-agent/enrollments/windows/login-agent";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,7 +107,7 @@ public final class PluginConstants {
|
||||
}
|
||||
|
||||
/**
|
||||
* Certificate enrollment Service related constants
|
||||
* Certificate enrollment Service related constants.
|
||||
*/
|
||||
public final class CertificateEnrolment {
|
||||
private CertificateEnrolment() {
|
||||
@ -121,17 +115,14 @@ public final class PluginConstants {
|
||||
}
|
||||
|
||||
public static final String TOKEN_TYPE =
|
||||
"http://schemas.microsoft.com/5.0.0" +
|
||||
".0/ConfigurationManager/Enrollment/DeviceEnrollmentToken";
|
||||
"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";
|
||||
"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";
|
||||
"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 PROPERTIES_XML = "properties.xml";
|
||||
@ -141,8 +132,7 @@ public final class PluginConstants {
|
||||
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";
|
||||
"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";
|
||||
@ -150,10 +140,23 @@ public final class PluginConstants {
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* SynclML service related constants
|
||||
* SynclML service related constants.
|
||||
*/
|
||||
public final class SyncML {
|
||||
private SyncML() {
|
||||
@ -182,9 +185,9 @@ public final class PluginConstants {
|
||||
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 VENDER_POSITION = 4;
|
||||
public static final int VENDOR_POSITION = 4;
|
||||
public static final int MODEL_POSITION = 5;
|
||||
public static final int MACADDRESS_POSITION = 7;
|
||||
public static final int MAC_ADDRESS_POSITION = 7;
|
||||
public static final int RESOLUTION_POSITION = 8;
|
||||
public static final int DEVICE_NAME_POSITION = 9;
|
||||
public static final String SYNCML_DATA_ONE = "1";
|
||||
@ -275,7 +278,8 @@ public final class PluginConstants {
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,4 +294,13 @@ public final class PluginConstants {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.common.authenticator;
|
||||
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.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;
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.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";
|
||||
}
|
||||
@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.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.identity.oauth2.stub.OAuth2TokenValidationServiceStub;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.OAuthTokenValidationException;
|
||||
|
||||
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(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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.common.authenticator;
|
||||
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.impl.LocalOAuthValidator;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.impl.RemoteOAuthValidator;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.common.authenticator.impl;
|
||||
|
||||
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.OAuth2TokenValidator;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.OAuthConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.OAuthValidationResponse;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.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.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.mdm.mobileservices.windows.common.authenticator.OAuth2TokenValidator;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.OAuthTokenValidationStubFactory;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.OAuthValidationResponse;
|
||||
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(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,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,23 +18,18 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Class for java CacheEntry
|
||||
*/
|
||||
@ApiModel(value = "CacheEntry",
|
||||
description = "This class carries all information related to token cache")
|
||||
public class CacheEntry {
|
||||
|
||||
@ApiModelProperty(name = "deviceID", value = "Windows deviceIdentifier", required = true)
|
||||
public class CacheEntry implements Serializable {
|
||||
private String deviceID;
|
||||
@ApiModelProperty(name = "username", value = "Enrolled User", required = true)
|
||||
private String username;
|
||||
@ApiModelProperty(name = "ownership", value = "Enrollment ownership(BYOD/COPE)", required = true)
|
||||
private String ownership;
|
||||
|
||||
private static final long serialVersionUID = 19981017L;
|
||||
|
||||
public String getOwnership() {
|
||||
return ownership;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,17 +18,10 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Class for challenge token
|
||||
*/
|
||||
@ApiModel(value = "Token", description = "Details related device encryption.")
|
||||
public class Token {
|
||||
|
||||
@ApiModelProperty(name = "challengeToken",
|
||||
value = "Enrollment Binary security token", required = true)
|
||||
private String challengeToken;
|
||||
|
||||
public String getChallengeToken() {
|
||||
|
||||
@ -1,103 +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.mdm.mobileservices.windows.common.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Bean class for storing Windows plugin properties after reading the property file.
|
||||
*/
|
||||
@ApiModel(value = "WindowsPluginProperties", description = "Windows plugin related properties.")
|
||||
public class WindowsPluginProperties {
|
||||
|
||||
@ApiModelProperty(name = "keyStorePassword", value = "Password of the keyStore.", required = true)
|
||||
private String keyStorePassword;
|
||||
@ApiModelProperty(name = "privateKeyPassword", value = "password of the privateKey.", required = true)
|
||||
private String privateKeyPassword;
|
||||
@ApiModelProperty(name = "commonName", value = "Common Name of the certificate.", required = true)
|
||||
private String commonName;
|
||||
@ApiModelProperty(name = "authPolicy", value = "Windows enrollment authentication policy(Federated/on-premise).", required = true)
|
||||
private String authPolicy;
|
||||
@ApiModelProperty(name = "domain", value = "Domain of the given Email.", required = true)
|
||||
private String domain;
|
||||
@ApiModelProperty(name = "notBeforeDays", value = "Number of days to before the certificate expire.", required = true)
|
||||
private int notBeforeDays;
|
||||
@ApiModelProperty(name = "notAfterDays", value = "Number of days to after the certificate has been expired.", required = true)
|
||||
private int notAfterDays;
|
||||
|
||||
public String getKeyStorePassword() {
|
||||
return keyStorePassword;
|
||||
}
|
||||
|
||||
public String getPrivateKeyPassword() {
|
||||
return privateKeyPassword;
|
||||
}
|
||||
|
||||
public String getCommonName() {
|
||||
return commonName;
|
||||
}
|
||||
|
||||
public int getNotBeforeDays() {
|
||||
return notBeforeDays;
|
||||
}
|
||||
|
||||
public int getNotAfterDays() {
|
||||
return notAfterDays;
|
||||
}
|
||||
|
||||
public void setKeyStorePassword(String keyStorePassword) {
|
||||
this.keyStorePassword = keyStorePassword;
|
||||
}
|
||||
|
||||
public void setPrivateKeyPassword(String privateKeyPassword) {
|
||||
this.privateKeyPassword = privateKeyPassword;
|
||||
}
|
||||
|
||||
public void setCommonName(String commonName) {
|
||||
this.commonName = commonName;
|
||||
}
|
||||
|
||||
public void setNotBeforeDays(int notBeforeDays) {
|
||||
this.notBeforeDays = notBeforeDays;
|
||||
}
|
||||
|
||||
public void setNotAfterDays(int notAfterDays) {
|
||||
this.notAfterDays = notAfterDays;
|
||||
}
|
||||
|
||||
public String getAuthPolicy() {
|
||||
return authPolicy;
|
||||
}
|
||||
|
||||
public void setAuthPolicy(String authPolicy) {
|
||||
this.authPolicy = authPolicy;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -30,7 +30,7 @@ import javax.ws.rs.core.Response;
|
||||
public class BadRequestException extends WebApplicationException {
|
||||
|
||||
public BadRequestException(Message message, MediaType mediaType) {
|
||||
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).
|
||||
super(Response.status(Response.Status.BAD_REQUEST).entity(message).
|
||||
type(mediaType).build());
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -19,7 +19,7 @@
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.exceptions;
|
||||
|
||||
/**
|
||||
* MDMAPIUtils class provides utility function used by CDM REST-API classes.
|
||||
* MDMAPIUtils class provides utility function which are used by CDM REST-API classes.
|
||||
*/
|
||||
public class MDMAPIException extends Exception {
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.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,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -19,7 +19,7 @@
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.exceptions;
|
||||
|
||||
/**
|
||||
* Custom class for windows API configurations.
|
||||
* Custom class for windows device configurations.
|
||||
*/
|
||||
public class WindowsConfigurationException extends Exception {
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
@ -18,23 +18,13 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* DTO class to hold the information of authenticated user.
|
||||
*/
|
||||
@ApiModel(value = "ApplicationInstallation",
|
||||
description = "This class carries all information related to install application")
|
||||
|
||||
public class AuthenticationInfo {
|
||||
@ApiModelProperty(name = "message", value = "Authentication info message.", required = true)
|
||||
private String message;
|
||||
@ApiModelProperty(name = "username", value = "Username of the enrolled user.", required = true)
|
||||
private String username;
|
||||
@ApiModelProperty(name = "tenantDomain", value = "Enrolled user's tenant domain.", required = true)
|
||||
private String tenantDomain;
|
||||
@ApiModelProperty(name = "tenantId", value = "Enrolled user's tenant ID)", required = true)
|
||||
private int tenantId = -1;
|
||||
|
||||
public String getUsername() {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
@ -19,8 +19,6 @@
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ws.security.WSSecurityException;
|
||||
import org.apache.ws.security.handler.RequestData;
|
||||
import org.apache.ws.security.message.token.BinarySecurity;
|
||||
@ -28,13 +26,12 @@ 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.DeviceManagementException;
|
||||
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO;
|
||||
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.OAuthValidatorFactory;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.beans.CacheEntry;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.AuthenticationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.OAuthTokenValidationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -43,119 +40,98 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class BSTValidator implements Validator {
|
||||
|
||||
private static Log log = LogFactory.getLog(BSTValidator.class);
|
||||
private static final String BEARER_TOKEN_TYPE = "bearer";
|
||||
private static final String RESOURCE_KEY = "resource";
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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 encodedBinarySecurityToken;
|
||||
String bearerToken;
|
||||
String requestedUri;
|
||||
Credential returnCredentials = null;
|
||||
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();
|
||||
encodedBinarySecurityToken = new String(base64.decode(binarySecurityToken));
|
||||
bearerToken = new String(base64.decode(binarySecurityToken));
|
||||
AuthenticationInfo authenticationInfo;
|
||||
try {
|
||||
authenticationInfo = validateRequest(requestedUri, encodedBinarySecurityToken);
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId());
|
||||
privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain());
|
||||
privilegedCarbonContext.setUsername(authenticationInfo.getUsername());
|
||||
authenticationInfo = validateRequest(requestedUri, bearerToken);
|
||||
WindowsAPIUtils.startTenantFlow(authenticationInfo);
|
||||
|
||||
if (authenticate(binarySecurityToken)) {
|
||||
returnCredentials = credential;
|
||||
if (authenticate(binarySecurityToken, authenticationInfo)) {
|
||||
userCredentials = credential;
|
||||
} else {
|
||||
String msg = "Authentication failure due to invalid binary security token.";
|
||||
log.error(msg);
|
||||
throw new WindowsDeviceEnrolmentException(msg);
|
||||
throw new WindowsDeviceEnrolmentException(
|
||||
"Authentication failure due to invalid binary security token.");
|
||||
}
|
||||
} catch (AuthenticationException e) {
|
||||
String msg = "Failure occurred in the BST validator.";
|
||||
log.error(msg, e);
|
||||
throw new WSSecurityException(msg, e);
|
||||
throw new WSSecurityException("Failure occurred in the BST validator.", e);
|
||||
} catch (WindowsDeviceEnrolmentException e) {
|
||||
String msg = "Authentication Failure occurred due to binary security token.";
|
||||
log.error(msg, e);
|
||||
throw new WSSecurityException(msg, 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 returnCredentials;
|
||||
return userCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method authenticates the user checking the binary security token in the user store.
|
||||
* 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
|
||||
* @param binarySecurityToken - Binary security token received in the SOAP message header.
|
||||
* @return - Authentication status.
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public boolean authenticate(String binarySecurityToken) throws
|
||||
private boolean authenticate(String binarySecurityToken, AuthenticationInfo authenticationInfo) throws
|
||||
AuthenticationException {
|
||||
|
||||
WindowsAPIUtils.startTenantFlow(authenticationInfo);
|
||||
if (DeviceUtil.getCacheEntry(binarySecurityToken) != null) {
|
||||
CacheEntry cacheentry = (CacheEntry) DeviceUtil.getCacheEntry(binarySecurityToken);
|
||||
String username = cacheentry.getUsername();
|
||||
return username != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate SOAP request token.
|
||||
*
|
||||
* @param requestedUri- Requested endpoint URI.
|
||||
* @param encodedBinarySecurityToken-Binary security token comes from the soap request message.
|
||||
* @param requestedUri -Requested endpoint URI.
|
||||
* @param binarySecurityToken -Binary security token comes from the soap request message.
|
||||
* @return returns authorized user information.
|
||||
* @throws WindowsDeviceEnrolmentException
|
||||
*/
|
||||
public AuthenticationInfo validateRequest(String requestedUri, String encodedBinarySecurityToken)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
private AuthenticationInfo validateRequest(String requestedUri, String binarySecurityToken)
|
||||
throws WindowsDeviceEnrolmentException, OAuthTokenValidationException {
|
||||
|
||||
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
|
||||
// Create a OAuth2TokenValidationRequestDTO object for validating access token
|
||||
OAuth2TokenValidationRequestDTO dto = new OAuth2TokenValidationRequestDTO();
|
||||
//Set the access token info
|
||||
OAuth2TokenValidationRequestDTO.OAuth2AccessToken oAuth2AccessToken = dto.new OAuth2AccessToken();
|
||||
oAuth2AccessToken.setTokenType(BSTValidator.BEARER_TOKEN_TYPE);
|
||||
oAuth2AccessToken.setIdentifier(encodedBinarySecurityToken);
|
||||
dto.setAccessToken(oAuth2AccessToken);
|
||||
|
||||
//Set the resource context param. This will be used in scope validation.
|
||||
OAuth2TokenValidationRequestDTO.TokenValidationContextParam
|
||||
resourceContextParam = dto.new TokenValidationContextParam();
|
||||
resourceContextParam.setKey(BSTValidator.RESOURCE_KEY);
|
||||
resourceContextParam.setValue(requestedUri + ":POST");
|
||||
|
||||
OAuth2TokenValidationRequestDTO.TokenValidationContextParam[]
|
||||
tokenValidationContextParams =
|
||||
new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1];
|
||||
tokenValidationContextParams[0] = resourceContextParam;
|
||||
dto.setContext(tokenValidationContextParams);
|
||||
String resource = requestedUri + ":POST";
|
||||
OAuthValidationResponse oAuthValidationResponse = OAuthValidatorFactory.getValidator().
|
||||
validateToken(binarySecurityToken, resource);
|
||||
try {
|
||||
OAuth2TokenValidationResponseDTO oAuth2TokenValidationResponseDTO =
|
||||
WindowsAPIUtils.getOAuth2TokenValidationService().validate(dto);
|
||||
if (oAuth2TokenValidationResponseDTO.isValid()) {
|
||||
String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser();
|
||||
if (oAuthValidationResponse.isValid()) {
|
||||
String username = oAuthValidationResponse.getUserName();
|
||||
String tenantDomain = oAuthValidationResponse.getTenantDomain();
|
||||
|
||||
authenticationInfo.setUsername(username);
|
||||
authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username));
|
||||
authenticationInfo.setTenantId(WindowsAPIUtils.getTenantIdOFUser(username));
|
||||
authenticationInfo.setTenantDomain(tenantDomain);
|
||||
authenticationInfo.setTenantId(WindowsAPIUtils.getTenantIdOFUser(username + "@" + tenantDomain));
|
||||
} else {
|
||||
authenticationInfo.setMessage(oAuth2TokenValidationResponseDTO.getErrorMsg());
|
||||
authenticationInfo.setMessage(oAuthValidationResponse.getErrorMsg());
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Authentication failure due to invalid binary security token.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(
|
||||
"Authentication failure due to invalid binary security token.", e);
|
||||
}
|
||||
return authenticationInfo;
|
||||
}
|
||||
|
||||
@ -1,138 +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.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.beans.WindowsPluginProperties;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class performs one time operations.
|
||||
*/
|
||||
public class ConfigInitializerContextListener implements ServletContextListener {
|
||||
|
||||
public static final int INITIAL_VALUE = 0;
|
||||
private static Log log = LogFactory.getLog(ConfigInitializerContextListener.class);
|
||||
|
||||
private enum PropertyName {
|
||||
PROPERTY_SIGNED_CERT_CN("SignedCertCN"),
|
||||
PROPERTY_SIGNED_CERT_NOT_BEFORE("SignedCertNotBefore"),
|
||||
PROPERTY_SIGNED_CERT_NOT_AFTER("SignedCertNotAfter"),
|
||||
PROPERTY_PASSWORD("Password"),
|
||||
PROPERTY_PRIVATE_KEY_PASSWORD("PrivateKeyPassword"),
|
||||
AUTH_POLICY("AuthPolicy"),
|
||||
DOMAIN("domain");
|
||||
|
||||
private final String propertyName;
|
||||
|
||||
PropertyName(final String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.propertyName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method loads wap-provisioning file / property file, sets wap-provisioning file and
|
||||
* extracted properties as attributes in servlet context.
|
||||
*
|
||||
* @param servletContextEvent - Uses when servlet communicating with servlet container.
|
||||
*/
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||
|
||||
ServletContext servletContext = servletContextEvent.getServletContext();
|
||||
File propertyFile = new File(getClass().getClassLoader().getResource(
|
||||
PluginConstants.CertificateEnrolment.PROPERTIES_XML).getFile());
|
||||
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder;
|
||||
Document document = null;
|
||||
try {
|
||||
docBuilder = docBuilderFactory.newDocumentBuilder();
|
||||
if (docBuilder != null) {
|
||||
document = docBuilder.parse(propertyFile);
|
||||
}
|
||||
} catch (ParserConfigurationException e) {
|
||||
log.error("Parser configuration failure while reading properties.xml.");
|
||||
} catch (SAXException e) {
|
||||
log.error("Parsing error occurred while reading properties.xml.");
|
||||
} catch (IOException e) {
|
||||
log.error("File reading error occurred while accessing properties.xml.");
|
||||
}
|
||||
|
||||
String password = null;
|
||||
String privateKeyPassword = null;
|
||||
String signedCertCommonName = null;
|
||||
String authPolicy = null;
|
||||
String domain = null;
|
||||
int signedCertNotBeforeDate = INITIAL_VALUE;
|
||||
int signedCertNotAfterDate = INITIAL_VALUE;
|
||||
|
||||
if (document != null) {
|
||||
password = document.getElementsByTagName(PropertyName.PROPERTY_PASSWORD.getValue()).item(0).
|
||||
getTextContent();
|
||||
privateKeyPassword = document.getElementsByTagName(PropertyName.PROPERTY_PRIVATE_KEY_PASSWORD.getValue()).
|
||||
item(0).getTextContent();
|
||||
signedCertCommonName =
|
||||
document.getElementsByTagName(PropertyName.PROPERTY_SIGNED_CERT_CN.getValue()).item(0).
|
||||
getTextContent();
|
||||
authPolicy = document.getElementsByTagName(PropertyName.AUTH_POLICY.getValue()).item(0).
|
||||
getTextContent();
|
||||
signedCertNotBeforeDate = Integer.valueOf(document.getElementsByTagName(
|
||||
PropertyName.PROPERTY_SIGNED_CERT_NOT_BEFORE.getValue()).item(0).getTextContent());
|
||||
signedCertNotAfterDate = Integer.valueOf(document.getElementsByTagName(
|
||||
PropertyName.PROPERTY_SIGNED_CERT_NOT_AFTER.getValue()).item(0).getTextContent());
|
||||
domain = document.getElementsByTagName(PropertyName.DOMAIN.getValue()).item(0).getTextContent();
|
||||
|
||||
}
|
||||
|
||||
WindowsPluginProperties properties = new WindowsPluginProperties();
|
||||
properties.setKeyStorePassword(password);
|
||||
properties.setPrivateKeyPassword(privateKeyPassword);
|
||||
properties.setCommonName(signedCertCommonName);
|
||||
properties.setNotBeforeDays(signedCertNotBeforeDate);
|
||||
properties.setNotAfterDays(signedCertNotAfterDate);
|
||||
properties.setAuthPolicy(authPolicy);
|
||||
properties.setDomain(domain);
|
||||
servletContext.setAttribute(PluginConstants.WINDOWS_PLUGIN_PROPERTIES, properties);
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.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,10 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
@ -18,29 +18,24 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for holding device ids.
|
||||
* Class for holding valid and invalid devices.
|
||||
*/
|
||||
@ApiModel(value = "DeviceIDHolder", description = "This class carries all information related to DeviceIDs")
|
||||
public class DeviceIDHolder {
|
||||
|
||||
@ApiModelProperty(name = "errorDeviceIdList", value = "Error occurred DeviceIds.)", required = true)
|
||||
private List<String> errorDeviceIdList;
|
||||
@ApiModelProperty(name = "validDeviceIDList", value = "Valid DeviceIDs.)", required = true)
|
||||
private List<String> invalidDeviceIdList;
|
||||
private List<DeviceIdentifier> validDeviceIDList;
|
||||
|
||||
public List<String> getErrorDeviceIdList() {
|
||||
return errorDeviceIdList;
|
||||
public List<String> getInvalidDeviceIdList() {
|
||||
return invalidDeviceIdList;
|
||||
}
|
||||
|
||||
public void setErrorDeviceIdList(List<String> errorDeviceIdList) {
|
||||
this.errorDeviceIdList = errorDeviceIdList;
|
||||
public void setInvalidDeviceIdList(List<String> invalidDeviceIdList) {
|
||||
this.invalidDeviceIdList = invalidDeviceIdList;
|
||||
}
|
||||
|
||||
public List<DeviceIdentifier> getValidDeviceIDList() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,7 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.beans.CacheEntry;
|
||||
|
||||
import javax.cache.Cache;
|
||||
@ -29,7 +28,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Class for generate random token for XCEP and WSTEP
|
||||
* Class for generate random token for XCEP and WSTEP.
|
||||
*/
|
||||
public class DeviceUtil {
|
||||
|
||||
@ -42,7 +41,7 @@ public class DeviceUtil {
|
||||
return String.valueOf(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public static void persistChallengeToken(String token, String deviceID, String username) throws DeviceManagementException {
|
||||
public static void persistChallengeToken(String token, String deviceID, String username) {
|
||||
|
||||
Object objCacheEntry = getCacheEntry(token);
|
||||
CacheEntry cacheEntry;
|
||||
@ -70,12 +69,12 @@ public class DeviceUtil {
|
||||
CacheManager contextCacheManager = Caching.getCacheManager(TOKEN_CACHE_MANAGER).
|
||||
getCache(TOKEN_CACHE).getCacheManager();
|
||||
if (!isContextCacheInitialized) {
|
||||
return Caching.getCacheManager(TOKEN_CACHE_MANAGER).getCache(TOKEN_CACHE);
|
||||
} else {
|
||||
isContextCacheInitialized = true;
|
||||
return contextCacheManager.createCacheBuilder(TOKEN_CACHE_MANAGER).setExpiry(
|
||||
CacheConfiguration.ExpiryType.MODIFIED,
|
||||
new CacheConfiguration.Duration(TimeUnit.MINUTES, CACHE_DURATION)).setStoreByValue(false).build();
|
||||
} else {
|
||||
return Caching.getCacheManager(TOKEN_CACHE_MANAGER).getCache(TOKEN_CACHE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -15,6 +15,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate Error Messages for responses.
|
||||
*/
|
||||
@ -23,7 +24,6 @@ package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
public class ErrorMessage {
|
||||
|
||||
private String errorMessage;
|
||||
private String errorCode;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
@ -33,7 +33,5 @@ public class ErrorMessage {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -60,9 +60,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, Messag
|
||||
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");
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(entityStream, UTF_8);
|
||||
try {
|
||||
return getGson().fromJson(reader, type);
|
||||
} finally {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.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,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ws.security.WSSecurityException;
|
||||
import org.apache.ws.security.handler.RequestData;
|
||||
import org.apache.ws.security.validate.Credential;
|
||||
@ -40,7 +38,6 @@ public class UsernameTokenValidator implements Validator {
|
||||
private static final int USER_SEGMENT = 0;
|
||||
private static final int DOMAIN_SEGMENT = 1;
|
||||
private static final String DELIMITER = "@";
|
||||
private static Log log = LogFactory.getLog(UsernameTokenValidator.class);
|
||||
|
||||
/**
|
||||
* This method validates the username token in SOAP message coming from the device.
|
||||
@ -65,20 +62,12 @@ public class UsernameTokenValidator implements Validator {
|
||||
if (authenticate(user, password, domain)) {
|
||||
returnCredentials = credential;
|
||||
} else {
|
||||
String msg = "Authentication failure due to incorrect credentials.";
|
||||
log.error(msg);
|
||||
throw new WindowsDeviceEnrolmentException(msg);
|
||||
throw new WindowsDeviceEnrolmentException("Authentication failure due to incorrect credentials.");
|
||||
}
|
||||
//Generic exception is caught here as there is no need of taking different actions for
|
||||
//different exceptions.
|
||||
} catch (AuthenticationException e) {
|
||||
String msg = "Failure occurred in the BST validator.";
|
||||
log.error(msg, e);
|
||||
throw new WSSecurityException(msg, e);
|
||||
throw new WSSecurityException("Failure occurred in the BST validator.", e);
|
||||
} catch (WindowsDeviceEnrolmentException e) {
|
||||
String msg = "Authentication Failure occurred due to binary security token.";
|
||||
log.error(msg, e);
|
||||
throw new WSSecurityException(msg, e);
|
||||
throw new WSSecurityException("Authentication Failure occurred due to binary security token.", e);
|
||||
}
|
||||
return returnCredentials;
|
||||
}
|
||||
@ -103,30 +92,21 @@ public class UsernameTokenValidator implements Validator {
|
||||
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||
|
||||
if (realmService == null) {
|
||||
String msg = "RealmService not initialized.";
|
||||
log.error(msg);
|
||||
throw new AuthenticationException(msg);
|
||||
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) {
|
||||
String msg = "Invalid tenant domain " + tenantDomain;
|
||||
log.error(msg);
|
||||
throw new AuthenticationException(msg);
|
||||
throw new AuthenticationException("Invalid tenant domain " + tenantDomain);
|
||||
}
|
||||
UserRealm userRealm = realmService.getTenantUserRealm(tenantId);
|
||||
|
||||
return userRealm.getUserStoreManager().authenticate(username, password);
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "User store is not initialized.";
|
||||
log.error(msg, e);
|
||||
throw new AuthenticationException(msg, e);
|
||||
throw new AuthenticationException("User store is not initialized.", e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,15 +18,12 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.common.util;
|
||||
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
||||
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.DeviceManagementException;
|
||||
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.notification.mgt.NotificationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
@ -35,13 +32,13 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
|
||||
import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.MDMAPIException;
|
||||
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.api.UserStoreManager;
|
||||
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;
|
||||
@ -52,8 +49,6 @@ import java.util.List;
|
||||
*/
|
||||
public class WindowsAPIUtils {
|
||||
|
||||
private static Log log = LogFactory.getLog(WindowsAPIUtils.class);
|
||||
|
||||
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
|
||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
identifier.setId(deviceId);
|
||||
@ -61,59 +56,23 @@ public class WindowsAPIUtils {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public static CertificateManagementService getCertificateManagementService() {
|
||||
CertificateManagementService cmService;
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
cmService =
|
||||
(CertificateManagementService)ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
return cmService;
|
||||
}
|
||||
|
||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||
if (deviceManagementProviderService == null) {
|
||||
String msg = "Device Management service has not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
throw new IllegalStateException("Device Management service has not initialized.");
|
||||
}
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
|
||||
|
||||
public static UserStoreManager getUserStoreManager() throws MDMAPIException {
|
||||
RealmService realmService;
|
||||
UserStoreManager userStoreManager;
|
||||
try {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||
if (realmService == null) {
|
||||
String msg = "Realm service has not initialized.";
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
int tenantId = ctx.getTenantId();
|
||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while retrieving current user store manager";
|
||||
throw new MDMAPIException(msg, e);
|
||||
}
|
||||
return userStoreManager;
|
||||
}
|
||||
|
||||
public static NotificationManagementService getNotificationManagementService() {
|
||||
NotificationManagementService notificationManagementService;
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
notificationManagementService = (NotificationManagementService) ctx.getOSGiService(
|
||||
NotificationManagementService.class, null);
|
||||
notificationManagementService =
|
||||
(NotificationManagementService) ctx.getOSGiService(NotificationManagementService.class, null);
|
||||
if (notificationManagementService == null) {
|
||||
String msg = "Notification Management service not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
throw new IllegalStateException("Notification Management service not initialized.");
|
||||
}
|
||||
return notificationManagementService;
|
||||
}
|
||||
@ -134,25 +93,23 @@ public class WindowsAPIUtils {
|
||||
WindowsDeviceUtils deviceUtils = new WindowsDeviceUtils();
|
||||
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs,
|
||||
message, responseMediaType);
|
||||
getDeviceManagementService().addOperation("windows", operation, deviceIDHolder.getValidDeviceIDList());
|
||||
if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) {
|
||||
return javax.ws.rs.core.Response.status(PluginConstants.StatusCodes.
|
||||
// getDeviceManagementService().addOperation(operation, deviceIDHolder.getValidDeviceIDList());
|
||||
if (!deviceIDHolder.getInvalidDeviceIdList().isEmpty()) {
|
||||
return Response.status(PluginConstants.StatusCodes.
|
||||
MULTI_STATUS_HTTP_CODE).type(
|
||||
responseMediaType).entity(deviceUtils.
|
||||
convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build();
|
||||
convertErrorMapIntoErrorMessage(deviceIDHolder.getInvalidDeviceIdList())).build();
|
||||
}
|
||||
return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.CREATED).
|
||||
return Response.status(Response.Status.CREATED).
|
||||
type(responseMediaType).build();
|
||||
}
|
||||
|
||||
public static PolicyManagerService getPolicyManagerService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
PolicyManagerService policyManagerService = (PolicyManagerService) ctx.getOSGiService(
|
||||
PolicyManagerService.class, null);
|
||||
PolicyManagerService policyManagerService =
|
||||
(PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null);
|
||||
if (policyManagerService == null) {
|
||||
String msg = "Policy Manager service has not initialized";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
throw new IllegalStateException("Policy Manager service has not initialized");
|
||||
}
|
||||
return policyManagerService;
|
||||
}
|
||||
@ -165,6 +122,14 @@ public class WindowsAPIUtils {
|
||||
getDeviceManagementService().updateOperation(deviceIdentifier, operation);
|
||||
}
|
||||
|
||||
public static List<? extends Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException, DeviceManagementException {
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService().getOperationsByDeviceAndStatus(
|
||||
deviceIdentifier, Operation.Status.PENDING);
|
||||
return pendingDataOperations;
|
||||
}
|
||||
|
||||
public static PlatformConfiguration getTenantConfiguration() throws DeviceManagementException {
|
||||
return getDeviceManagementService().getConfiguration(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
@ -172,16 +137,20 @@ public class WindowsAPIUtils {
|
||||
|
||||
public static int getTenantIdOFUser(String username) throws DeviceManagementException {
|
||||
int tenantId = 0;
|
||||
RealmService realmService;
|
||||
String domainName = MultitenantUtils.getTenantDomain(username);
|
||||
if (domainName != null) {
|
||||
try {
|
||||
TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager();
|
||||
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) {
|
||||
String errorMsg = "Error when getting the tenant id from the tenant domain : " +
|
||||
domainName;
|
||||
log.error(errorMsg, e);
|
||||
throw new DeviceManagementException(errorMsg, e);
|
||||
throw new DeviceManagementException("Error when getting the tenant id from the tenant domain : "
|
||||
+ domainName, e);
|
||||
}
|
||||
}
|
||||
return tenantId;
|
||||
@ -192,19 +161,50 @@ public class WindowsAPIUtils {
|
||||
OAuth2TokenValidationService oAuth2TokenValidationService =
|
||||
(OAuth2TokenValidationService) ctx.getOSGiService(OAuth2TokenValidationService.class, null);
|
||||
if (oAuth2TokenValidationService == null) {
|
||||
String msg = "OAuth2TokenValidation service has not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
throw new IllegalStateException("OAuth2TokenValidation service has not initialized.");
|
||||
}
|
||||
return oAuth2TokenValidationService;
|
||||
}
|
||||
|
||||
public static void startTenantFlow(String userName) {
|
||||
public static AuthenticatorConfig getBSTAuthenticatorConfig() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
AuthenticatorConfigService authenticatorConfigService =
|
||||
(AuthenticatorConfigService) ctx.getOSGiService(AuthenticatorConfigService.class, null);
|
||||
AuthenticatorConfig authenticatorConfig = authenticatorConfigService.getAuthenticatorConfig("BST");
|
||||
if (authenticatorConfigService == null) {
|
||||
throw new IllegalStateException("AuthenticatorConfiguration service has not initialized.");
|
||||
}
|
||||
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();
|
||||
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
if (authenticationInfo.getTenantDomain() == null) {
|
||||
privilegedCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
privilegedCarbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
privilegedCarbonContext.setUsername(userName);
|
||||
} 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 = WindowsAPIUtils.getTenantConfiguration()) != null) {
|
||||
return tenantConfiguration.getConfiguration();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -43,8 +43,8 @@ public class WindowsDeviceUtils {
|
||||
message.setResponseMessage("Device identifier list is empty");
|
||||
throw new BadRequestException(message, responseMediaType);
|
||||
}
|
||||
List<String> errorDeviceIdList = new ArrayList<String>();
|
||||
List<DeviceIdentifier> validDeviceIDList = new ArrayList<DeviceIdentifier>();
|
||||
List<String> errorDeviceIdList = new ArrayList<>();
|
||||
List<DeviceIdentifier> validDeviceIDList = new ArrayList<>();
|
||||
int deviceIDCounter = 0;
|
||||
|
||||
for (String deviceID : deviceIDs) {
|
||||
@ -75,11 +75,12 @@ public class WindowsDeviceUtils {
|
||||
}
|
||||
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
|
||||
deviceIDHolder.setValidDeviceIDList(validDeviceIDList);
|
||||
deviceIDHolder.setErrorDeviceIdList(errorDeviceIdList);
|
||||
deviceIDHolder.setInvalidDeviceIdList(errorDeviceIdList);
|
||||
return deviceIDHolder;
|
||||
}
|
||||
|
||||
public String convertErrorMapIntoErrorMessage(List<String> errorDeviceIdList) {
|
||||
return StringUtils.join(errorDeviceIdList.iterator(), COMMA_SEPARATION_PATTERN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,12 +28,9 @@ import java.util.List;
|
||||
/**
|
||||
* Configurations that needs to be added on the device.
|
||||
*/
|
||||
@ApiModel(value = "AddTag", description = "This class carries all information related to Syncml AddTag.")
|
||||
public class AddTag {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandID of the AddTag.", required = true)
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "items", value = "List of items of the AddTag.", required = true)
|
||||
List<Item> items;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
@ -45,11 +40,11 @@ public class AddTag {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@ -62,8 +57,8 @@ public class AddTag {
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
add.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<Item> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
Item item = itemIterator.next();
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext();) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, add);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,12 +25,9 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Inform an event occurred from device to server.
|
||||
*/
|
||||
@ApiModel(value = "Alert",
|
||||
description = "This class carries all information related to Syncml alert.")
|
||||
public class Alert {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandId of The Syncml Alert.", required = true)
|
||||
public class AlertTag {
|
||||
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "data", value = "Data of the AlertTag.", required = true)
|
||||
String data;
|
||||
|
||||
public int getCommandId() {
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,20 +28,16 @@ import java.util.List;
|
||||
/**
|
||||
* Wrapper for other SyncML elements.
|
||||
*/
|
||||
@ApiModel(value = "AtomicTag", description = "This class carries all information related to syncml Engine Atomic tag")
|
||||
public class AtomicTag {
|
||||
@ApiModelProperty(name = "commandId", value = "Syncml Atomic tag CommandId", required = true)
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "adds", value = "List of addtags", required = true)
|
||||
List<AddTag> adds;
|
||||
@ApiModelProperty(name = "replaces", value = "List of replace tags", required = true)
|
||||
List<Replace> replaces;
|
||||
List<ReplaceTag> replaces;
|
||||
|
||||
public List<Replace> getReplaces() {
|
||||
public List<ReplaceTag> getReplaces() {
|
||||
return replaces;
|
||||
}
|
||||
|
||||
public void setReplaces(List<Replace> replaces) {
|
||||
public void setReplaces(List<ReplaceTag> replaces) {
|
||||
this.replaces = replaces;
|
||||
}
|
||||
|
||||
@ -80,8 +74,8 @@ public class AtomicTag {
|
||||
}
|
||||
}
|
||||
if (getReplaces() != null) {
|
||||
for (Iterator<Replace> replaceIterator = getReplaces().iterator(); replaceIterator.hasNext(); ) {
|
||||
Replace add = replaceIterator.next();
|
||||
for (Iterator<ReplaceTag> replaceIterator = getReplaces().iterator(); replaceIterator.hasNext(); ) {
|
||||
ReplaceTag add = replaceIterator.next();
|
||||
if (add != null) {
|
||||
add.buildReplaceElement(doc, atomic);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,10 +25,7 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Challenge data pass through the device and Device Management server for the security purpose.
|
||||
*/
|
||||
@ApiModel(value = "ChallengeTag",
|
||||
description = "This class carries all information related to install application")
|
||||
public class ChallengeTag {
|
||||
@ApiModelProperty(name = "meta", value = "Syncml MetaTag", required = true)
|
||||
MetaTag meta;
|
||||
|
||||
public MetaTag getMeta() {
|
||||
@ -41,11 +36,11 @@ public class ChallengeTag {
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public void buildChallElement(Document doc, Element rootElement) {
|
||||
Element chal = doc.createElement(Constants.CHALLENGE);
|
||||
rootElement.appendChild(chal);
|
||||
public void buildChallengeElement(Document doc, Element rootElement) {
|
||||
Element challenge = doc.createElement(Constants.CHALLENGE);
|
||||
rootElement.appendChild(challenge);
|
||||
if (getMeta() != null) {
|
||||
getMeta().buildMetaElement(doc, chal);
|
||||
getMeta().buildMetaElement(doc, challenge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,12 +25,8 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Credentials passed between the device and the server for security purposes.
|
||||
*/
|
||||
@ApiModel(value = "Credential",
|
||||
description = "This class carries all information related to syncml credentials")
|
||||
public class Credential {
|
||||
@ApiModelProperty(name = "meta", value = "Syncml credential's MetaTag reference.)", required = true)
|
||||
public class CredentialTag {
|
||||
MetaTag meta;
|
||||
@ApiModelProperty(name = "data", value = "Data of the Credential Tag.)", required = true)
|
||||
String data;
|
||||
|
||||
public MetaTag getMeta() {
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,13 +28,9 @@ import java.util.List;
|
||||
/**
|
||||
* Configurations that need to be delete on Device.
|
||||
*/
|
||||
@ApiModel(value = "DeleteTag",
|
||||
description = "This class carries all information related to Syncml DeleteTag.")
|
||||
public class DeleteTag {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandId of the Syncl DeleteTag.", required = true)
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "items", value = "List of items of the syncml DeleteTag. ", required = true)
|
||||
List<Item> items;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
@ -46,11 +40,11 @@ public class DeleteTag {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@ -63,8 +57,8 @@ public class DeleteTag {
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
delete.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<Item> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
Item item = itemIterator.next();
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, delete);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,13 +28,9 @@ import java.util.List;
|
||||
/**
|
||||
* Commands that needs to be executed on the device.
|
||||
*/
|
||||
@ApiModel(value = "ExecuteTag",
|
||||
description = "This class carries all information related to Syncml ExecuteTag.")
|
||||
public class ExecuteTag {
|
||||
@ApiModelProperty(name = "type", value = "CommandId of the syncml ExecuteTag.", required = true)
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "type", value = "List of items of the Syncml ExecuteTag.", required = true)
|
||||
List<Item> items;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
@ -46,11 +40,11 @@ public class ExecuteTag {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@ -63,8 +57,8 @@ public class ExecuteTag {
|
||||
commandId.appendChild(doc.createTextNode(String.valueOf(getCommandId())));
|
||||
exec.appendChild(commandId);
|
||||
}
|
||||
for (Iterator<Item> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
Item item = itemIterator.next();
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, exec);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,13 +28,9 @@ import java.util.List;
|
||||
/**
|
||||
* Data that needs to be retrieved from the device.
|
||||
*/
|
||||
@ApiModel(value = "Get",
|
||||
description = "This class carries all information related to syncml GetTag.")
|
||||
public class Get {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandId of the syncml GetTag.", required = true)
|
||||
public class GetTag {
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "items", value = "List of items of the Syncml GetTag.", required = true)
|
||||
List<Item> items;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
@ -46,11 +40,11 @@ public class Get {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@ -64,8 +58,8 @@ public class Get {
|
||||
get.appendChild(commandId);
|
||||
}
|
||||
if (getItems() != null) {
|
||||
for (Iterator<Item> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
Item item = itemIterator.next();
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, get);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,16 +25,11 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Represents an items that should be retrieved from the device or a command.
|
||||
*/
|
||||
@ApiModel(value = "Item",
|
||||
description = "This class carries all information related to Syncml Item.")
|
||||
public class Item {
|
||||
@ApiModelProperty(name = "target", value = "Target reference value of the Syncml Message(ex:Device).", required = true)
|
||||
Target target;
|
||||
@ApiModelProperty(name = "source", value = "Source reference of the syncml message.(Ex:EMM Server).", required = true)
|
||||
Source source;
|
||||
@ApiModelProperty(name = "data", value = "Content of the syncml message.", required = true)
|
||||
public class ItemTag {
|
||||
|
||||
TargetTag target;
|
||||
SourceTag source;
|
||||
String data;
|
||||
@ApiModelProperty(name = "meta", value = "Meta data of the syncml messsage.", required = true)
|
||||
MetaTag meta;
|
||||
|
||||
public MetaTag getMeta() {
|
||||
@ -55,19 +48,19 @@ public class Item {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Source getSource() {
|
||||
public SourceTag getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Source source) {
|
||||
public void setSource(SourceTag source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public Target getTarget() {
|
||||
public TargetTag getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(Target target) {
|
||||
public void setTarget(TargetTag target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
@ -28,13 +26,10 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* MetaTag data related to credentials.
|
||||
*/
|
||||
@ApiModel(value = "MetaTag", description = "This class carries all information related to MetaTag")
|
||||
public class MetaTag {
|
||||
@ApiModelProperty(name = "format", value = "MetaTag format.)", required = true)
|
||||
|
||||
String format;
|
||||
@ApiModelProperty(name = "type", value = "MetaTag type)", required = true)
|
||||
String type;
|
||||
@ApiModelProperty(name = "nextNonce", value = "Syncml Nextnonce)", required = true)
|
||||
String nextNonce;
|
||||
|
||||
public String getNextNonce() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,13 +28,9 @@ import java.util.List;
|
||||
/**
|
||||
* Commands sent from the device.
|
||||
*/
|
||||
@ApiModel(value = "Replace",
|
||||
description = "This class carries all information related to Syncml ReplaceTag.")
|
||||
public class Replace {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandId of the syncml ReplaceTag.", required = true)
|
||||
public class ReplaceTag {
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "items", value = "List of items of the syncml ReplaceTag.", required = true)
|
||||
List<Item> items;
|
||||
List<ItemTag> items;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
@ -46,11 +40,11 @@ public class Replace {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
public List<ItemTag> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
public void setItems(List<ItemTag> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@ -64,8 +58,8 @@ public class Replace {
|
||||
replace.appendChild(commandId);
|
||||
}
|
||||
if (getItems() != null) {
|
||||
for (Iterator<Item> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
Item item = itemIterator.next();
|
||||
for (Iterator<ItemTag> itemIterator = getItems().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, replace);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,17 +28,11 @@ import java.util.List;
|
||||
/**
|
||||
* Results sent for the requests made to the device.
|
||||
*/
|
||||
@ApiModel(value = "Results",
|
||||
description = "This class carries all information related to Syncml Item.")
|
||||
public class Results {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandID of the Syncml Results Tag.", required = true)
|
||||
public class ResultsTag {
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "messageReference", value = "MessageReference of the Syncml Results Tag.", required = true)
|
||||
int messageReference = -1;
|
||||
@ApiModelProperty(name = "commandReference", value = "CommandReference of the Syncml Results Tag.", required = true)
|
||||
int commandReference = -1;
|
||||
@ApiModelProperty(name = "item", value = "List of Items in Syncml ResultTag.", required = true)
|
||||
List<Item> item;
|
||||
List<ItemTag> item;
|
||||
|
||||
public int getCommandId() {
|
||||
return commandId;
|
||||
@ -66,11 +58,11 @@ public class Results {
|
||||
this.commandReference = commandReference;
|
||||
}
|
||||
|
||||
public List<Item> getItem() {
|
||||
public List<ItemTag> getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(List<Item> item) {
|
||||
public void setItem(List<ItemTag> item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@ -93,8 +85,8 @@ public class Results {
|
||||
results.appendChild(messageReference);
|
||||
}
|
||||
if (getItem() != null) {
|
||||
for (Iterator<Item> itemIterator = getItem().iterator(); itemIterator.hasNext(); ) {
|
||||
Item item = itemIterator.next();
|
||||
for (Iterator<ItemTag> itemIterator = getItem().iterator(); itemIterator.hasNext(); ) {
|
||||
ItemTag item = itemIterator.next();
|
||||
if (item != null) {
|
||||
item.buildItemElement(doc, results);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -28,23 +26,16 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Sequence data that use to execute tag list
|
||||
* Class used to build syncml SequenceTag.
|
||||
*/
|
||||
@ApiModel(value = "SequenceTag",
|
||||
description = "This class carries all information related to Syncml SequenceTag.")
|
||||
public class SequenceTag {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandId of the Syncml SequenceTag", required = true)
|
||||
|
||||
int commandId;
|
||||
@ApiModelProperty(name = "exec", value = "ExcecuteTag sequence of the Syncml SequenceTag", required = true)
|
||||
ExecuteTag exec;
|
||||
@ApiModelProperty(name = "get", value = "GetTag of the syncml SequenceTag.", required = true)
|
||||
Get get;
|
||||
@ApiModelProperty(name = "deleteTag", value = "DeleteTag of the syncml SequenceTag.", required = true)
|
||||
GetTag get;
|
||||
DeleteTag deleteTag;
|
||||
@ApiModelProperty(name = "atomicTag", value = "AtomicTag sequence of the syncml SequenceTag.", required = true)
|
||||
AtomicTag atomicTag;
|
||||
@ApiModelProperty(name = "replaces", value = "ReplaceTag of the syncml SequenceTag.", required = true)
|
||||
List<Replace> replaces;
|
||||
List<ReplaceTag> replaces;
|
||||
|
||||
public DeleteTag getDeleteTag() {
|
||||
return deleteTag;
|
||||
@ -54,11 +45,11 @@ public class SequenceTag {
|
||||
this.deleteTag = deleteTag;
|
||||
}
|
||||
|
||||
public List<Replace> getReplaces() {
|
||||
public List<ReplaceTag> getReplaces() {
|
||||
return replaces;
|
||||
}
|
||||
|
||||
public void setReplaces(List<Replace> replaces) {
|
||||
public void setReplaces(List<ReplaceTag> replaces) {
|
||||
this.replaces = replaces;
|
||||
}
|
||||
|
||||
@ -86,11 +77,11 @@ public class SequenceTag {
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
public Get getGet() {
|
||||
public GetTag getGet() {
|
||||
return get;
|
||||
}
|
||||
|
||||
public void setGet(Get get) {
|
||||
public void setGet(GetTag get) {
|
||||
this.get = get;
|
||||
}
|
||||
|
||||
@ -109,18 +100,19 @@ public class SequenceTag {
|
||||
getGet().buildGetElement(doc, sequence);
|
||||
}
|
||||
if (getReplaces() != null) {
|
||||
for (Iterator<Replace> replaceIterator = getReplaces().iterator(); replaceIterator.hasNext(); ) {
|
||||
Replace replace = replaceIterator.next();
|
||||
for (Iterator<ReplaceTag> replaceIterator = getReplaces().iterator(); replaceIterator.hasNext(); ) {
|
||||
ReplaceTag replace = replaceIterator.next();
|
||||
if (replace != null) {
|
||||
replace.buildReplaceElement(doc, sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getAtomicTag() != null) {
|
||||
getAtomicTag().buildAtomicElement(doc, sequence);
|
||||
}
|
||||
if (getDeleteTag() != null) {
|
||||
getDeleteTag().buildDeleteElement(doc, sequence);
|
||||
}
|
||||
if (getAtomicTag() != null) {
|
||||
getAtomicTag().buildAtomicElement(doc, sequence);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,28 +25,25 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Source details of syncml header's.
|
||||
*/
|
||||
@ApiModel(value = "Source",
|
||||
description = "This class carries all information related to Syncml source.")
|
||||
public class Source {
|
||||
@ApiModelProperty(name = "LocURI", value = "Location URI.(Source Location:Device)", required = true)
|
||||
private String LocURI;
|
||||
@ApiModelProperty(name = "LocName", value = "Name of the location", required = true)
|
||||
private String LocName;
|
||||
public class SourceTag {
|
||||
|
||||
private String locURI;
|
||||
private String locName;
|
||||
|
||||
public String getLocURI() {
|
||||
return LocURI;
|
||||
return locURI;
|
||||
}
|
||||
|
||||
public void setLocURI(String locURI) {
|
||||
LocURI = locURI;
|
||||
this.locURI = locURI;
|
||||
}
|
||||
|
||||
public String getLocName() {
|
||||
return LocName;
|
||||
return locName;
|
||||
}
|
||||
|
||||
public void setLocName(String locName) {
|
||||
LocName = locName;
|
||||
this.locName = locName;
|
||||
}
|
||||
|
||||
public void buildSourceElement(Document doc, Element rootElement) {
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,25 +25,16 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Status of a previously sent message to device;
|
||||
*/
|
||||
@ApiModel(value = "Status",
|
||||
description = "This class carries all information related to Syncml Device statuses.")
|
||||
public class Status {
|
||||
@ApiModelProperty(name = "commandId", value = "CommandId of the Syncml StatusTag.", required = true)
|
||||
public class StatusTag {
|
||||
int commandId = -1;
|
||||
@ApiModelProperty(name = "messageReference", value = "Message referenceId.", required = true)
|
||||
int messageReference = -1;
|
||||
@ApiModelProperty(name = "commandReference", value = "Command referenceId.", required = true)
|
||||
int commandReference = -1;
|
||||
@ApiModelProperty(name = "command", value = "Command String.", required = true)
|
||||
String command;
|
||||
@ApiModelProperty(name = "targetReference", value = "Target reference of the status message.", required = true)
|
||||
String targetReference;
|
||||
@ApiModelProperty(name = "data", value = "Status data of the message.(ex:200,404,500...)", required = true)
|
||||
String data;
|
||||
@ApiModelProperty(name = "challenge", value = "Challenge value.", required = true)
|
||||
ChallengeTag challenge;
|
||||
|
||||
public Status(int commandId, int messageReference, int commandReference, String command,
|
||||
public StatusTag(int commandId, int messageReference, int commandReference, String command,
|
||||
String targetReference, String data) {
|
||||
this.commandId = commandId;
|
||||
this.messageReference = messageReference;
|
||||
@ -55,7 +44,7 @@ public class Status {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Status() {
|
||||
public StatusTag() {
|
||||
}
|
||||
|
||||
public ChallengeTag getChallenge() {
|
||||
@ -143,7 +132,7 @@ public class Status {
|
||||
status.appendChild(targetReference);
|
||||
}
|
||||
if (getChallenge() != null) {
|
||||
getChallenge().buildChallElement(doc, status);
|
||||
getChallenge().buildChallengeElement(doc, status);
|
||||
}
|
||||
if (getData() != null) {
|
||||
Element data = doc.createElement(Constants.DATA);
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -30,23 +28,14 @@ import java.util.List;
|
||||
/**
|
||||
* Represents the body details of a syncml.
|
||||
*/
|
||||
@ApiModel(value = "SyncmlBody", description = "This class carries all information related to SyncmlBody.")
|
||||
public class SyncmlBody {
|
||||
@ApiModelProperty(name = "getCommands", value = "Get value of the syncmlBody.", required = true)
|
||||
Get getCommands;
|
||||
@ApiModelProperty(name = "exec", value = "List of executeTags in syncmlBody.", required = true)
|
||||
GetTag getCommands;
|
||||
List<ExecuteTag> exec;
|
||||
@ApiModelProperty(name = "status", value = "List of statusTags in syncmlBody.", required = true)
|
||||
List<Status> status;
|
||||
@ApiModelProperty(name = "alert", value = "Alert tag in syncmlBody.", required = true)
|
||||
Alert alert;
|
||||
@ApiModelProperty(name = "replace", value = "replace tag in syncmlBody.", required = true)
|
||||
Replace replace;
|
||||
@ApiModelProperty(name = "results", value = "Results tag in syncmlBody.", required = true)
|
||||
Results results;
|
||||
@ApiModelProperty(name = "sequence", value = "Sequence tag in syncmlBody.", required = true)
|
||||
List<StatusTag> status;
|
||||
AlertTag alert;
|
||||
ReplaceTag replace;
|
||||
ResultsTag results;
|
||||
SequenceTag sequence;
|
||||
@ApiModelProperty(name = "atomicTag", value = "Atomic tag in syncmlBody.", required = true)
|
||||
AtomicTag atomicTag;
|
||||
|
||||
public AtomicTag getAtomicTag() {
|
||||
@ -73,43 +62,43 @@ public class SyncmlBody {
|
||||
this.exec = exec;
|
||||
}
|
||||
|
||||
public Results getResults() {
|
||||
public ResultsTag getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(Results results) {
|
||||
public void setResults(ResultsTag results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
public Replace getReplace() {
|
||||
public ReplaceTag getReplace() {
|
||||
return replace;
|
||||
}
|
||||
|
||||
public void setReplace(Replace replace) {
|
||||
public void setReplace(ReplaceTag replace) {
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
public List<Status> getStatus() {
|
||||
public List<StatusTag> getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(List<Status> status) {
|
||||
public void setStatus(List<StatusTag> status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Alert getAlert() {
|
||||
public AlertTag getAlert() {
|
||||
return alert;
|
||||
}
|
||||
|
||||
public void setAlert(Alert alert) {
|
||||
public void setAlert(AlertTag alert) {
|
||||
this.alert = alert;
|
||||
}
|
||||
|
||||
public Get getGet() {
|
||||
public GetTag getGet() {
|
||||
return getCommands;
|
||||
}
|
||||
|
||||
public void setGet(Get get) {
|
||||
public void setGet(GetTag get) {
|
||||
this.getCommands = get;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,19 +18,14 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Represents a base format of a syncml document
|
||||
*/
|
||||
@ApiModel(value = "SyncmlDocument", description = "This class carries all information related to SyncmlDocument.")
|
||||
public class SyncmlDocument {
|
||||
@ApiModelProperty(name = "header", value = "Header of the syncmlDocument.", required = true)
|
||||
SyncmlHeader header;
|
||||
@ApiModelProperty(name = "body", value = "Body of the SyncmlDocument.", required = true)
|
||||
SyncmlBody body;
|
||||
|
||||
public SyncmlHeader getHeader() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,19 +25,12 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Represents the header details of a syncml.
|
||||
*/
|
||||
@ApiModel(value = "SyncmlHeader", description = "This class carries all information related to SyncmlHeader.")
|
||||
public class SyncmlHeader {
|
||||
@ApiModelProperty(name = "sessionId", value = "SessionId of the syncml Message.", required = true)
|
||||
private int sessionId = -1;
|
||||
@ApiModelProperty(name = "MsgID", value = "MessageId of the syncml Session.", required = true)
|
||||
private int MsgID = -1;
|
||||
@ApiModelProperty(name = "target", value = "Target of the syncml Message.(Ex:Device/Server.)", required = true)
|
||||
private Target target;
|
||||
@ApiModelProperty(name = "source", value = "Source of the Syncml Message.(Ex:Server/Device.)", required = true)
|
||||
private Source source;
|
||||
@ApiModelProperty(name = "credential", value = "Credentials of the Syncml header.", required = true)
|
||||
private Credential credential;
|
||||
@ApiModelProperty(name = "hexadecimalSessionId", value = "HexaDecimal SessionId of the syncmlHeader.", required = true)
|
||||
private TargetTag target;
|
||||
private SourceTag source;
|
||||
private CredentialTag credential;
|
||||
private String hexadecimalSessionId;
|
||||
|
||||
public String getHexadecimalSessionId() {
|
||||
@ -50,11 +41,11 @@ public class SyncmlHeader {
|
||||
this.hexadecimalSessionId = hexSessionId;
|
||||
}
|
||||
|
||||
public Credential getCredential() {
|
||||
public CredentialTag getCredential() {
|
||||
return credential;
|
||||
}
|
||||
|
||||
public void setCredential(Credential credential) {
|
||||
public void setCredential(CredentialTag credential) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
@ -74,19 +65,19 @@ public class SyncmlHeader {
|
||||
this.MsgID = msgID;
|
||||
}
|
||||
|
||||
public Target getTarget() {
|
||||
public TargetTag getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(Target target) {
|
||||
public void setTarget(TargetTag target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Source getSource() {
|
||||
public SourceTag getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Source source) {
|
||||
public void setSource(SourceTag source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
@ -27,11 +25,9 @@ import org.wso2.carbon.mdm.mobileservices.windows.operations.util.Constants;
|
||||
/**
|
||||
* Target details of syncml header's.
|
||||
*/
|
||||
@ApiModel(value = "Target", description = "This class carries all information related to Syncml Target.")
|
||||
public class Target {
|
||||
@ApiModelProperty(name = "LocURI", value = "Location URI of the target.", required = true)
|
||||
public class TargetTag {
|
||||
|
||||
private String LocURI;
|
||||
@ApiModelProperty(name = "LocName", value = "Location Name of the target.", required = true)
|
||||
private String LocName;
|
||||
|
||||
public String getLocURI() {
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -22,7 +22,6 @@ package org.wso2.carbon.mdm.mobileservices.windows.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=";
|
||||
@ -35,8 +34,6 @@ public class Constants {
|
||||
public static final String UTF_8 = "UTF-8";
|
||||
public static final String MD5 = "MD5";
|
||||
public static final String YES = "yes";
|
||||
public static final String ERROR = "Error";
|
||||
public static final String INFORMATION = "information";
|
||||
|
||||
public static final String EXECUTE = "Exec";
|
||||
public static final String ATOMIC = "Atomic";
|
||||
@ -82,17 +79,26 @@ public class Constants {
|
||||
public static final String META_FORMAT_CHARACTER = "chr";
|
||||
|
||||
/**
|
||||
* SynclML service related constants
|
||||
* 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 ACCEPTED_FOR_PROCESSING = "202";
|
||||
public static final String PIN_NOTFOUND = "405";
|
||||
public static final String CREDENTIALS_MISSING = "407";
|
||||
public static final String INVALID_CREDENTIALS = "401";
|
||||
public static final String LOCKRESET_NOTIFICATION = "Error occurred in Device Lock Operation. " +
|
||||
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,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -31,7 +31,7 @@ public class OperationCode {
|
||||
IMSI("./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMSI"),
|
||||
IMEI("./Vendor/MSFT/DeviceInstanceService/Identity/Identity1/IMEI"),
|
||||
SOFTWARE_VERSION("./DevDetail/SwV"),
|
||||
VENDER("./DevDetail/OEM"),
|
||||
VENDOR("./DevDetail/OEM"),
|
||||
MAC_ADDRESS("./DevDetail/Ext/WLANMACAddress"),
|
||||
RESOLUTION("./DevDetail/Ext/Microsoft/Resolution"),
|
||||
DEVICE_NAME("./DevDetail/Ext/Microsoft/DeviceName"),
|
||||
@ -68,7 +68,8 @@ public class OperationCode {
|
||||
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_PASSWORD_ENABLE("./Vendor/MSFT/PolicyManager/My/DeviceLock/DevicePasswordEnabled"),
|
||||
DEVICE_PASSCODE_DELETE("./Vendor/MSFT/PolicyManager/My/DeviceLock");
|
||||
|
||||
private final String code;
|
||||
|
||||
|
||||
@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.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.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.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.*;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils.convertToDeviceIdentifierObject;
|
||||
|
||||
/**
|
||||
* This class is used to handle pending operations of the device.
|
||||
*/
|
||||
public class OperationHandler {
|
||||
private static Log log = LogFactory.getLog(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() && (OperationCode.Command.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.setDeviceIdentifier(deviceIdentifier);
|
||||
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.setDeviceIdentifier(deviceIdentifier);
|
||||
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.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.equals(operation.getCode())) &&
|
||||
(operation.getId() == status.getCommandReference())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
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 {
|
||||
|
||||
List<? extends Operation> pendingOperations;
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
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.equals(status.getTargetReference()))) {
|
||||
updateLockOperation(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
if ((OperationCode.Command.DEVICE_RING.equals(status.getTargetReference()))) {
|
||||
ring(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
if (equals(OperationCode.Command.WIPE_DATA.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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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.setDeviceIdentifier(deviceIdentifier);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -77,20 +77,20 @@ public class OperationReply {
|
||||
}
|
||||
|
||||
private void generateHeader() throws SyncmlMessageFormatException {
|
||||
String nextnonceValue = Constants.INITIAL_NONCE;
|
||||
String nextNonceValue = Constants.INITIAL_NONCE;
|
||||
SyncmlHeader sourceHeader = syncmlDocument.getHeader();
|
||||
SyncmlHeader header = new SyncmlHeader();
|
||||
header.setMsgID(sourceHeader.getMsgID());
|
||||
header.setHexadecimalSessionId(Integer.toHexString(sourceHeader.getSessionId()));
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(sourceHeader.getSource().getLocURI());
|
||||
header.setTarget(target);
|
||||
|
||||
Source source = new Source();
|
||||
SourceTag source = new SourceTag();
|
||||
source.setLocURI(sourceHeader.getTarget().getLocURI());
|
||||
header.setSource(source);
|
||||
|
||||
Credential cred = new Credential();
|
||||
CredentialTag cred = new CredentialTag();
|
||||
if (sourceHeader.getCredential() == null) {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.CRED_FORMAT);
|
||||
@ -100,15 +100,15 @@ public class OperationReply {
|
||||
cred.setMeta(sourceHeader.getCredential().getMeta());
|
||||
}
|
||||
SyncmlBody sourcebody = syncmlDocument.getBody();
|
||||
List<Status> statuses = sourcebody.getStatus();
|
||||
List<StatusTag> statuses = sourcebody.getStatus();
|
||||
|
||||
for (Status status : statuses) {
|
||||
for (StatusTag status : statuses) {
|
||||
if (HEADER_COMMAND_TEXT.equals(status.getCommand()) &&
|
||||
status.getChallenge() != null) {
|
||||
nextnonceValue = status.getChallenge().getMeta().getNextNonce();
|
||||
nextNonceValue = status.getChallenge().getMeta().getNextNonce();
|
||||
}
|
||||
}
|
||||
cred.setData(new SyncmlCredentials().generateCredData(nextnonceValue));
|
||||
cred.setData(SyncmlCredentialUtil.generateCredData(nextNonceValue));
|
||||
header.setCredential(cred);
|
||||
|
||||
replySyncmlDocument.setHeader(header);
|
||||
@ -131,22 +131,22 @@ public class OperationReply {
|
||||
private SyncmlBody generateStatuses() {
|
||||
SyncmlBody sourceSyncmlBody = syncmlDocument.getBody();
|
||||
SyncmlHeader sourceHeader = syncmlDocument.getHeader();
|
||||
Status headerStatus;
|
||||
StatusTag headerStatus;
|
||||
SyncmlBody syncmlBodyReply = new SyncmlBody();
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
List<Status> sourceStatuses = sourceSyncmlBody.getStatus();
|
||||
List<StatusTag> statuses = new ArrayList<>();
|
||||
List<StatusTag> sourceStatuses = sourceSyncmlBody.getStatus();
|
||||
if (sourceStatuses.isEmpty()) {
|
||||
headerStatus =
|
||||
new Status(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID,
|
||||
new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID,
|
||||
HEADER_COMMAND_TEXT, sourceHeader.getSource().getLocURI(),
|
||||
String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED));
|
||||
statuses.add(headerStatus);
|
||||
} else {
|
||||
for (Status sourceStatus : sourceStatuses) {
|
||||
for (StatusTag sourceStatus : sourceStatuses) {
|
||||
if (sourceStatus.getChallenge() != null && HEADER_COMMAND_TEXT.equals(sourceStatus.getCommand())) {
|
||||
|
||||
headerStatus =
|
||||
new Status(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID,
|
||||
new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID,
|
||||
HEADER_COMMAND_TEXT, sourceHeader.getSource().getLocURI(),
|
||||
String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED));
|
||||
statuses.add(headerStatus);
|
||||
@ -155,14 +155,14 @@ public class OperationReply {
|
||||
}
|
||||
if (sourceSyncmlBody.getResults() != null) {
|
||||
int ResultCommandId = ++headerCommandId;
|
||||
Status resultStatus = new Status(ResultCommandId, sourceHeader.getMsgID(),
|
||||
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;
|
||||
Status alertStatus = new Status(alertCommandId,
|
||||
StatusTag alertStatus = new StatusTag(alertCommandId,
|
||||
sourceHeader.getMsgID(),
|
||||
sourceSyncmlBody.getAlert().getCommandId(),
|
||||
ALERT_COMMAND_TEXT, null,
|
||||
@ -171,7 +171,7 @@ public class OperationReply {
|
||||
}
|
||||
if (sourceSyncmlBody.getReplace() != null) {
|
||||
int replaceCommandId = ++headerCommandId;
|
||||
Status replaceStatus = new Status(replaceCommandId, sourceHeader.getMsgID(),
|
||||
StatusTag replaceStatus = new StatusTag(replaceCommandId, sourceHeader.getMsgID(),
|
||||
sourceSyncmlBody.getReplace().getCommandId(), REPLACE_COMMAND_TEXT, null,
|
||||
String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED)
|
||||
);
|
||||
@ -181,7 +181,7 @@ public class OperationReply {
|
||||
List<ExecuteTag> Executes = sourceSyncmlBody.getExec();
|
||||
for (ExecuteTag exec : Executes) {
|
||||
int execCommandId = ++headerCommandId;
|
||||
Status execStatus = new Status(execCommandId, sourceHeader.getMsgID(),
|
||||
StatusTag execStatus = new StatusTag(execCommandId, sourceHeader.getMsgID(),
|
||||
exec.getCommandId(), EXEC_COMMAND_TEXT, null, String.valueOf(
|
||||
Constants.SyncMLResponseCodes.ACCEPTED));
|
||||
statuses.add(execStatus);
|
||||
@ -189,7 +189,7 @@ public class OperationReply {
|
||||
}
|
||||
if (sourceSyncmlBody.getGet() != null) {
|
||||
int getCommandId = ++headerCommandId;
|
||||
Status execStatus = new Status(getCommandId, sourceHeader.getMsgID(), sourceSyncmlBody
|
||||
StatusTag execStatus = new StatusTag(getCommandId, sourceHeader.getMsgID(), sourceSyncmlBody
|
||||
.getGet().getCommandId(), GET_COMMAND_TEXT, null, String.valueOf(
|
||||
Constants.SyncMLResponseCodes.ACCEPTED));
|
||||
statuses.add(execStatus);
|
||||
@ -200,13 +200,13 @@ public class OperationReply {
|
||||
|
||||
private void appendOperations(SyncmlBody syncmlBody) throws PolicyManagementException,
|
||||
FeatureManagementException, JSONException, SyncmlOperationException {
|
||||
Get getElement = new Get();
|
||||
List<Item> getElements = new ArrayList<>();
|
||||
GetTag getElement = new GetTag();
|
||||
List<ItemTag> getElements = new ArrayList<>();
|
||||
List<ExecuteTag> executeElements = new ArrayList<>();
|
||||
AtomicTag atomicTagElement = new AtomicTag();
|
||||
List<AddTag> addElements = new ArrayList<>();
|
||||
Replace replaceElement = new Replace();
|
||||
List<Item> replaceItems = new ArrayList<>();
|
||||
ReplaceTag replaceElement = new ReplaceTag();
|
||||
List<ItemTag> replaceItems = new ArrayList<>();
|
||||
SequenceTag monitorSequence = new SequenceTag();
|
||||
|
||||
if (operations != null) {
|
||||
@ -215,8 +215,8 @@ public class OperationReply {
|
||||
switch (type) {
|
||||
case POLICY:
|
||||
if (this.syncmlDocument.getBody().getAlert() != null) {
|
||||
if (this.syncmlDocument.getBody().getAlert().getData().equals
|
||||
(Constants.INITIAL_ALERT_DATA)) {
|
||||
if ((Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody()
|
||||
.getAlert().getData()))) {
|
||||
SequenceTag policySequence = new SequenceTag();
|
||||
policySequence = buildSequence(operation, policySequence);
|
||||
syncmlBody.setSequence(policySequence);
|
||||
@ -233,46 +233,40 @@ public class OperationReply {
|
||||
|
||||
break;
|
||||
case INFO:
|
||||
Item itemGet = appendGetInfo(operation);
|
||||
ItemTag itemGet = appendGetInfo(operation);
|
||||
getElements.add(itemGet);
|
||||
break;
|
||||
case COMMAND:
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.DEVICE_LOCK)) {
|
||||
ExecuteTag execElement = executeCommand(operation);
|
||||
ExecuteTag execElement;
|
||||
if ((PluginConstants.OperationCodes.DEVICE_LOCK.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.DEVICE_RING)) {
|
||||
ExecuteTag execElement = executeCommand(operation);
|
||||
if ((PluginConstants.OperationCodes.DEVICE_RING.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.DISENROLL)) {
|
||||
ExecuteTag execElement = executeCommand(operation);
|
||||
if ((PluginConstants.OperationCodes.DISENROLL.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.WIPE_DATA)) {
|
||||
ExecuteTag execElement = executeCommand(operation);
|
||||
if ((PluginConstants.OperationCodes.WIPE_DATA.equals(operation.getCode()))) {
|
||||
execElement = executeCommand(operation);
|
||||
executeElements.add(execElement);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.LOCK_RESET)) {
|
||||
if ((PluginConstants.OperationCodes.LOCK_RESET.equals(operation.getCode()))) {
|
||||
SequenceTag sequenceElement = new SequenceTag();
|
||||
SequenceTag sequence = buildSequence(operation, sequenceElement);
|
||||
syncmlBody.setSequence(sequence);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.MONITOR)) {
|
||||
|
||||
Get monitorGetElement = new Get();
|
||||
List<Item> monitorItems;
|
||||
if ((PluginConstants.OperationCodes.MONITOR.equals(operation.getCode()))) {
|
||||
GetTag monitorGetElement = new GetTag();
|
||||
List<ItemTag> monitorItems;
|
||||
List<ProfileFeature> profileFeatures;
|
||||
|
||||
if (this.syncmlDocument.getBody().getAlert() != null) {
|
||||
if (this.syncmlDocument.getBody().getAlert().getData().equals
|
||||
(Constants.INITIAL_ALERT_DATA)) {
|
||||
if (Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody().
|
||||
getAlert().getData())) {
|
||||
|
||||
monitorSequence.setCommandId(operation.getId());
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
@ -298,15 +292,15 @@ public class OperationReply {
|
||||
}
|
||||
}
|
||||
if (!replaceItems.isEmpty()) {
|
||||
replaceElement.setCommandId(300);
|
||||
replaceElement.setCommandId(Constants.SyncmlMessageCodes.replaceCommandId);
|
||||
replaceElement.setItems(replaceItems);
|
||||
}
|
||||
if (!getElements.isEmpty()) {
|
||||
getElement.setCommandId(75);
|
||||
getElement.setCommandId(Constants.SyncmlMessageCodes.elementCommandId);
|
||||
getElement.setItems(getElements);
|
||||
}
|
||||
if (!addElements.isEmpty()) {
|
||||
atomicTagElement.setCommandId(400);
|
||||
atomicTagElement.setCommandId(Constants.SyncmlMessageCodes.atomicCommandId);
|
||||
atomicTagElement.setAdds(addElements);
|
||||
}
|
||||
syncmlBody.setGet(getElement);
|
||||
@ -315,15 +309,15 @@ public class OperationReply {
|
||||
syncmlBody.setReplace(replaceElement);
|
||||
}
|
||||
|
||||
private Item appendExecInfo(Operation operation) {
|
||||
Item item = new Item();
|
||||
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())) {
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(command.getCode());
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.DISENROLL)) {
|
||||
if ((PluginConstants
|
||||
.OperationCodes.DISENROLL.equals(operation.getCode()))) {
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_CHARACTER);
|
||||
item.setMeta(meta);
|
||||
@ -335,22 +329,22 @@ public class OperationReply {
|
||||
return item;
|
||||
}
|
||||
|
||||
private Item appendGetInfo(Operation operation) {
|
||||
Item item = new 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())) {
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(info.getCode());
|
||||
item.setTarget(target);
|
||||
}
|
||||
}
|
||||
if ((operationCode != null) && operationCode.equals(
|
||||
PluginConstants.OperationCodes.LOCK_RESET)) {
|
||||
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())) {
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(getInfo.getCode());
|
||||
item.setTarget(target);
|
||||
}
|
||||
@ -359,11 +353,11 @@ public class OperationReply {
|
||||
return item;
|
||||
}
|
||||
|
||||
private Item appendReplaceInfo(Operation operation) throws JSONException {
|
||||
private ItemTag appendReplaceInfo(Operation operation) throws JSONException {
|
||||
String policyAllowData = "1";
|
||||
String policyDisallowData = "0";
|
||||
Item item = new Item();
|
||||
Target target = new Target();
|
||||
ItemTag item = new ItemTag();
|
||||
TargetTag target = new TargetTag();
|
||||
String operationCode = operation.getCode();
|
||||
JSONObject payload = new JSONObject(operation.getPayLoad().toString());
|
||||
for (Command command : Command.values()) {
|
||||
@ -371,8 +365,7 @@ public class OperationReply {
|
||||
if (operationCode != null && operationCode.equals(command.name())) {
|
||||
target.setLocURI(command.getCode());
|
||||
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.CAMERA)) {
|
||||
if ((PluginConstants.OperationCodes.CAMERA.equals(operation.getCode()))) {
|
||||
|
||||
if (payload.getBoolean("enabled")) {
|
||||
MetaTag meta = new MetaTag();
|
||||
@ -388,8 +381,8 @@ public class OperationReply {
|
||||
item.setData(policyDisallowData);
|
||||
}
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants
|
||||
.OperationCodes.ENCRYPT_STORAGE)) {
|
||||
if ((PluginConstants.OperationCodes.ENCRYPT_STORAGE.
|
||||
equals(operation.getCode()))) {
|
||||
|
||||
if (payload.getBoolean("encrypted")) {
|
||||
MetaTag meta = new MetaTag();
|
||||
@ -415,7 +408,7 @@ public class OperationReply {
|
||||
List<AddTag> addList = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.PASSCODE_POLICY)) {
|
||||
if ((PluginConstants.OperationCodes.PASSCODE_POLICY.equals(operation.getCode()))) {
|
||||
|
||||
PasscodePolicy passcodeObject = gson.fromJson((String) operation.getPayLoad(), PasscodePolicy.class);
|
||||
|
||||
@ -489,11 +482,11 @@ public class OperationReply {
|
||||
|
||||
MetaTag meta = new MetaTag();
|
||||
meta.setFormat(Constants.META_FORMAT_CHARACTER);
|
||||
List<Item> items = new ArrayList<>();
|
||||
List<ItemTag> items = new ArrayList<>();
|
||||
|
||||
for (Configure configure : Configure.values()) {
|
||||
if (operationCode != null && operationCode.equals(configure.name())) {
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
target.setLocURI(configure.getCode());
|
||||
items.get(0).setTarget(target);
|
||||
}
|
||||
@ -512,8 +505,8 @@ public class OperationReply {
|
||||
public ExecuteTag executeCommand(Operation operation) {
|
||||
ExecuteTag execElement = new ExecuteTag();
|
||||
execElement.setCommandId(operation.getId());
|
||||
List<Item> itemsExec = new ArrayList<>();
|
||||
Item itemExec = appendExecInfo(operation);
|
||||
List<ItemTag> itemsExec = new ArrayList<>();
|
||||
ItemTag itemExec = appendExecInfo(operation);
|
||||
itemsExec.add(itemExec);
|
||||
execElement.setItems(itemsExec);
|
||||
return execElement;
|
||||
@ -523,14 +516,14 @@ public class OperationReply {
|
||||
JSONException, SyncmlOperationException {
|
||||
|
||||
sequenceElement.setCommandId(operation.getId());
|
||||
List<Replace> replaceItems = new ArrayList<>();
|
||||
List<ReplaceTag> replaceItems = new ArrayList<>();
|
||||
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.LOCK_RESET)) {
|
||||
if ((PluginConstants.OperationCodes.LOCK_RESET.equals(operation.getCode()))) {
|
||||
ExecuteTag execElement = executeCommand(operation);
|
||||
Get getElements = new Get();
|
||||
GetTag getElements = new GetTag();
|
||||
getElements.setCommandId(operation.getId());
|
||||
List<Item> getItems = new ArrayList<>();
|
||||
Item itemGets = appendGetInfo(operation);
|
||||
List<ItemTag> getItems = new ArrayList<>();
|
||||
ItemTag itemGets = appendGetInfo(operation);
|
||||
getItems.add(itemGets);
|
||||
getElements.setItems(getItems);
|
||||
|
||||
@ -538,7 +531,7 @@ public class OperationReply {
|
||||
sequenceElement.setGet(getElements);
|
||||
return sequenceElement;
|
||||
|
||||
} else if (operation.getCode().equals(PluginConstants.OperationCodes.POLICY_BUNDLE)) {
|
||||
} else if ((PluginConstants.OperationCodes.POLICY_BUNDLE.equals(operation.getCode()))) {
|
||||
List<? extends Operation> policyOperations;
|
||||
try {
|
||||
policyOperations = (List<? extends Operation>) operation.getPayLoad();
|
||||
@ -546,10 +539,12 @@ public class OperationReply {
|
||||
throw new ClassCastException();
|
||||
}
|
||||
for (Operation policy : policyOperations) {
|
||||
if (policy.getCode().equals(PluginConstants.OperationCodes.CAMERA)) {
|
||||
Replace replaceCameraConfig = new Replace();
|
||||
Item cameraItem;
|
||||
List<Item> cameraItems = new ArrayList<>();
|
||||
|
||||
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);
|
||||
@ -560,11 +555,11 @@ public class OperationReply {
|
||||
replaceCameraConfig.setItems(cameraItems);
|
||||
replaceItems.add(replaceCameraConfig);
|
||||
}
|
||||
if (policy.getCode().equals(PluginConstants.OperationCodes.ENCRYPT_STORAGE)) {
|
||||
if ((PluginConstants.OperationCodes.ENCRYPT_STORAGE.equals(policy.getCode()))) {
|
||||
|
||||
Replace replaceStorageConfig = new Replace();
|
||||
Item storageItem;
|
||||
List<Item> storageItems = new ArrayList<>();
|
||||
ReplaceTag replaceStorageConfig = new ReplaceTag();
|
||||
ItemTag storageItem;
|
||||
List<ItemTag> storageItems = new ArrayList<>();
|
||||
try {
|
||||
storageItem = appendReplaceInfo(policy);
|
||||
storageItems.add(storageItem);
|
||||
@ -576,14 +571,18 @@ public class OperationReply {
|
||||
replaceItems.add(replaceStorageConfig);
|
||||
|
||||
}
|
||||
if (policy.getCode().equals(PluginConstants.OperationCodes.PASSCODE_POLICY)) {
|
||||
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);
|
||||
@ -600,69 +599,70 @@ public class OperationReply {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Item> buildMonitorOperation(List<ProfileFeature> effectiveMonitoringFeature) {
|
||||
List<Item> monitorItems = new ArrayList<>();
|
||||
public List<ItemTag> buildMonitorOperation(List<ProfileFeature> effectiveMonitoringFeature) {
|
||||
List<ItemTag> monitorItems = new ArrayList<>();
|
||||
Operation monitorOperation;
|
||||
for (ProfileFeature profileFeature : effectiveMonitoringFeature) {
|
||||
|
||||
if (profileFeature.getFeatureCode().equals(PluginConstants
|
||||
.OperationCodes.CAMERA)) {
|
||||
if ((PluginConstants.OperationCodes.CAMERA.equals
|
||||
(profileFeature.getFeatureCode()))) {
|
||||
String cameraStatus = PluginConstants
|
||||
.OperationCodes.CAMERA_STATUS;
|
||||
|
||||
monitorOperation = new Operation();
|
||||
monitorOperation.setCode(cameraStatus);
|
||||
Item item = appendGetInfo(monitorOperation);
|
||||
ItemTag item = appendGetInfo(monitorOperation);
|
||||
monitorItems.add(item);
|
||||
}
|
||||
if (profileFeature.getFeatureCode().equals(PluginConstants
|
||||
.OperationCodes.ENCRYPT_STORAGE)) {
|
||||
if (PluginConstants.OperationCodes.ENCRYPT_STORAGE.equals
|
||||
(profileFeature.getFeatureCode())) {
|
||||
String encryptStorageStatus = PluginConstants
|
||||
.OperationCodes.ENCRYPT_STORAGE_STATUS;
|
||||
|
||||
monitorOperation = new Operation();
|
||||
monitorOperation.setCode(encryptStorageStatus);
|
||||
Item item = appendGetInfo(monitorOperation);
|
||||
ItemTag item = appendGetInfo(monitorOperation);
|
||||
monitorItems.add(item);
|
||||
}
|
||||
if (profileFeature.getFeatureCode().equals(PluginConstants
|
||||
.OperationCodes.PASSCODE_POLICY)) {
|
||||
if ((PluginConstants.OperationCodes.PASSCODE_POLICY.equals
|
||||
(profileFeature.getFeatureCode()))) {
|
||||
String passcodeStatus = PluginConstants
|
||||
.OperationCodes.DEVICE_PASSWORD_STATUS;
|
||||
|
||||
monitorOperation = new Operation();
|
||||
monitorOperation.setCode(passcodeStatus);
|
||||
Item item = appendGetInfo(monitorOperation);
|
||||
ItemTag item = appendGetInfo(monitorOperation);
|
||||
monitorItems.add(item);
|
||||
}
|
||||
}
|
||||
return monitorItems;
|
||||
}
|
||||
|
||||
public List<Item> buildDeleteInfo(Operation operation) {
|
||||
List<Item> deleteItems = new ArrayList<>();
|
||||
Item deleteItem = new Item();
|
||||
Target target = new Target();
|
||||
String operationCode = operation.getCode();
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.PASSCODE_POLICY)) {
|
||||
|
||||
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 (operationCode != null && operationCode.equals(command.name())) {
|
||||
if (operation.getCode() != null && operation.getCode().equals(command.name())) {
|
||||
target.setLocURI(command.getCode());
|
||||
deleteItem.setTarget(target);
|
||||
itemTag.setTarget(target);
|
||||
deleteTagItems.add(itemTag);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return deleteItems;
|
||||
return deleteTagItems;
|
||||
}
|
||||
|
||||
public AddTag generatePasscodePolicyData(Configure configure, int policyData) {
|
||||
String attempt = String.valueOf(policyData);
|
||||
AddTag add = new AddTag();
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
Item item = new Item();
|
||||
Target target = new Target();
|
||||
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);
|
||||
@ -670,15 +670,15 @@ public class OperationReply {
|
||||
item.setMeta(meta);
|
||||
item.setData(attempt);
|
||||
itemList.add(item);
|
||||
add.setCommandId(90);
|
||||
add.setCommandId(Constants.SyncmlMessageCodes.addCommandId);
|
||||
add.setItems(itemList);
|
||||
return add;
|
||||
}
|
||||
|
||||
public AddTag generatePasscodeBooleanData(Operation operation, Configure configure) {
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
MetaTag meta = new MetaTag();
|
||||
AddTag add = new AddTag();
|
||||
AddTag addTag = null;
|
||||
|
||||
PasscodePolicy passcodePolicy = gson.fromJson((String) operation.getPayLoad(), PasscodePolicy.class);
|
||||
if (operation.getCode() != null && (PluginConstants.OperationCodes.DEVICE_PASSWORD_ENABLE.
|
||||
@ -686,87 +686,38 @@ public class OperationReply {
|
||||
if (passcodePolicy.isEnablePassword()) {
|
||||
target.setLocURI(configure.getCode());
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
Item item = new Item();
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData("0");
|
||||
itemList.add(item);
|
||||
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemList);
|
||||
|
||||
addTag = TagUtil.buildAddTag(operation, Constants.SyncMLResponseCodes.NEGATIVE_CSP_DATA);
|
||||
} else {
|
||||
target.setLocURI(configure.getCode());
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
Item item = new Item();
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData("1");
|
||||
itemList.add(item);
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemList);
|
||||
|
||||
addTag = TagUtil.buildAddTag(operation, Constants.SyncMLResponseCodes.POSITIVE_CSP_DATA);
|
||||
}
|
||||
}
|
||||
if (PluginConstants.OperationCodes.ALPHANUMERIC_PASSWORD.
|
||||
equals(configure.name())) {
|
||||
if (passcodePolicy.isRequireAlphanumeric()) {
|
||||
Item item = new Item();
|
||||
target.setLocURI(configure.getCode());
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData("1");
|
||||
itemList.add(item);
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemList);
|
||||
addTag = TagUtil.buildAddTag(operation, Constants.SyncMLResponseCodes.POSITIVE_CSP_DATA);
|
||||
} else {
|
||||
target.setLocURI(configure.getCode());
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
Item item = new Item();
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData("0");
|
||||
itemList.add(item);
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemList);
|
||||
addTag = TagUtil.buildAddTag(operation, Constants.SyncMLResponseCodes.NEGATIVE_CSP_DATA);
|
||||
}
|
||||
}
|
||||
if (PluginConstants.OperationCodes.SIMPLE_PASSWORD.
|
||||
equals(configure.name())) {
|
||||
if (passcodePolicy.isAllowSimple()) {
|
||||
Item item = new Item();
|
||||
target.setLocURI(configure.getCode());
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData("1");
|
||||
itemList.add(item);
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemList);
|
||||
|
||||
addTag = TagUtil.buildAddTag(operation, Constants.SyncMLResponseCodes.POSITIVE_CSP_DATA);
|
||||
} else {
|
||||
Item item = new Item();
|
||||
target.setLocURI(configure.getCode());
|
||||
meta.setFormat(Constants.META_FORMAT_INT);
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
item.setTarget(target);
|
||||
item.setMeta(meta);
|
||||
item.setData("0");
|
||||
itemList.add(item);
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemList);
|
||||
addTag = TagUtil.buildAddTag(operation, Constants.SyncMLResponseCodes.NEGATIVE_CSP_DATA);
|
||||
}
|
||||
}
|
||||
return add;
|
||||
return addTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,502 +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.mdm.mobileservices.windows.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.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManagementException;
|
||||
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.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.*;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils.convertToDeviceIdentifierObject;
|
||||
|
||||
/**
|
||||
* Class contains Operation related utilities.
|
||||
*/
|
||||
public class OperationUtils {
|
||||
private static Log log = LogFactory.getLog(OperationUtils.class);
|
||||
List<? extends Operation> pendingDataOperations;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws DeviceManagementException
|
||||
*/
|
||||
public void updateDeviceOperations(Status status, SyncmlDocument syncmlDocument,
|
||||
DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException, DeviceManagementException, NotificationManagementException,
|
||||
WindowsOperationException {
|
||||
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService()
|
||||
.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
if (status.getData().equals(Constants.SyncMLResponseCodes.ACCEPTED) || status.getData().equals
|
||||
(Constants.SyncMLResponseCodes.ACCEPTED_FOR_PROCESSING)) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
updateOperations(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
|
||||
} else if (status.getData().equals(Constants.SyncMLResponseCodes.PIN_NOTFOUND)) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getId() == status.getCommandReference() && operation.
|
||||
getCode().equals(String.valueOf(OperationCode.Command.DEVICE_LOCK))) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
updateOperations(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
|
||||
try {
|
||||
NotificationManagementService nmService = WindowsAPIUtils.getNotificationManagementService();
|
||||
Notification lockResetNotification = new Notification();
|
||||
lockResetNotification.setOperationId(status.getCommandReference());
|
||||
lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW));
|
||||
lockResetNotification.setDescription(
|
||||
Constants.SyncMLResponseCodes.LOCKRESET_NOTIFICATION);
|
||||
nmService.addNotification(deviceIdentifier, lockResetNotification);
|
||||
} catch (NotificationManagementException e) {
|
||||
throw new WindowsOperationException("Failure occurred in getting notification service", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update operation statuses
|
||||
*
|
||||
* @param deviceId specific device Id
|
||||
* @param operations operation list to be update
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void updateOperations(String deviceId,
|
||||
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.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
|
||||
* @throws DeviceManagementException
|
||||
* @throws NotificationManagementException
|
||||
*/
|
||||
public void lockOperationUpdate(Status status, SyncmlDocument syncmlDocument, DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException, DeviceManagementException, NotificationManagementException {
|
||||
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService()
|
||||
.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
if (status.getData().equals(Constants.SyncMLResponseCodes.ACCEPTED)) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getCode().equals(OperationCode.Command.DEVICE_LOCK.getCode())
|
||||
&& operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
new OperationUtils().updateOperations(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status.getData().equals(Constants.SyncMLResponseCodes.PIN_NOTFOUND)) {
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
|
||||
if (operation.getCode().equals(OperationCode.Command.DEVICE_LOCK.getCode()) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
new OperationUtils().updateOperations(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
try {
|
||||
NotificationManagementService nmService = WindowsAPIUtils.getNotificationManagementService();
|
||||
Notification lockResetNotification = new Notification();
|
||||
lockResetNotification.setOperationId(status.getCommandReference());
|
||||
lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW));
|
||||
lockResetNotification.setDescription(Constants.SyncMLResponseCodes.LOCKRESET_NOTIFICATION);
|
||||
|
||||
nmService.addNotification(deviceIdentifier, lockResetNotification);
|
||||
} catch (NotificationManagementException e) {
|
||||
String msg = "Failure occurred in getting notification service";
|
||||
log.error(msg, e);
|
||||
throw new NotificationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 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
|
||||
* @throws DeviceManagementException
|
||||
*/
|
||||
public void ring(Status status, SyncmlDocument syncmlDocument,
|
||||
DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException, DeviceManagementException {
|
||||
|
||||
if (status.getData().equals(Constants.SyncMLResponseCodes.ACCEPTED)) {
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService()
|
||||
.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getCode().equals(OperationCode.Command.DEVICE_RING) &&
|
||||
(operation.getId() == status.getCommandReference())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
new OperationUtils().updateOperations(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Update the status of the DataWipe operation.
|
||||
*
|
||||
* @param status Status of the datawipe.
|
||||
* @param syncmlDocument Parsed syncml payload from the syncml engine.
|
||||
* @param deviceIdentifier specific device id to be wiped.
|
||||
* @throws OperationManagementException
|
||||
* @throws DeviceManagementException
|
||||
*/
|
||||
public void dataWipe(Status status, SyncmlDocument syncmlDocument,
|
||||
DeviceIdentifier deviceIdentifier)
|
||||
throws OperationManagementException, DeviceManagementException {
|
||||
|
||||
if (status.getData().equals(Constants.SyncMLResponseCodes.ACCEPTED)) {
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService()
|
||||
.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
|
||||
if (operation.getCode().equals(OperationCode.Command.WIPE_DATA) &&
|
||||
(operation.getId() == status.getCommandReference())) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
updateOperations(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
|
||||
* @throws DeviceManagementException
|
||||
* @throws FeatureManagementException
|
||||
* @throws PolicyComplianceException
|
||||
* @throws NotificationManagementException
|
||||
*/
|
||||
public List<? extends Operation> getPendingOperations(SyncmlDocument syncmlDocument)
|
||||
throws OperationManagementException, DeviceManagementException, FeatureManagementException,
|
||||
PolicyComplianceException, NotificationManagementException, WindowsDeviceEnrolmentException,
|
||||
WindowsOperationException {
|
||||
|
||||
List<? extends Operation> pendingOperations;
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
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
|
||||
* @param deviceFeature
|
||||
* @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 DeviceManagementException
|
||||
* @throws NotificationManagementException
|
||||
* @throws OperationManagementException
|
||||
*/
|
||||
public void UpdateUriOperations(SyncmlDocument syncmlDocument) throws DeviceManagementException,
|
||||
NotificationManagementException, OperationManagementException, WindowsOperationException {
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
List<Status> statuses = syncmlDocument.getBody().getStatus();
|
||||
OperationUtils operationUtils = new OperationUtils();
|
||||
|
||||
for (Status status : statuses) {
|
||||
|
||||
if (status.getCommand().equals(Constants.EXECUTE)) {
|
||||
if (status.getTargetReference() == null) {
|
||||
operationUtils.updateDeviceOperations(status, syncmlDocument, deviceIdentifier);
|
||||
} else {
|
||||
if (status.getTargetReference().equals(OperationCode.Command.DEVICE_LOCK)) {
|
||||
operationUtils.lockOperationUpdate(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
if (status.getTargetReference().equals(OperationCode.Command.DEVICE_RING)) {
|
||||
operationUtils.ring(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
if (status.getTargetReference().equals(OperationCode.Command.WIPE_DATA)) {
|
||||
operationUtils.dataWipe(status, syncmlDocument, deviceIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status.getCommand().equals(Constants.SEQUENCE)) {
|
||||
if (status.getData().equals(Constants.SyncMLResponseCodes.ACCEPTED)) {
|
||||
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService()
|
||||
.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.POLICY_BUNDLE) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.MONITOR) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
operationUtils.updateOperations(syncmlDocument.getHeader().getSource().getLocURI(),
|
||||
pendingDataOperations);
|
||||
} else {
|
||||
pendingDataOperations = WindowsAPIUtils.getDeviceManagementService()
|
||||
.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
for (Operation operation : pendingDataOperations) {
|
||||
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.POLICY_BUNDLE) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
}
|
||||
if (operation.getCode().equals(PluginConstants.OperationCodes.MONITOR) &&
|
||||
operation.getId() == status.getCommandReference()) {
|
||||
operation.setStatus(Operation.Status.ERROR);
|
||||
}
|
||||
}
|
||||
operationUtils.updateOperations(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 NotificationManagementException
|
||||
*/
|
||||
public List<Profile> generateDeviceOperationStatusObject(SyncmlDocument syncmlDocument) throws
|
||||
NotificationManagementException, WindowsOperationException {
|
||||
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
String lockUri = null;
|
||||
Results result = syncmlDocument.getBody().getResults();
|
||||
|
||||
List<Profile> profiles = new ArrayList<>();
|
||||
if (result != null) {
|
||||
List<Item> results = result.getItem();
|
||||
for (OperationCode.Info info : OperationCode.Info.values()) {
|
||||
if (PluginConstants.OperationCodes.PIN_CODE.equals(info
|
||||
.name())) {
|
||||
lockUri = info.getCode();
|
||||
}
|
||||
}
|
||||
for (Item item : results) {
|
||||
for (OperationCode.Info info : OperationCode.Info.values()) {
|
||||
if (item.getSource().getLocURI().equals(info.getCode()) && info.name().equals(
|
||||
PluginConstants.OperationCodes.CAMERA_STATUS)) {
|
||||
Profile cameraProfile = new Profile();
|
||||
cameraProfile.setFeatureCode(PluginConstants.OperationCodes.CAMERA);
|
||||
cameraProfile.setData(item.getData());
|
||||
if (item.getData().equals(PluginConstants.SyncML.SYNCML_DATA_ONE)) {
|
||||
cameraProfile.setEnable(true);
|
||||
} else {
|
||||
cameraProfile.setEnable(false);
|
||||
}
|
||||
profiles.add(cameraProfile);
|
||||
}
|
||||
if (item.getSource().getLocURI().equals(info.getCode()) && info.name().equals(
|
||||
PluginConstants.OperationCodes.ENCRYPT_STORAGE_STATUS)) {
|
||||
Profile encryptStorage = new Profile();
|
||||
encryptStorage.setFeatureCode(PluginConstants.OperationCodes.ENCRYPT_STORAGE);
|
||||
encryptStorage.setData(item.getData());
|
||||
if (item.getData().equals(PluginConstants.SyncML.SYNCML_DATA_ONE)) {
|
||||
encryptStorage.setEnable(true);
|
||||
} else {
|
||||
encryptStorage.setEnable(false);
|
||||
}
|
||||
profiles.add(encryptStorage);
|
||||
}
|
||||
if (item.getSource().getLocURI().equals(info.getCode()) && info.name().equals(
|
||||
PluginConstants.OperationCodes.DEVICE_PASSWORD_STATUS)) {
|
||||
Profile encryptStorage = new Profile();
|
||||
encryptStorage.setFeatureCode(PluginConstants.OperationCodes.PASSCODE_POLICY);
|
||||
encryptStorage.setData(item.getData());
|
||||
if (item.getData().equals(PluginConstants.SyncML.SYNCML_DATA_ZERO)) {
|
||||
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) {
|
||||
String msg = "Failure Occurred in getting notification service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Compliance Features
|
||||
*
|
||||
* @param syncmlDocument syncmlDocument object parsed from the syncml engine.
|
||||
* @throws NotificationManagementException
|
||||
* @throws FeatureManagementException
|
||||
* @throws PolicyComplianceException
|
||||
*/
|
||||
public void generateComplianceFeatureStatus(SyncmlDocument syncmlDocument) throws NotificationManagementException,
|
||||
FeatureManagementException, PolicyComplianceException, WindowsDeviceEnrolmentException,
|
||||
WindowsOperationException {
|
||||
List<Profile> profiles = generateDeviceOperationStatusObject(syncmlDocument);
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
|
||||
syncmlDocument.getHeader().getSource().getLocURI());
|
||||
boolean isCompliance = false;
|
||||
if (profiles.size() != Constants.EMPTY) {
|
||||
try {
|
||||
List<ProfileFeature> profileFeatures = WindowsAPIUtils.getPolicyManagerService().getEffectiveFeatures(
|
||||
deviceIdentifier);
|
||||
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()) &&
|
||||
deviceFeature.getFeatureCode().equals(PluginConstants.OperationCodes.CAMERA)) {
|
||||
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()) &&
|
||||
deviceFeature.getFeatureCode().equals(PluginConstants.OperationCodes.
|
||||
ENCRYPT_STORAGE)) {
|
||||
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()) &&
|
||||
deviceFeature.getFeatureCode().equals(PluginConstants.OperationCodes.
|
||||
PASSCODE_POLICY)) {
|
||||
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 (org.wso2.carbon.policy.mgt.common.FeatureManagementException e) {
|
||||
String msg = "Error occurred while getting effective policy.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (JSONException e) {
|
||||
String msg = "Error occurred while parsing json object.";
|
||||
log.error(msg);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
} catch (PolicyComplianceException e) {
|
||||
String msg = "Error occurred while setting up policy compliance.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -26,11 +26,11 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Class for generate security token for client and server.
|
||||
* Generate security token to client and server.
|
||||
*/
|
||||
public class SyncmlCredentials {
|
||||
public class SyncmlCredentialUtil {
|
||||
|
||||
public String generateCredData(String nextNonce) throws SyncmlMessageFormatException {
|
||||
public static String generateCredData(String nextNonce) throws SyncmlMessageFormatException {
|
||||
MessageDigest digest;
|
||||
String usrPwdNonceHash;
|
||||
String nonce;
|
||||
@ -42,14 +42,15 @@ public class SyncmlCredentials {
|
||||
String usrPwdNonce = usrPwdHash + ":" + nonce;
|
||||
usrPwdNonceHash = Base64.encodeBase64String(digest.digest(usrPwdNonce.getBytes(Constants.UTF_8)));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new SyncmlMessageFormatException("Problem occurred in encoding credentials data.", e);
|
||||
throw new SyncmlMessageFormatException("Problem occurred while decoding credentials data.", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SyncmlMessageFormatException("Problem occurred in generating password hash.", e);
|
||||
throw new SyncmlMessageFormatException("Application environment does not have an implementation " +
|
||||
"available/configured for the requested algorithm", e);
|
||||
}
|
||||
return usrPwdNonceHash;
|
||||
}
|
||||
|
||||
public String generateRST(String username, String password) throws SyncmlMessageFormatException {
|
||||
public static String generateRST(String username, String password) throws SyncmlMessageFormatException {
|
||||
MessageDigest digest;
|
||||
String usrPwdNonceHash;
|
||||
String nonce;
|
||||
@ -61,9 +62,10 @@ public class SyncmlCredentials {
|
||||
String usrPwdNonce = usrPwdHash + ":" + nonce;
|
||||
usrPwdNonceHash = Base64.encodeBase64String(digest.digest(usrPwdNonce.getBytes(Constants.UTF_8)));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new SyncmlMessageFormatException("Problem occurred in encoding credentials data.", e);
|
||||
throw new SyncmlMessageFormatException("Problem occurred while decoding credentials data.", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SyncmlMessageFormatException("Problem occurred in generating password hash.", e);
|
||||
throw new SyncmlMessageFormatException("Application environment does not have an implementation " +
|
||||
"available/configured for the requested algorithm", e);
|
||||
}
|
||||
return usrPwdNonceHash;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.operations.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.SyncmlOperationException;
|
||||
@ -36,13 +34,11 @@ import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* Generates the response syncml xml file that should be sent to the phone.
|
||||
* Generates the response syncml xml file that should be sent to the Device.
|
||||
*/
|
||||
public class SyncmlGenerator {
|
||||
|
||||
private static Log log = LogFactory.getLog(SyncmlGenerator.class);
|
||||
|
||||
public String generatePayload(SyncmlDocument syncmlDocument) throws SyncmlOperationException {
|
||||
public static String generatePayload(SyncmlDocument syncmlDocument) throws SyncmlOperationException {
|
||||
Document doc = generateDocument();
|
||||
Element rootElement = createRootElement(doc);
|
||||
SyncmlHeader header = syncmlDocument.getHeader();
|
||||
@ -58,9 +54,7 @@ public class SyncmlGenerator {
|
||||
try {
|
||||
docBuilder = documentFactory.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException e) {
|
||||
String message = "Error while generating a new document of syncml";
|
||||
log.error(message, e);
|
||||
throw new SyncmlOperationException(message, e);
|
||||
throw new SyncmlOperationException("Error occurred while generating a new document of syncml", e);
|
||||
}
|
||||
return docBuilder.newDocument();
|
||||
}
|
||||
@ -72,16 +66,14 @@ public class SyncmlGenerator {
|
||||
return rootElement;
|
||||
}
|
||||
|
||||
private String transformDocument(Document document) throws SyncmlOperationException {
|
||||
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) {
|
||||
String message = "Error while retrieving a new transformer";
|
||||
log.error(message, e);
|
||||
throw new SyncmlOperationException(message, 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);
|
||||
@ -91,9 +83,7 @@ public class SyncmlGenerator {
|
||||
try {
|
||||
transformer.transform(domSource, streamResult);
|
||||
} catch (TransformerException e) {
|
||||
String message = "Error while transforming document to a string";
|
||||
log.error(message, e);
|
||||
throw new SyncmlOperationException(message, e);
|
||||
throw new SyncmlOperationException("Error occurred while transforming document to a string", e);
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -22,11 +22,9 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.SyncmlMessageFormatException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.IllegalFormatCodePointException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -80,15 +78,17 @@ public class SyncmlParser {
|
||||
* @param syncmlPayload - Received SyncML XML payload
|
||||
* @return - SyncmlDocument object generated from the received payload
|
||||
*/
|
||||
public static SyncmlDocument parseSyncmlPayload(Document syncmlPayload) throws SyncmlMessageFormatException {
|
||||
public static SyncmlDocument parseSyncmlPayload(Document syncmlPayload) {
|
||||
SyncmlDocument syncmlDocument = new SyncmlDocument();
|
||||
if (syncmlPayload.getElementsByTagName(SYNC_HEADER) == null) {
|
||||
throw new SyncmlMessageFormatException();
|
||||
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);
|
||||
@ -108,9 +108,9 @@ public class SyncmlParser {
|
||||
|
||||
String sessionID = null;
|
||||
String messageID = null;
|
||||
Target target = null;
|
||||
Source source = null;
|
||||
Credential credential = null;
|
||||
TargetTag target = null;
|
||||
SourceTag source = null;
|
||||
CredentialTag credential = null;
|
||||
SyncmlHeader header = new SyncmlHeader();
|
||||
|
||||
NodeList headerElements = syncHeader.getChildNodes();
|
||||
@ -122,31 +122,31 @@ public class SyncmlParser {
|
||||
|
||||
if (SyncMLHeaderParameter.MSG_ID.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
messageID = node.getTextContent().trim();
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.SESSION_ID.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
sessionID = node.getTextContent().trim();
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.TARGET.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
target = generateTarget(node);
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.SOURCE.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
source = generateSource(node);
|
||||
}
|
||||
} else if (SyncMLHeaderParameter.CRED.getValue().equals(nodeName)) {
|
||||
if (node.getTextContent().trim() == null) {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
credential = generateCredential(node);
|
||||
}
|
||||
@ -170,10 +170,10 @@ public class SyncmlParser {
|
||||
*/
|
||||
private static SyncmlBody generateSyncmlBody(Node syncBody) {
|
||||
|
||||
Alert alert = null;
|
||||
Replace replace = null;
|
||||
Results results = null;
|
||||
List<Status> status = new ArrayList<>();
|
||||
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++) {
|
||||
@ -207,9 +207,9 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Source
|
||||
* @return - Source object
|
||||
*/
|
||||
private static Source generateSource(Node node) {
|
||||
private static SourceTag generateSource(Node node) {
|
||||
|
||||
Source source = new Source();
|
||||
SourceTag source = new SourceTag();
|
||||
Node sourceURIItem = node.getChildNodes().item(0);
|
||||
Node sourceNameItem = node.getChildNodes().item(1);
|
||||
String sourceURI = null;
|
||||
@ -232,9 +232,9 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Target
|
||||
* @return - Target object
|
||||
*/
|
||||
private static Target generateTarget(Node node) {
|
||||
private static TargetTag generateTarget(Node node) {
|
||||
|
||||
Target target = new Target();
|
||||
TargetTag target = new TargetTag();
|
||||
Node targetURIItem = node.getChildNodes().item(0);
|
||||
Node targetNameItem = node.getChildNodes().item(1);
|
||||
String targetURI = null;
|
||||
@ -257,10 +257,10 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Results
|
||||
* @return - Results object
|
||||
*/
|
||||
private static Results generateResults(Node node) {
|
||||
private static ResultsTag generateResults(Node node) {
|
||||
|
||||
Results results = new Results();
|
||||
List<Item> item = new ArrayList<>();
|
||||
ResultsTag results = new ResultsTag();
|
||||
List<ItemTag> item = new ArrayList<>();
|
||||
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
|
||||
@ -298,9 +298,9 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Status
|
||||
* @return - Status object
|
||||
*/
|
||||
private static Status generateStatus(Node node) {
|
||||
private static StatusTag generateStatus(Node node) {
|
||||
|
||||
Status status = new Status();
|
||||
StatusTag status = new StatusTag();
|
||||
for (int x = 0; x < node.getChildNodes().getLength(); x++) {
|
||||
String nodeName = node.getChildNodes().item(x).getNodeName();
|
||||
switch (nodeName) {
|
||||
@ -321,17 +321,17 @@ public class SyncmlParser {
|
||||
status.setCommand(command);
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_CHAL:
|
||||
NodeList chalNodes = node.getChildNodes().item(x).getChildNodes();
|
||||
NodeList childNodes = node.getChildNodes().item(x).getChildNodes();
|
||||
MetaTag meta = new MetaTag();
|
||||
ChallengeTag chal = new ChallengeTag();
|
||||
String format = chalNodes.item(0).getFirstChild().getTextContent();
|
||||
ChallengeTag challengeTag = new ChallengeTag();
|
||||
String format = childNodes.item(0).getFirstChild().getTextContent();
|
||||
meta.setFormat(format);
|
||||
String type = chalNodes.item(0).getFirstChild().getNextSibling().getTextContent();
|
||||
String type = childNodes.item(0).getFirstChild().getNextSibling().getTextContent();
|
||||
meta.setType(type);
|
||||
String nonce = chalNodes.item(0).getFirstChild().getNextSibling().getNextSibling().getTextContent();
|
||||
String nonce = childNodes.item(0).getFirstChild().getNextSibling().getNextSibling().getTextContent();
|
||||
meta.setNextNonce(nonce);
|
||||
chal.setMeta(meta);
|
||||
status.setChallenge(chal);
|
||||
challengeTag.setMeta(meta);
|
||||
status.setChallenge(challengeTag);
|
||||
break;
|
||||
case PluginConstants.SyncML.SYNCML_DATA:
|
||||
String data = node.getChildNodes().item(x).getTextContent().trim();
|
||||
@ -352,11 +352,11 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Replace
|
||||
* @return - Replace object
|
||||
*/
|
||||
private static Replace generateReplace(Node node) {
|
||||
private static ReplaceTag generateReplace(Node node) {
|
||||
|
||||
Replace replace = new Replace();
|
||||
ReplaceTag replace = new ReplaceTag();
|
||||
String commandId = node.getChildNodes().item(0).getTextContent().trim();
|
||||
List<Item> items = new ArrayList<>();
|
||||
List<ItemTag> items = new ArrayList<>();
|
||||
for (int i = 0; i < node.getChildNodes().getLength() - 1; i++) {
|
||||
items.add(generateItem(node.getChildNodes().item(i + 1)));
|
||||
}
|
||||
@ -371,8 +371,8 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Alert
|
||||
* @return - Alert object
|
||||
*/
|
||||
private static Alert generateAlert(Node node) {
|
||||
Alert alert = new Alert();
|
||||
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();
|
||||
alert.setCommandId(Integer.valueOf(commandID));
|
||||
@ -386,39 +386,41 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Item
|
||||
* @return - Item object
|
||||
*/
|
||||
private static Item generateItem(Node node) {
|
||||
Item item = new Item();
|
||||
Source source = new Source();
|
||||
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++) {
|
||||
if (node.getChildNodes().item(x).getNodeName() != null) {
|
||||
Node itemNode;
|
||||
itemNode = node.getChildNodes().item(x);
|
||||
if (itemNode.getNodeName() != null) {
|
||||
nodeName = node.getChildNodes().item(x).getNodeName();
|
||||
} else {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (nodeName == PluginConstants.SyncML.SYNCML_SOURCE) {
|
||||
if (node.getChildNodes().item(x).getChildNodes().item(x).getNodeName() != null) {
|
||||
childNodeName = node.getChildNodes().item(x).getChildNodes().item(x).getNodeName();
|
||||
if (PluginConstants.SyncML.SYNCML_SOURCE.equals(nodeName)) {
|
||||
if (itemNode.getChildNodes().item(x).getNodeName() != null) {
|
||||
childNodeName = itemNode.getChildNodes().item(x).getNodeName();
|
||||
} else {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (childNodeName == PluginConstants.SyncML.SYNCML_LOCATION_URI) {
|
||||
if (node.getChildNodes().item(x).getChildNodes().item(x).getTextContent().trim() != null) {
|
||||
locUri = node.getChildNodes().item(x).getChildNodes().item(x).getTextContent().trim();
|
||||
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 IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
source.setLocURI(locUri);
|
||||
item.setSource(source);
|
||||
}
|
||||
} else if (nodeName == PluginConstants.SyncML.SYNCML_DATA) {
|
||||
if (node.getChildNodes().item(x).getTextContent().trim() != null) {
|
||||
data = node.getChildNodes().item(x).getTextContent().trim();
|
||||
} else if (PluginConstants.SyncML.SYNCML_DATA.equals(nodeName)) {
|
||||
if (itemNode.getTextContent().trim() != null) {
|
||||
data = itemNode.getTextContent().trim();
|
||||
} else {
|
||||
throw new IllegalFormatCodePointException(2);
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
item.setData(data);
|
||||
}
|
||||
@ -432,8 +434,8 @@ public class SyncmlParser {
|
||||
* @param node - XML node which represents Credential
|
||||
* @return - Credential object
|
||||
*/
|
||||
private static Credential generateCredential(Node node) {
|
||||
Credential credential = new Credential();
|
||||
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);
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.mdm.mobileservices.windows.operations.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.AddTag;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.ItemTag;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.MetaTag;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.TargetTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains utility methods which are used while creating Syncml Messages.
|
||||
*/
|
||||
public class TagUtil {
|
||||
/**
|
||||
* Build syncml AddTag for Device response message.
|
||||
*
|
||||
* @param operation Policy operation
|
||||
* @param data Configuration service provider(CSP) data value 1/0
|
||||
* @return Syncml AddTag type object.
|
||||
*/
|
||||
public static AddTag buildAddTag(Operation operation, String data) {
|
||||
TargetTag target = new TargetTag();
|
||||
MetaTag meta = new MetaTag();
|
||||
AddTag add = new AddTag();
|
||||
|
||||
List<ItemTag> itemTags = new ArrayList<>();
|
||||
ItemTag itemTag = new ItemTag();
|
||||
itemTag.setTarget(target);
|
||||
itemTag.setMeta(meta);
|
||||
itemTag.setData(data);
|
||||
itemTags.add(itemTag);
|
||||
add.setCommandId(operation.getId());
|
||||
add.setItems(itemTags);
|
||||
return add;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,10 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
@ -32,8 +28,6 @@ import java.util.List;
|
||||
/**
|
||||
* Interface for Admin operations persisting. This interface accepts operations added via UI.
|
||||
*/
|
||||
|
||||
@Api(value = "Operations", description = "Windows Device Management REST-API implementation.")
|
||||
@Path("/operation")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ -42,72 +36,22 @@ public interface Operations {
|
||||
|
||||
@POST
|
||||
@Path("/devicelock")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Adding a Device Lock on Windows Devices via the REST API",
|
||||
notes = "Adding a Device lock operation to the windows device"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Internal Server error")
|
||||
})
|
||||
Response lock(@HeaderParam("Accept") String headerParam, List<String> deviceids) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/devicedisenroll")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Disenrolling Windows Devices via the REST API",
|
||||
notes = "Enforcing Disenrolling operation to the windows device"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Internal Server error")
|
||||
})
|
||||
Response disenroll(@HeaderParam("Accept") String headerParam, List<String> deviceids) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/devicewipe")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Wiping Information off Windows Devices via the REST API",
|
||||
notes = "Enforce wipe operation to the windows device"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Internal Server error")
|
||||
})
|
||||
Response wipe(@HeaderParam("Accept") String headerParam, List<String> deviceids) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/devicering")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Ringing Windows Devices via the Rest API",
|
||||
notes = "Adding a Device ring operation to the windows device."
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Internal Server error")
|
||||
})
|
||||
Response ring(@HeaderParam("Accept") String headerParam, List<String> deviceids) throws WindowsDeviceEnrolmentException;
|
||||
|
||||
@POST
|
||||
@Path("/lockreset")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Resetting the Lock of Windows Devices via the REST API",
|
||||
notes = "Adding a Device lock re-test operation to the windows device."
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Internal Server error")
|
||||
})
|
||||
Response lockReset(@HeaderParam("Accept") String acceptHeader, List<String> deviceids)
|
||||
throws WindowsDeviceEnrolmentException;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,15 +18,11 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Class for get device IDS.
|
||||
*/
|
||||
@ApiModel(value = "Device", description = "This class carries all information related to Device.")
|
||||
public class Device {
|
||||
@ApiModelProperty(name = "id", value = "DeviceIDs.", required = true)
|
||||
|
||||
private String id;
|
||||
|
||||
public String getID() {
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.services.adminoperations.beans;
|
||||
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.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,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -51,7 +51,7 @@ public class OperationsImpl implements Operations {
|
||||
* REST endpoint for the Device Lock operation
|
||||
*
|
||||
* @param acceptHeader header value of the request POST message.
|
||||
* @param deviceIDs list of device ids to be add device lockOperationUpdate operation.
|
||||
* @param deviceIDs list of device ids to be add device updateLockOperation operation.
|
||||
* @return Response object for client.
|
||||
* @throws WindowsDeviceEnrolmentException
|
||||
*/
|
||||
@ -60,7 +60,7 @@ public class OperationsImpl implements Operations {
|
||||
public Response lock(@HeaderParam("Accept") String acceptHeader, List<String> deviceIDs)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoking windows device lockOperationUpdate operation");
|
||||
log.debug("Invoking windows device updateLockOperation operation");
|
||||
}
|
||||
MediaType responseMediaType = WindowsAPIUtils.getResponseMediaType(acceptHeader);
|
||||
Message message = new Message();
|
||||
@ -198,15 +198,15 @@ public class OperationsImpl implements Operations {
|
||||
}
|
||||
|
||||
/**
|
||||
* REST endpoint for the device lockOperationUpdate reset.
|
||||
* Lock reset have to be done, when device user does not set PIN for the lockOperationUpdate screen.
|
||||
* Admin set lockOperationUpdate operation for the specific device,If the device is in above scenario,
|
||||
* REST endpoint for the device updateLockOperation reset.
|
||||
* Lock reset have to be done, when device user does not set PIN for the updateLockOperation screen.
|
||||
* Admin set updateLockOperation operation for the specific device,If the device is in above scenario,
|
||||
* admin will be notified.since
|
||||
* admin have to set lockOperationUpdate reset operation to the device so that automatically generate PIN value for the
|
||||
* lockOperationUpdate screen.
|
||||
* admin have to set updateLockOperation reset operation to the device so that automatically generate PIN value for the
|
||||
* updateLockOperation screen.
|
||||
*
|
||||
* @param acceptHeader POST message header value.
|
||||
* @param deviceIDs Device ids to be lockOperationUpdate reset.
|
||||
* @param deviceIDs Device ids to be updateLockOperation reset.
|
||||
* @return Response object for the client.
|
||||
* @throws WindowsDeviceEnrolmentException
|
||||
*/
|
||||
|
||||
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.mdm.mobileservices.windows.services.adminoperations.util;
|
||||
//
|
||||
//import com.google.gson.Gson;
|
||||
//import org.apache.commons.logging.Log;
|
||||
//import org.apache.commons.logging.LogFactory;
|
||||
//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.DeviceManagementException;
|
||||
//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.operation.mgt.ConfigOperation;
|
||||
//import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
//import org.wso2.carbon.mdm.mobileservices.windows.common.SyncmlCommandType;
|
||||
//import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
//import org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans.Device;
|
||||
//import org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans.OperationRequest;
|
||||
//import org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans.Wifi;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class OperationStore {
|
||||
//
|
||||
// private static Log log = LogFactory.getLog(OperationStore.class);
|
||||
//
|
||||
// public static boolean storeOperation(OperationRequest operationRequest, Operation.Type type,
|
||||
// String commandType) throws
|
||||
// WindowsDeviceEnrolmentException {
|
||||
//
|
||||
// List<Device> devices = operationRequest.getDeviceList();
|
||||
// List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
||||
// DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
//
|
||||
// Operation operation = transformBasicOperation(operationRequest, type, commandType);
|
||||
//
|
||||
// for (int i = 0; i < devices.size(); i++) {
|
||||
// try {
|
||||
// deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
// deviceIdentifier.setId(devices.get(i).getID());
|
||||
// deviceIdentifiers.add(deviceIdentifier);
|
||||
// getDeviceManagementServiceProvider().getDevice(deviceIdentifier);
|
||||
//
|
||||
// } catch (DeviceManagementException e) {
|
||||
// log.error("Cannot validate device ID: " + devices.get(i).getID());
|
||||
// deviceIdentifiers.remove(i);
|
||||
// }
|
||||
// }
|
||||
// try {
|
||||
// getDeviceManagementServiceProvider().addOperation(operation, deviceIdentifiers);
|
||||
// } catch (OperationManagementException e) {
|
||||
// String msg = "Failure occurred while storing command operation.";
|
||||
// log.error(msg);
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// private static DeviceManagementProviderService getDeviceManagementServiceProvider() {
|
||||
// DeviceManagementProviderService deviceManager;
|
||||
// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
// deviceManager =
|
||||
// (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||
//
|
||||
// if (deviceManager == null) {
|
||||
// String msg = "Device management service is not initialized.";
|
||||
// log.error(msg);
|
||||
// }
|
||||
// return deviceManager;
|
||||
// }
|
||||
//
|
||||
// private static Operation transformBasicOperation(OperationRequest operationRequest, Operation.Type type,
|
||||
// String commandType) throws WindowsDeviceEnrolmentException {
|
||||
//
|
||||
// Operation operation = new Operation();
|
||||
// operation.setCode(commandType);
|
||||
// operation.setType(type);
|
||||
// Gson gson = new Gson();
|
||||
//
|
||||
// if (commandType == SyncmlCommandType.WIFI.getValue()) {
|
||||
//
|
||||
// operation = new ConfigOperation();
|
||||
// operation.setCode(commandType);
|
||||
// operation.setType(type);
|
||||
//
|
||||
// Wifi wifiObject = (Wifi) operationRequest.getBasicOperation();
|
||||
// operation.setPayLoad(gson.toJson(wifiObject));
|
||||
// } else {
|
||||
// // no operation.....
|
||||
// }
|
||||
//
|
||||
// return operation;
|
||||
// }
|
||||
//}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,10 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.authbst;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.authbst.beans.Credentials;
|
||||
|
||||
@ -34,23 +30,11 @@ import javax.ws.rs.core.Response;
|
||||
/**
|
||||
* Interface for handling authentication request comes via MDM login page.
|
||||
*/
|
||||
@Api(value = "BSTProvider", description = "Windows Device Management REST-API implementation.")
|
||||
@Path("/bst")
|
||||
public interface BSTProvider {
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/authentication")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Getting Binary security token via the Rest API",
|
||||
notes = "Getting binary security token to call next certificate endpoints.",
|
||||
response = String.class
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Internal Server error")
|
||||
})
|
||||
Response getBST(Credentials credentials) throws WindowsDeviceEnrolmentException;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,9 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.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;
|
||||
@ -29,28 +26,18 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
/**
|
||||
* This bean class is for credentials coming from wab page at federated authentication step.
|
||||
*/
|
||||
@ApiModel(value = "Credentials", description = "This class carries all information related to Credentials.")
|
||||
@XmlRootElement(name = "credentials")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class Credentials {
|
||||
|
||||
@ApiModelProperty(name = "username", value = "User name", required = true)
|
||||
@XmlElement(required = true, name = "username")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(name = "email", value = "Email Address of the user.", required = true)
|
||||
@XmlElement(required = true, name = "email")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(name = "password", value = "password of the user.", required = true)
|
||||
@XmlElement(required = true, name = "password")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(name = "ownership", value = "ownership of the user.(BYOD/COPE).", required = true)
|
||||
@XmlElement(required = true, name = "ownership")
|
||||
private String ownership;
|
||||
|
||||
@ApiModelProperty(name = "usertoken", value = "User Token.", required = true)
|
||||
@XmlElement(required = true, name = "token")
|
||||
private String usertoken;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -19,12 +19,9 @@
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.authbst.impl;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.beans.Token;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.AuthenticationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
@ -43,15 +40,12 @@ import javax.ws.rs.core.Response;
|
||||
*/
|
||||
public class BSTProviderImpl implements BSTProvider {
|
||||
|
||||
private static Log log = LogFactory.getLog(BSTProviderImpl.class);
|
||||
private static final String DELIMITER = "@";
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param credentials - Credential object passes from the wab page.
|
||||
* @return - Response with binary security token.
|
||||
*/
|
||||
@Override
|
||||
public Response getBST(Credentials credentials) throws WindowsDeviceEnrolmentException {
|
||||
@ -68,14 +62,9 @@ public class BSTProviderImpl implements BSTProvider {
|
||||
JSONObject tokenContent = new JSONObject();
|
||||
tokenContent.put("UserToken", userToken);
|
||||
return Response.ok().entity(tokenContent.toString()).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Failure occurred in generating challenge token.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
} catch (JSONException e) {
|
||||
String msg = "Failure occurred in generating challenge token Json.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(
|
||||
"Failure occurred in generating Json payload for challenge token.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,9 +88,7 @@ public class BSTProviderImpl implements BSTProvider {
|
||||
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||
|
||||
if (realmService == null) {
|
||||
String msg = "RealmService not initialized.";
|
||||
log.error(msg);
|
||||
throw new AuthenticationException(msg);
|
||||
throw new AuthenticationException("RealmService not initialized.");
|
||||
}
|
||||
|
||||
int tenantId;
|
||||
@ -112,17 +99,13 @@ public class BSTProviderImpl implements BSTProvider {
|
||||
}
|
||||
|
||||
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
|
||||
String msg = "Invalid tenant domain " + tenantDomain;
|
||||
log.error(msg);
|
||||
throw new AuthenticationException(msg);
|
||||
throw new AuthenticationException("Invalid tenant domain " + tenantDomain);
|
||||
}
|
||||
UserRealm userRealm = realmService.getTenantUserRealm(tenantId);
|
||||
|
||||
return userRealm.getUserStoreManager().authenticate(username, password);
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "User store is not initialized.";
|
||||
log.error(msg, e);
|
||||
throw new AuthenticationException(msg, e);
|
||||
throw new AuthenticationException("User store is not initialized.", e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,17 +18,23 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
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.license.mgt.License;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Windows Platform Configuration REST-API implementation.
|
||||
@ -37,8 +43,9 @@ import javax.ws.rs.core.MediaType;
|
||||
@WebService
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Api(value = "ConfigurationMgtService", description = "Windows Device Management REST-API implementation.")
|
||||
public interface ConfigurationMgtService {
|
||||
public class ConfigurationMgtService {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConfigurationMgtService.class);
|
||||
|
||||
/**
|
||||
* Save Tenant configurations.
|
||||
@ -48,17 +55,49 @@ public interface ConfigurationMgtService {
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@POST
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Configuring Windows Platform Settings",
|
||||
notes = "Configure the Windows platform settings using this REST API"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Windows platform configuration saved successfully"),
|
||||
@ApiResponse(code = 500, message = "Internal Server Error")
|
||||
})
|
||||
Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException;
|
||||
public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException {
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
String message;
|
||||
|
||||
try {
|
||||
configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
if (!configuration.getConfiguration().isEmpty()) {
|
||||
List<ConfigurationEntry> configs = configuration.getConfiguration();
|
||||
for (ConfigurationEntry entry : configs) {
|
||||
if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) {
|
||||
License license = new License();
|
||||
license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US);
|
||||
license.setVersion("1.0.0");
|
||||
license.setText(entry.getValue().toString());
|
||||
WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license);
|
||||
licenseEntry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (licenseEntry != null) {
|
||||
configs.remove(licenseEntry);
|
||||
}
|
||||
configuration.setConfiguration(configs);
|
||||
WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration);
|
||||
Response.status(Response.Status.CREATED);
|
||||
responseMsg.setResponseMessage("Windows platform configuration saved successfully.");
|
||||
responseMsg.setResponseCode(Response.Status.CREATED.toString());
|
||||
return responseMsg;
|
||||
} else {
|
||||
Response.status(Response.Status.BAD_REQUEST);
|
||||
responseMsg.setResponseMessage("Windows platform configuration can not be saved.");
|
||||
responseMsg.setResponseCode(Response.Status.CREATED.toString());
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
message = "Error Occurred while configuring Windows Platform.";
|
||||
log.error(message, e);
|
||||
throw new WindowsConfigurationException(message, e);
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Tenant configurations according to the device type.
|
||||
@ -67,17 +106,39 @@ public interface ConfigurationMgtService {
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@GET
|
||||
@ApiOperation(
|
||||
httpMethod = "GET",
|
||||
value = "Getting Windows Platform Configurations",
|
||||
notes = "Get the Windows platform configuration details using this REST API",
|
||||
response = PlatformConfiguration.class
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Get Windows Configurations"),
|
||||
@ApiResponse(code = 500, message = "Server Error")
|
||||
})
|
||||
PlatformConfiguration getConfiguration() throws WindowsConfigurationException;
|
||||
public PlatformConfiguration getConfiguration() throws WindowsConfigurationException {
|
||||
String msg;
|
||||
PlatformConfiguration tenantConfiguration;
|
||||
List<ConfigurationEntry> configs;
|
||||
try {
|
||||
tenantConfiguration = WindowsAPIUtils.getDeviceManagementService().
|
||||
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
if (tenantConfiguration != null) {
|
||||
configs = tenantConfiguration.getConfiguration();
|
||||
} else {
|
||||
tenantConfiguration = new PlatformConfiguration();
|
||||
configs = new ArrayList<>();
|
||||
}
|
||||
|
||||
ConfigurationEntry entry = new ConfigurationEntry();
|
||||
License license = WindowsAPIUtils.getDeviceManagementService().getLicense(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS,
|
||||
PluginConstants.TenantConfigProperties.LANGUAGE_US);
|
||||
|
||||
if (license != null && configs != null) {
|
||||
entry.setContentType(PluginConstants.TenantConfigProperties.CONTENT_TYPE_TEXT);
|
||||
entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY);
|
||||
entry.setValue(license.getText());
|
||||
configs.add(entry);
|
||||
tenantConfiguration.setConfiguration(configs);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while retrieving the Windows tenant configuration";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return tenantConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Tenant Configurations for the specific Device type.
|
||||
@ -87,17 +148,39 @@ public interface ConfigurationMgtService {
|
||||
* @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"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 201, message = "Created"),
|
||||
@ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " +
|
||||
"windows platform")
|
||||
})
|
||||
Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException;
|
||||
public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException {
|
||||
String message;
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
try {
|
||||
configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
List<ConfigurationEntry> configs = configuration.getConfiguration();
|
||||
for (ConfigurationEntry entry : configs) {
|
||||
if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) {
|
||||
License license = new License();
|
||||
license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US);
|
||||
license.setVersion("1.0.0");
|
||||
license.setText(entry.getValue().toString());
|
||||
WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license);
|
||||
licenseEntry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (licenseEntry != null) {
|
||||
configs.remove(licenseEntry);
|
||||
}
|
||||
configuration.setConfiguration(configs);
|
||||
WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration);
|
||||
Response.status(Response.Status.CREATED);
|
||||
responseMsg.setResponseMessage("Windows platform configuration succeeded.");
|
||||
responseMsg.setResponseCode(Response.Status.CREATED.toString());
|
||||
} catch (DeviceManagementException e) {
|
||||
message = "Error occurred while modifying configuration settings of Windows platform.";
|
||||
log.error(message, e);
|
||||
throw new WindowsConfigurationException(message, e);
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,182 +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.mdm.mobileservices.windows.services.configurationmgtservice.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
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.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Windows Platform Configuration REST-API implementation.
|
||||
* All end points supports JSON, XMl with content negotiation.
|
||||
*/
|
||||
@WebService
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
public class ConfigurationMgtServiceImpl {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class);
|
||||
|
||||
/**
|
||||
* Save Tenant configurations.
|
||||
*
|
||||
* @param configuration Tenant Configurations to be saved.
|
||||
* @return Message type object for the provide save status.
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@POST
|
||||
public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException {
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
String message;
|
||||
|
||||
try {
|
||||
configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
if (!configuration.getConfiguration().isEmpty()) {
|
||||
List<ConfigurationEntry> configs = configuration.getConfiguration();
|
||||
for (ConfigurationEntry entry : configs) {
|
||||
if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) {
|
||||
License license = new License();
|
||||
license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US);
|
||||
license.setVersion("1.0.0");
|
||||
license.setText(entry.getValue().toString());
|
||||
WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license);
|
||||
licenseEntry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (licenseEntry != null) {
|
||||
configs.remove(licenseEntry);
|
||||
}
|
||||
configuration.setConfiguration(configs);
|
||||
WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration);
|
||||
Response.status(Response.Status.CREATED);
|
||||
responseMsg.setResponseMessage("Windows platform configuration saved successfully.");
|
||||
responseMsg.setResponseCode(Response.Status.CREATED.toString());
|
||||
return responseMsg;
|
||||
}
|
||||
else {
|
||||
Response.status(Response.Status.BAD_REQUEST);
|
||||
responseMsg.setResponseMessage("Windows platform configuration can not be saved.");
|
||||
responseMsg.setResponseCode(Response.Status.CREATED.toString());
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
message = "Error Occurred in while configuring Windows Platform.";
|
||||
log.error(message, e);
|
||||
throw new WindowsConfigurationException(message, e);
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Tenant configurations according to the device type.
|
||||
*
|
||||
* @return Tenant configuration object contains specific tenant configurations.
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@GET
|
||||
public PlatformConfiguration getConfiguration() throws WindowsConfigurationException {
|
||||
String msg;
|
||||
PlatformConfiguration PlatformConfiguration = null;
|
||||
try {
|
||||
if (WindowsAPIUtils.getDeviceManagementService().
|
||||
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS) != null) {
|
||||
PlatformConfiguration = WindowsAPIUtils.getDeviceManagementService().
|
||||
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
List<ConfigurationEntry> configs = PlatformConfiguration.getConfiguration();
|
||||
ConfigurationEntry entry = new ConfigurationEntry();
|
||||
License license = WindowsAPIUtils.getDeviceManagementService().getLicense(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, PluginConstants.
|
||||
TenantConfigProperties.LANGUAGE_US);
|
||||
if(license != null) {
|
||||
entry.setContentType(PluginConstants.TenantConfigProperties.CONTENT_TYPE_TEXT);
|
||||
entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY);
|
||||
entry.setValue(license.getText());
|
||||
configs.add(entry);
|
||||
PlatformConfiguration.setConfiguration(configs);
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while retrieving the Windows tenant configuration";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return PlatformConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Tenant Configurations for the specific Device type.
|
||||
*
|
||||
* @param configuration Tenant configurations to be updated.
|
||||
* @return Response message.
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@PUT
|
||||
public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException {
|
||||
String message;
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
try {
|
||||
configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
List<ConfigurationEntry> configs = configuration.getConfiguration();
|
||||
for (ConfigurationEntry entry : configs) {
|
||||
if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) {
|
||||
License license = new License();
|
||||
license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US);
|
||||
license.setVersion("1.0.0");
|
||||
license.setText(entry.getValue().toString());
|
||||
WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license);
|
||||
licenseEntry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (licenseEntry != null) {
|
||||
configs.remove(licenseEntry);
|
||||
}
|
||||
configuration.setConfiguration(configs);
|
||||
WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration);
|
||||
Response.status(Response.Status.CREATED);
|
||||
responseMsg.setResponseMessage("Windows platform configuration succeeded.");
|
||||
responseMsg.setResponseCode(Response.Status.CREATED.toString());
|
||||
} catch (DeviceManagementException e) {
|
||||
message = "Error occurred while modifying configuration settings of Windows platform.";
|
||||
log.error(message, e);
|
||||
throw new WindowsConfigurationException(message, e);
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,114 +18,137 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Windows Device Management REST-API implementation.
|
||||
* All end points supports JSON, XMl with content negotiation.
|
||||
*/
|
||||
@Api(value = "DeviceManagementService", description = "Windows Device Management REST-API implementation.")
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
public interface DeviceManagementService {
|
||||
@WebService
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public class DeviceManagementService {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagementService.class);
|
||||
|
||||
/**
|
||||
* Get all devices.Returns list of Windows devices registered in MDM.
|
||||
*
|
||||
* @return Device List
|
||||
* @throws WindowsConfigurationException
|
||||
* @return Returns retrieved devices.
|
||||
* @throws WindowsConfigurationException occurred while retrieving all the devices from DB.
|
||||
*/
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting Details of All Windows Devices",
|
||||
notes = "Use this REST API to retrieve the details " +
|
||||
"(e.g., the Android device type, serial number, International Mobile Station Equipment Identity " +
|
||||
"(IMEI), owner, version, model etc.) of all Windows devices that are registered with WSO2 EMM.",
|
||||
response = Device.class,
|
||||
responseContainer = "List"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "List of Devices"),
|
||||
@ApiResponse(code = 500, message = "Error occurred while fetching the device list")
|
||||
})
|
||||
List<Device> getAllDevices() throws WindowsConfigurationException;
|
||||
public List<Device> getAllDevices() throws WindowsConfigurationException {
|
||||
String msg;
|
||||
List<Device> devices;
|
||||
try {
|
||||
devices = WindowsAPIUtils.getDeviceManagementService().
|
||||
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while fetching the device list.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Windows device details of a given device Id.
|
||||
*
|
||||
* @param id Device Id
|
||||
* @return Device
|
||||
* @throws WindowsConfigurationException
|
||||
* @return Returns retrieved device.
|
||||
* @throws WindowsConfigurationException occurred while getting device from DB.
|
||||
*/
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting Details of an Windows Device",
|
||||
notes = "Use this REST API to retrieve the details " +
|
||||
"(e.g., the Android device type, serial number, International Mobile Station Equipment Identity " +
|
||||
"(IMEI), owner, version, model etc.) of a specific Windows device that is registered with WSO2 EMM",
|
||||
response = Device.class
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Information of the given device"),
|
||||
@ApiResponse(code = 500, message = "Error occurred while fetching the device information")
|
||||
})
|
||||
org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id)
|
||||
throws WindowsConfigurationException;
|
||||
public Device getDevice(@PathParam("id") String id) throws WindowsConfigurationException {
|
||||
String msg;
|
||||
Device device;
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id);
|
||||
device = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||
if (device == null) {
|
||||
Response.status(Response.Status.NOT_FOUND);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while fetching the device information.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Windows device details of given device id.
|
||||
*
|
||||
* @param id Device Id
|
||||
* @param device Device Details
|
||||
* @return Message
|
||||
* @throws WindowsConfigurationException
|
||||
* @param id Device Id.
|
||||
* @param device Device details to be updated.
|
||||
* @return Returns the message whether device update or not.
|
||||
* @throws WindowsConfigurationException occurred while updating the Device Info.
|
||||
*/
|
||||
@PUT
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Updating the Details of an Windows Device",
|
||||
notes = "Use this REST API to update the details of an Windows device"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 202, message = "The device enrollment details has been updated successfully"),
|
||||
@ApiResponse(code = 500, message = "Error occurred while modifying the device information"),
|
||||
@ApiResponse(code = 304, message = "Device not found for the update")
|
||||
})
|
||||
@Path("{id}")
|
||||
Message updateDevice(@PathParam("id") String id, Device device) throws WindowsConfigurationException;
|
||||
public Message updateDevice(@PathParam("id") String id, Device device) throws WindowsConfigurationException {
|
||||
String msg;
|
||||
Message responseMessage = new Message();
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(id);
|
||||
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
boolean isUpdated;
|
||||
try {
|
||||
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
isUpdated = WindowsAPIUtils.getDeviceManagementService().updateDeviceInfo(deviceIdentifier, device);
|
||||
if (isUpdated) {
|
||||
Response.status(Response.Status.ACCEPTED);
|
||||
responseMessage.setResponseMessage("Device information has modified successfully.");
|
||||
} else {
|
||||
Response.status(Response.Status.NOT_MODIFIED);
|
||||
responseMessage.setResponseMessage("Device not found for the update.");
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while modifying the device information.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the Licence agreement for specific windows platform.
|
||||
*
|
||||
* @return Returns License agreement.
|
||||
* @throws WindowsConfigurationException occurred while getting licence for specific platform and Language.
|
||||
*/
|
||||
@GET
|
||||
@Path("license")
|
||||
@Produces("application/json")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting the License Agreement for Windows Device Registration",
|
||||
notes = "Use this REST API to retrieve the license agreement that is used for the Windows device " +
|
||||
"registration process",
|
||||
response = String.class)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Licence agreement"),
|
||||
@ApiResponse(code = 500, message = "Error occurred while retrieving the license configured for Windows " +
|
||||
"device enrolment")
|
||||
})
|
||||
License getLicense() throws WindowsConfigurationException;
|
||||
public License getLicense() throws WindowsConfigurationException {
|
||||
License license;
|
||||
try {
|
||||
license =
|
||||
WindowsAPIUtils.getDeviceManagementService().getLicense(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS,
|
||||
DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while retrieving the license configured for Windows device enrollment";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return license;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,158 +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.mdm.mobileservices.windows.services.devicemgtservice.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Windows Device Management REST-API implementation.
|
||||
* All end points supports JSON, XMl with content negotiation.
|
||||
*/
|
||||
@WebService
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
public class DeviceManagementServiceImpl {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagementServiceImpl.class);
|
||||
|
||||
/**
|
||||
* Get all devices.Returns list of Windows devices registered in MDM.
|
||||
*
|
||||
* @return Device List
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@GET
|
||||
public List<Device> getAllDevices()
|
||||
throws WindowsConfigurationException {
|
||||
String msg;
|
||||
List<Device> devices;
|
||||
|
||||
try {
|
||||
devices = WindowsAPIUtils.getDeviceManagementService().
|
||||
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while fetching the device list.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Windows device details of a given device Id.
|
||||
*
|
||||
* @param id Device Id
|
||||
* @return Device
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@GET
|
||||
@Path("{id}")
|
||||
public Device getDevice(@PathParam("id") String id)
|
||||
throws WindowsConfigurationException {
|
||||
|
||||
String msg;
|
||||
Device device;
|
||||
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id);
|
||||
device = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||
if (device == null) {
|
||||
Response.status(Response.Status.NOT_FOUND);
|
||||
}
|
||||
} catch (DeviceManagementException deviceMgtEx) {
|
||||
msg = "Error occurred while fetching the device information.";
|
||||
log.error(msg, deviceMgtEx);
|
||||
throw new WindowsConfigurationException(msg, deviceMgtEx);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Windows device details of given device id.
|
||||
*
|
||||
* @param id Device Id
|
||||
* @param device Device Details
|
||||
* @return Message
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
public Message updateDevice(@PathParam("id") String id, Device device)
|
||||
throws WindowsConfigurationException {
|
||||
String msg;
|
||||
Message responseMessage = new Message();
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(id);
|
||||
deviceIdentifier
|
||||
.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
boolean result;
|
||||
try {
|
||||
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
result = WindowsAPIUtils.getDeviceManagementService()
|
||||
.updateDeviceInfo(deviceIdentifier, device);
|
||||
if (result) {
|
||||
Response.status(Response.Status.ACCEPTED);
|
||||
responseMessage.setResponseMessage("Device information has modified successfully.");
|
||||
} else {
|
||||
Response.status(Response.Status.NOT_MODIFIED);
|
||||
responseMessage.setResponseMessage("Device not found for the update.");
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while modifying the device information.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("license")
|
||||
@Produces("application/json")
|
||||
public License getLicense() throws WindowsConfigurationException {
|
||||
License license;
|
||||
|
||||
try {
|
||||
license =
|
||||
WindowsAPIUtils.getDeviceManagementService().getLicense(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS,
|
||||
DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while retrieving the license configured for Windows device enrollment";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,11 +18,8 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.discovery;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.discovery.beans.DiscoveryRequest;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.discovery.beans.DiscoveryResponse;
|
||||
|
||||
@ -44,44 +41,23 @@ import javax.xml.ws.soap.SOAPBinding;
|
||||
@WebService(targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE,
|
||||
name = "IDiscoveryService")
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
@Api(value = "DiscoveryService", description = "Windows Device Management REST-API implementation.")
|
||||
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)
|
||||
@ApiOperation(
|
||||
httpMethod = "POST",
|
||||
value = "Discover the EMM server via REST API.",
|
||||
notes = "Request the server endpoints.",
|
||||
response = DiscoveryResponse.class
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200,
|
||||
message = "Windows policy, policy endpoints, enrollment endpoints and authentication endpoint."),
|
||||
@ApiResponse(code = 500, message = "Internal server error")
|
||||
})
|
||||
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;
|
||||
|
||||
@GET
|
||||
@WebMethod
|
||||
@WebResult()
|
||||
@ApiOperation(
|
||||
httpMethod = "GET",
|
||||
value = "Discover the EMM server via REST API.",
|
||||
notes = "Check the server availability."
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Ok."),
|
||||
@ApiResponse(code = 500, message = "Internal server error.")
|
||||
})
|
||||
Response discoverGet();
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,9 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.discovery.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;
|
||||
@ -30,20 +27,15 @@ import java.io.Serializable;
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "DiscoveryRequest")
|
||||
@SuppressWarnings("unused")
|
||||
@ApiModel(value = "DiscoveryRequest",
|
||||
description = "This class carries all information related to Discovery request.")
|
||||
public class DiscoveryRequest implements Serializable {
|
||||
|
||||
@XmlElement(name = "EmailAddress", required = true)
|
||||
@ApiModelProperty(name = "emailId", value = "Email ID.", required = true)
|
||||
private String emailId;
|
||||
|
||||
@XmlElement(name = "RequestVersion")
|
||||
@ApiModelProperty(name = "version", value = "Request Version.", required = true)
|
||||
private String version;
|
||||
|
||||
@XmlElement(name = "DeviceType")
|
||||
@ApiModelProperty(name = "deviceType", value = "Type of the Device.", required = true)
|
||||
private String deviceType;
|
||||
|
||||
public String getEmailId() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,9 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.discovery.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;
|
||||
@ -30,28 +27,18 @@ import java.io.Serializable;
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "DiscoveryResponse")
|
||||
@SuppressWarnings("unused")
|
||||
@ApiModel(value = "DiscoveryResponse",
|
||||
description = "This class carries all information related to DiscoverResponse.")
|
||||
public class DiscoveryResponse implements Serializable {
|
||||
|
||||
@XmlElement(name = "AuthPolicy")
|
||||
@ApiModelProperty(name = "authPolicy",
|
||||
value = "Authentication policy(On-premise/Federated)", required = true)
|
||||
private String authPolicy;
|
||||
|
||||
@XmlElement(name = "EnrollmentPolicyServiceUrl")
|
||||
@ApiModelProperty(name = "enrollmentPolicyServiceUrl",
|
||||
value = "Enrollment policy(XCEP) endpoint URL.", required = true)
|
||||
private String enrollmentPolicyServiceUrl;
|
||||
|
||||
@XmlElement(name = "EnrollmentServiceUrl")
|
||||
@ApiModelProperty(name = "enrollmentServiceUrl",
|
||||
value = "Enrollment Service(WSTEP) endpoint URL.", required = true)
|
||||
private String enrollmentServiceUrl;
|
||||
|
||||
@XmlElement(name = "AuthenticationServiceUrl")
|
||||
@ApiModelProperty(name = "authenticationServiceUrl",
|
||||
value = "SOAP request authentication service URL", required = true)
|
||||
private String authenticationServiceUrl;
|
||||
|
||||
public void setAuthenticationServiceUrl(String authenticationServiceUrl) {
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
/*
|
||||
* 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) 2015, 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",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -20,22 +20,22 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.discovery.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.beans.WindowsPluginProperties;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.discovery.beans.DiscoveryRequest;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.discovery.DiscoveryService;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.discovery.beans.DiscoveryRequest;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.discovery.beans.DiscoveryResponse;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.jws.WebService;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.core.Response;
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* Implementation class of Discovery Request. This class implements the first two services
|
||||
@ -48,9 +48,9 @@ import javax.xml.ws.soap.SOAPBinding;
|
||||
public class DiscoveryServiceImpl implements DiscoveryService {
|
||||
|
||||
public static final String FEDERATED = "Federated";
|
||||
private static final String DELIMITER = "@";
|
||||
private static final int DOMAIN_SEGMENT = 1;
|
||||
private static Log log = LogFactory.getLog(DiscoveryServiceImpl.class);
|
||||
@Resource
|
||||
private WebServiceContext context;
|
||||
|
||||
/**
|
||||
* This method returns the OnPremise AuthPolicy and next two endpoint the mobile device should
|
||||
@ -61,35 +61,26 @@ public class DiscoveryServiceImpl implements DiscoveryService {
|
||||
* @param response - DiscoveryResponse bean for response
|
||||
*/
|
||||
@Override
|
||||
public void discover(DiscoveryRequest discoveryRequest, Holder<DiscoveryResponse> response) {
|
||||
public void discover(DiscoveryRequest discoveryRequest, Holder<DiscoveryResponse> response)
|
||||
throws WindowsDeviceEnrolmentException {
|
||||
|
||||
ServletContext ctx = (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
|
||||
WindowsPluginProperties windowsPluginProperties = (WindowsPluginProperties) ctx.getAttribute(
|
||||
PluginConstants.WINDOWS_PLUGIN_PROPERTIES);
|
||||
String emailId = discoveryRequest.getEmailId();
|
||||
String[] userDomains = emailId.split(DELIMITER);
|
||||
String domain = userDomains[DOMAIN_SEGMENT];
|
||||
|
||||
DiscoveryResponse discoveryResponse = new DiscoveryResponse();
|
||||
if (FEDERATED.equals(windowsPluginProperties.getAuthPolicy())) {
|
||||
discoveryResponse.setAuthPolicy(windowsPluginProperties.getAuthPolicy());
|
||||
discoveryResponse.setEnrollmentPolicyServiceUrl(PluginConstants.Discovery.ENROLL_SUBDOMAIN +
|
||||
windowsPluginProperties.getDomain() + PluginConstants.Discovery.
|
||||
if (FEDERATED.equals(getAuthPolicy())) {
|
||||
discoveryResponse.setAuthPolicy(FEDERATED);
|
||||
discoveryResponse.setEnrollmentPolicyServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.
|
||||
CERTIFICATE_ENROLLMENT_POLICY_SERVICE_URL);
|
||||
discoveryResponse.setEnrollmentServiceUrl(PluginConstants.Discovery.ENROLL_SUBDOMAIN +
|
||||
windowsPluginProperties.getDomain() + PluginConstants.Discovery.
|
||||
discoveryResponse.setEnrollmentServiceUrl(PluginConstants.Discovery.DEVICE_ENROLLMENT_SUBDOMAIN +
|
||||
domain + PluginConstants.Discovery.
|
||||
CERTIFICATE_ENROLLMENT_SERVICE_URL);
|
||||
discoveryResponse.setAuthenticationServiceUrl(PluginConstants.Discovery.ENROLL_SUBDOMAIN +
|
||||
windowsPluginProperties.getDomain() + PluginConstants.Discovery.WAB_URL);
|
||||
} else {
|
||||
discoveryResponse.setAuthPolicy(windowsPluginProperties.getAuthPolicy());
|
||||
discoveryResponse.setEnrollmentPolicyServiceUrl(PluginConstants.Discovery.ENROLL_SUBDOMAIN +
|
||||
windowsPluginProperties.getDomain() + PluginConstants.Discovery.
|
||||
ONPREMISE_CERTIFICATE_ENROLLMENT_POLICY);
|
||||
discoveryResponse.setEnrollmentServiceUrl(PluginConstants.Discovery.ENROLL_SUBDOMAIN +
|
||||
windowsPluginProperties.getDomain() + PluginConstants.Discovery.
|
||||
ONPREMISE_CERTIFICATE_ENROLLMENT_SERVICE_URL);
|
||||
discoveryResponse.setAuthenticationServiceUrl(null);
|
||||
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");
|
||||
}
|
||||
@ -109,4 +100,37 @@ public class DiscoveryServiceImpl implements DiscoveryService {
|
||||
}
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,35 +18,54 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Endpoint for Enforce Effective Policy.
|
||||
*/
|
||||
@Api(value = "PolicyMgtService", description = "Windows Device Management REST-API implementation.")
|
||||
@WebService
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
public interface PolicyMgtService {
|
||||
public class PolicyMgtService {
|
||||
private static Log log = LogFactory.getLog(PolicyMgtService.class);
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@ApiOperation(
|
||||
httpMethod = "GET",
|
||||
value = "Identifying whether a Policy is Enforced on an Windows Device",
|
||||
notes = "When a device registers with WSO2 EMM, a policy is enforced on the device based on the policy " +
|
||||
"enforcement criteria. Using this API you are able to identify if a specific device has a policy " +
|
||||
"enforced or if no policy is enforced on the device."
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Effective policy added to operation"),
|
||||
@ApiResponse(code = 204, message = "No effective policy found")
|
||||
})
|
||||
Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader,
|
||||
@PathParam("id") String id) throws WindowsConfigurationException;
|
||||
public Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader,
|
||||
@PathParam("id") String id) throws WindowsConfigurationException {
|
||||
|
||||
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id);
|
||||
Message responseMessage = new Message();
|
||||
Policy policy;
|
||||
try {
|
||||
PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService();
|
||||
policy = policyManagerService.getEffectivePolicy(deviceIdentifier);
|
||||
if (policy == null) {
|
||||
responseMessage.setResponseCode(Response.Status.NO_CONTENT.toString());
|
||||
responseMessage.setResponseMessage("No effective policy found");
|
||||
return responseMessage;
|
||||
} else {
|
||||
responseMessage.setResponseCode(Response.Status.OK.toString());
|
||||
responseMessage.setResponseMessage("Effective policy added to operation");
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred while getting the policy.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.mdm.mobileservices.windows.services.policymgtservice.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.PolicyMgtService;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Endpoint for Enforce Effective Policy.
|
||||
*/
|
||||
|
||||
@WebService
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
public class PolicyMgtServiceImpl implements PolicyMgtService {
|
||||
private static Log log = LogFactory.getLog(PolicyMgtServiceImpl.class);
|
||||
|
||||
@GET
|
||||
public Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader,
|
||||
@PathParam("id") String id) throws WindowsConfigurationException {
|
||||
|
||||
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id);
|
||||
Message responseMessage = new Message();
|
||||
Policy policy;
|
||||
try {
|
||||
PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService();
|
||||
policy = policyManagerService.getEffectivePolicy(deviceIdentifier);
|
||||
if (policy == null) {
|
||||
responseMessage.setResponseCode(Response.Status.NO_CONTENT.toString());
|
||||
responseMessage.setResponseMessage("No effective policy found");
|
||||
return responseMessage;
|
||||
} else {
|
||||
responseMessage.setResponseCode(Response.Status.OK.toString());
|
||||
responseMessage.setResponseMessage("Effective policy added to operation");
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred while getting the policy.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,10 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.syncml;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
@ -39,7 +35,6 @@ import javax.ws.rs.core.Response;
|
||||
/**
|
||||
* Interface for Syncml message flow.
|
||||
*/
|
||||
@Api(value = "SyncmlService", description = "Windows Device Management REST-API implementation.")
|
||||
@Path("/devicemanagement")
|
||||
public interface SyncmlService {
|
||||
|
||||
@ -47,17 +42,6 @@ public interface SyncmlService {
|
||||
@POST
|
||||
@Consumes({PluginConstants.SYNCML_MEDIA_TYPE, MediaType.APPLICATION_XML})
|
||||
@Produces(PluginConstants.SYNCML_MEDIA_TYPE)
|
||||
@ApiOperation(
|
||||
consumes = "application/vnd.syncml.dm+xml;charset=utf-8",
|
||||
produces = "application/vnd.syncml.dm+xml;charset=utf-8",
|
||||
httpMethod = "POST",
|
||||
value = "Windows Device Management service REST API",
|
||||
notes = "Windows device management session"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Successfully completed syncml session"),
|
||||
@ApiResponse(code = 500, message = "Internal server error")
|
||||
})
|
||||
Response getResponse(Document request) throws WindowsDeviceEnrolmentException, WindowsOperationException,
|
||||
NotificationManagementException, WindowsConfigurationException;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,16 +18,11 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Bean for get basic operations.
|
||||
*/
|
||||
@ApiModel(value = "BasicOperation",
|
||||
description = "This class carries all information related to Basic operation.")
|
||||
public class BasicOperation {
|
||||
@ApiModelProperty(name = "name", value = "Name of the basic operation.", required = true)
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,38 +18,19 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Bean for device lockOperationUpdate screen passcode policy.
|
||||
* Bean for device updateLockOperation screen passcode policy.
|
||||
*/
|
||||
@ApiModel(value = "PasscodePolicy",
|
||||
description = "This class carries all information related to Passcode Policy.")
|
||||
public class PasscodePolicy extends BasicOperation {
|
||||
|
||||
@ApiModelProperty(name = "maxFailedAttempts", value = "No of Max fail attempts.", required = true)
|
||||
private int maxFailedAttempts;
|
||||
@ApiModelProperty(name = "minLength", value = "Minimum length of the Passcode.", required = true)
|
||||
private int minLength;
|
||||
@ApiModelProperty(name = "pinHistory",
|
||||
value = "The number of passwords Windows 10 Mobile remembers in the password history.", required = true)
|
||||
private int pinHistory;
|
||||
@ApiModelProperty(name = "minComplexChars",
|
||||
value = "The number of password element types (in other words, uppercase letters, lowercase letters, " +
|
||||
"numbers, or punctuation) required to create strong passwords.", required = true)
|
||||
private int minComplexChars;
|
||||
@ApiModelProperty(name = "maxPINAgeInDays",
|
||||
value = "Number of Maximum days to expire the passcode.", required = true)
|
||||
private int maxPINAgeInDays;
|
||||
@ApiModelProperty(name = "requireAlphanumeric",
|
||||
value = "An integer value that specifies the complexity of the password or PIN allowed.", required = true)
|
||||
private boolean requireAlphanumeric;
|
||||
@ApiModelProperty(name = "allowSimple", value = "Set boolean value to allow simple password.", required = true)
|
||||
private boolean allowSimple;
|
||||
@ApiModelProperty(name = "enablePassword", value = "Set boolean value enable password.", required = true)
|
||||
private boolean enablePassword;
|
||||
@ApiModelProperty(name = "maxInactiveTime", value = "Maximum Inactive time.", required = true)
|
||||
private int maxInactiveTime;
|
||||
|
||||
public int getMaxInactiveTime() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,23 +18,14 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Class for contains device active policy.
|
||||
*/
|
||||
@ApiModel(value = "Profile",
|
||||
description = "This class carries all information related to Profile features.")
|
||||
public class Profile {
|
||||
|
||||
@ApiModelProperty(name = "featureCode", value = "Profile type operation feature code.", required = true)
|
||||
String featureCode;
|
||||
@ApiModelProperty(name = "data", value = "Profile type operation data content..", required = true)
|
||||
String data;
|
||||
@ApiModelProperty(name = "enable", value = "Status of the Profile operation.", required = true)
|
||||
boolean enable;
|
||||
@ApiModelProperty(name = "compliance", value = "Status of the operation compliance.", required = true)
|
||||
boolean compliance;
|
||||
|
||||
public boolean isCompliance() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -18,33 +18,19 @@
|
||||
|
||||
package org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Bean for WIFI configurations.
|
||||
*/
|
||||
@ApiModel(value = "Wifi",
|
||||
description = "This class carries all information related to Wifi policy.")
|
||||
public class Wifi extends BasicOperation {
|
||||
|
||||
@ApiModelProperty(name = "networkName", value = "Name of the Wifi Network.", required = true)
|
||||
private String networkName;
|
||||
@ApiModelProperty(name = "ssid", value = "SSID.", required = true)
|
||||
private String ssid;
|
||||
@ApiModelProperty(name = "connectionType", value = "Type of the connection.", required = true)
|
||||
private String connectionType;
|
||||
@ApiModelProperty(name = "connectionMode", value = "Connection mode.", required = true)
|
||||
private String connectionMode;
|
||||
@ApiModelProperty(name = "authentication", value = "Authentication type.", required = true)
|
||||
private String authentication;
|
||||
@ApiModelProperty(name = "encryption", value = "Encryption type.", required = true)
|
||||
private String encryption;
|
||||
@ApiModelProperty(name = "keyType", value = "Key type.", required = true)
|
||||
private String keyType;
|
||||
@ApiModelProperty(name = "protection", value = "Protection.", required = true)
|
||||
private String protection;
|
||||
@ApiModelProperty(name = "keyMaterial", value = "Key Material.", required = true)
|
||||
private String keyMaterial;
|
||||
|
||||
public String getNetworkName() {
|
||||
|
||||
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.mdm.mobileservices.windows.services.syncml.beans;
|
||||
|
||||
/**
|
||||
* Class for get windows device properties.
|
||||
*/
|
||||
public class WindowsDevice {
|
||||
|
||||
private String deviceType;
|
||||
private String deviceId;
|
||||
private String osVersion;
|
||||
private String imsi;
|
||||
private String imei;
|
||||
private String manufacturer;
|
||||
private String model;
|
||||
private String user;
|
||||
|
||||
public String getImei() {
|
||||
return imei;
|
||||
}
|
||||
|
||||
public void setImei(String imei) {
|
||||
this.imei = imei;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getOsVersion() {
|
||||
return osVersion;
|
||||
}
|
||||
|
||||
public void setOsVersion(String osVersion) {
|
||||
this.osVersion = osVersion;
|
||||
}
|
||||
|
||||
public String getImsi() {
|
||||
return imsi;
|
||||
}
|
||||
|
||||
public void setImsi(String imsi) {
|
||||
this.imsi = imsi;
|
||||
}
|
||||
|
||||
public String getManufacturer() {
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
public void setManufacturer(String manufacturer) {
|
||||
this.manufacturer = manufacturer;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -20,7 +20,6 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.syncml.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
@ -33,13 +32,14 @@ import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.SyncmlMessag
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.SyncmlOperationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsDeviceEnrolmentException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.AuthenticationInfo;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.DeviceUtil;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.*;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.operations.util.*;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.syncml.SyncmlService;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans.WindowsDevice;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
@ -59,38 +59,32 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
* This method is used to generate and return Device object from the received information at
|
||||
* the Syncml step.
|
||||
*
|
||||
* @param deviceID - Unique device ID received from the Device
|
||||
* @param osVersion - Device OS version
|
||||
* @param imsi - Device IMSI
|
||||
* @param imei - Device IMEI
|
||||
* @param manufacturer - Device Manufacturer name
|
||||
* @param model - Device Model
|
||||
* @return - Generated device object
|
||||
* @param windowsDevice Windows specific property object.
|
||||
* @return - Generated device object.
|
||||
*/
|
||||
private Device generateDevice(String type, String deviceID, String osVersion, String imsi,
|
||||
String imei, String manufacturer, String model, String user) {
|
||||
private Device generateDevice(WindowsDevice windowsDevice) {
|
||||
|
||||
Device generatedDevice = new Device();
|
||||
|
||||
Device.Property OSVersionProperty = new Device.Property();
|
||||
OSVersionProperty.setName(PluginConstants.SyncML.OS_VERSION);
|
||||
OSVersionProperty.setValue(osVersion);
|
||||
OSVersionProperty.setValue(windowsDevice.getOsVersion());
|
||||
|
||||
Device.Property IMSEIProperty = new Device.Property();
|
||||
IMSEIProperty.setName(PluginConstants.SyncML.IMSI);
|
||||
IMSEIProperty.setValue(imsi);
|
||||
IMSEIProperty.setValue(windowsDevice.getImsi());
|
||||
|
||||
Device.Property IMEIProperty = new Device.Property();
|
||||
IMEIProperty.setName(PluginConstants.SyncML.IMEI);
|
||||
IMEIProperty.setValue(imei);
|
||||
IMEIProperty.setValue(windowsDevice.getImei());
|
||||
|
||||
Device.Property DevManProperty = new Device.Property();
|
||||
DevManProperty.setName(PluginConstants.SyncML.VENDOR);
|
||||
DevManProperty.setValue(manufacturer);
|
||||
DevManProperty.setValue(windowsDevice.getManufacturer());
|
||||
|
||||
Device.Property DevModProperty = new Device.Property();
|
||||
DevModProperty.setName(PluginConstants.SyncML.MODEL);
|
||||
DevModProperty.setValue(model);
|
||||
DevModProperty.setValue(windowsDevice.getModel());
|
||||
|
||||
List<Device.Property> propertyList = new ArrayList<>();
|
||||
propertyList.add(OSVersionProperty);
|
||||
@ -100,14 +94,14 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
propertyList.add(DevModProperty);
|
||||
|
||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||
enrolmentInfo.setOwner(user);
|
||||
enrolmentInfo.setOwner(windowsDevice.getUser());
|
||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||
|
||||
generatedDevice.setEnrolmentInfo(enrolmentInfo);
|
||||
generatedDevice.setDeviceIdentifier(deviceID);
|
||||
generatedDevice.setDeviceIdentifier(windowsDevice.getDeviceId());
|
||||
generatedDevice.setProperties(propertyList);
|
||||
generatedDevice.setType(type);
|
||||
generatedDevice.setType(windowsDevice.getDeviceType());
|
||||
|
||||
return generatedDevice;
|
||||
}
|
||||
@ -133,48 +127,29 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
SyncmlDocument syncmlDocument;
|
||||
List<Operation> deviceInfoOperations;
|
||||
List<? extends Operation> pendingOperations;
|
||||
OperationUtils operationUtils = new OperationUtils();
|
||||
OperationHandler operationHandler = new OperationHandler();
|
||||
DeviceInfo deviceInfo = new DeviceInfo();
|
||||
|
||||
try {
|
||||
if (SyncmlParser.parseSyncmlPayload(request) != null) {
|
||||
try {
|
||||
syncmlDocument = SyncmlParser.parseSyncmlPayload(request);
|
||||
} catch (SyncmlMessageFormatException e) {
|
||||
String msg = "Error occurred due to bad syncml format.";
|
||||
log.error(msg, e);
|
||||
throw new SyncmlMessageFormatException(msg, e);
|
||||
}
|
||||
SyncmlHeader syncmlHeader = syncmlDocument.getHeader();
|
||||
sessionId = syncmlHeader.getSessionId();
|
||||
user = syncmlHeader.getSource().getLocName();
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource()
|
||||
.getLocURI());
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource().
|
||||
getLocURI());
|
||||
msgId = syncmlHeader.getMsgID();
|
||||
if ((PluginConstants.SyncML.SYNCML_FIRST_MESSAGE_ID == msgId) &&
|
||||
(PluginConstants.SyncML.SYNCML_FIRST_SESSION_ID == sessionId)) {
|
||||
token = syncmlHeader.getCredential().getData();
|
||||
CacheEntry cacheToken = (CacheEntry) DeviceUtil.getCacheEntry(token);
|
||||
|
||||
if (cacheToken.getUsername().equals(user)) {
|
||||
if ((cacheToken.getUsername() != null) && (cacheToken.getUsername().equals(user))) {
|
||||
|
||||
if (enrollDevice(request)) {
|
||||
deviceInfoOperations = deviceInfo.getDeviceInfo();
|
||||
try {
|
||||
response = generateReply(syncmlDocument, deviceInfoOperations);
|
||||
PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService();
|
||||
policyManagerService.getEffectivePolicy(deviceIdentifier);
|
||||
return Response.status(Response.Status.OK).entity(response).build();
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred in while getting effective policy.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
} catch (SyncmlOperationException e) {
|
||||
String msg = "Error occurred in while generating hash value.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
}
|
||||
|
||||
} else {
|
||||
String msg = "Error occurred in device enrollment.";
|
||||
log.error(msg);
|
||||
@ -187,15 +162,8 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
}
|
||||
} else if (PluginConstants.SyncML.SYNCML_SECOND_MESSAGE_ID == msgId &&
|
||||
PluginConstants.SyncML.SYNCML_FIRST_SESSION_ID == sessionId) {
|
||||
|
||||
if (enrollDevice(request)) {
|
||||
try {
|
||||
return Response.ok().entity(generateReply(syncmlDocument, null)).build();
|
||||
} catch (SyncmlOperationException e) {
|
||||
String msg = "Error occurred in while getting effective feature";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
}
|
||||
} else {
|
||||
String msg = "Error occurred in modify enrollment.";
|
||||
log.error(msg);
|
||||
@ -204,35 +172,9 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
} else if (sessionId >= PluginConstants.SyncML.SYNCML_SECOND_SESSION_ID) {
|
||||
if ((syncmlDocument.getBody().getAlert() != null)) {
|
||||
if (!syncmlDocument.getBody().getAlert().getData().equals(Constants.DISENROLL_ALERT_DATA)) {
|
||||
try {
|
||||
pendingOperations = operationUtils.getPendingOperations(syncmlDocument);
|
||||
pendingOperations = operationHandler.getPendingOperations(syncmlDocument);
|
||||
return Response.ok().entity(generateReply(syncmlDocument, pendingOperations)).build();
|
||||
} catch (OperationManagementException e) {
|
||||
String msg = "Cannot access operation management service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Cannot access Device management service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (FeatureManagementException e) {
|
||||
String msg = "Error occurred in getting effective features. ";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (PolicyComplianceException e) {
|
||||
String msg = "Error occurred in setting policy compliance.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
} catch (NotificationManagementException e) {
|
||||
String msg = "Error occurred in while getting notification service";
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (SyncmlOperationException e) {
|
||||
String msg = "Error occurred in while encoding hash value.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier) != null) {
|
||||
WindowsAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
||||
return Response.ok().entity(generateReply(syncmlDocument, null)).build();
|
||||
@ -241,46 +183,10 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Failure occurred in dis-enrollment flow.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (SyncmlOperationException e) {
|
||||
String msg = "Error occurred in while generating hash value.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
pendingOperations = operationUtils.getPendingOperations(syncmlDocument);
|
||||
return Response.ok().entity(generateReply(syncmlDocument, pendingOperations))
|
||||
.build();
|
||||
} catch (OperationManagementException e) {
|
||||
String msg = "Cannot access operation management service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Cannot access Device management service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (FeatureManagementException e) {
|
||||
String msg = "Error occurred in getting effective features. ";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
} catch (PolicyComplianceException e) {
|
||||
String msg = "Error occurred in setting policy compliance.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
} catch (NotificationManagementException e) {
|
||||
String msg = "Error occurred in while getting notification service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (SyncmlOperationException e) {
|
||||
String msg = "Error occurred in while getting effective feature.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
pendingOperations = operationHandler.getPendingOperations(syncmlDocument);
|
||||
return Response.ok().entity(generateReply(syncmlDocument, pendingOperations)).build();
|
||||
}
|
||||
} else {
|
||||
String msg = "Failure occurred in Device request message.";
|
||||
@ -289,7 +195,19 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
}
|
||||
}
|
||||
} catch (SyncmlMessageFormatException e) {
|
||||
String msg = "Error occurred in parsing syncml request.";
|
||||
String msg = "Error occurred while parsing syncml request.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (OperationManagementException e) {
|
||||
String msg = "Cannot access operation management service.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
} catch (SyncmlOperationException e) {
|
||||
String msg = "Error occurred while getting effective feature.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Failure occurred in dis-enrollment flow.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
}
|
||||
@ -314,7 +232,7 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
String devMan;
|
||||
String devMod;
|
||||
String devLang;
|
||||
String vender;
|
||||
String vendor;
|
||||
String macAddress;
|
||||
String resolution;
|
||||
String modVersion;
|
||||
@ -328,40 +246,51 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
syncmlDocument = SyncmlParser.parseSyncmlPayload(request);
|
||||
msgID = syncmlDocument.getHeader().getMsgID();
|
||||
if (msgID == PluginConstants.SyncML.SYNCML_FIRST_MESSAGE_ID) {
|
||||
Replace replace = syncmlDocument.getBody().getReplace();
|
||||
List<Item> itemList = replace.getItems();
|
||||
ReplaceTag replace = syncmlDocument.getBody().getReplace();
|
||||
List<ItemTag> itemList = replace.getItems();
|
||||
devID = itemList.get(PluginConstants.SyncML.DEVICE_ID_POSITION).getData();
|
||||
devMan = itemList.get(PluginConstants.SyncML.DEVICE_MAN_POSITION).getData();
|
||||
devMod = itemList.get(PluginConstants.SyncML.DEVICE_MODEL_POSITION).getData();
|
||||
modVersion = itemList.get(PluginConstants.SyncML.DEVICE_MOD_VER_POSITION).getData();
|
||||
devLang = itemList.get(PluginConstants.SyncML.DEVICE_LANG_POSITION).getData();
|
||||
user = syncmlDocument.getHeader().getSource().getLocName();
|
||||
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
|
||||
authenticationInfo.setUsername(user);
|
||||
WindowsAPIUtils.startTenantFlow(authenticationInfo);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"OS Version:" + modVersion + ", DevID: " + devID + ", DevMan: " + devMan +
|
||||
", DevMod: " + devMod + ", DevLang: " + devLang);
|
||||
}
|
||||
Device generateDevice = generateDevice(DeviceManagementConstants.MobileDeviceTypes.
|
||||
MOBILE_DEVICE_TYPE_WINDOWS, devID, modVersion, imsi, imei, devMan, devMod, user);
|
||||
status = WindowsAPIUtils.getDeviceManagementService().enrollDevice(generateDevice);
|
||||
WindowsAPIUtils.startTenantFlow(user);
|
||||
WindowsDevice windowsDevice = new WindowsDevice();
|
||||
windowsDevice.setDeviceType(DeviceManagementConstants.MobileDeviceTypes.
|
||||
MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
windowsDevice.setDeviceId(devID);
|
||||
windowsDevice.setImei(imei);
|
||||
windowsDevice.setImsi(imsi);
|
||||
windowsDevice.setManufacturer(devMan);
|
||||
windowsDevice.setOsVersion(modVersion);
|
||||
windowsDevice.setModel(devMod);
|
||||
windowsDevice.setUser(user);
|
||||
Device device = generateDevice(windowsDevice);
|
||||
status = WindowsAPIUtils.getDeviceManagementService().enrollDevice(device);
|
||||
return status;
|
||||
|
||||
} else if (msgID == PluginConstants.SyncML.SYNCML_SECOND_MESSAGE_ID) {
|
||||
List<Item> itemList = syncmlDocument.getBody().getResults().getItem();
|
||||
|
||||
List<ItemTag> itemList = syncmlDocument.getBody().getResults().getItem();
|
||||
osVersion = itemList.get(PluginConstants.SyncML.OSVERSION_POSITION).getData();
|
||||
imsi = itemList.get(PluginConstants.SyncML.IMSI_POSITION).getData();
|
||||
imei = itemList.get(PluginConstants.SyncML.IMEI_POSITION).getData();
|
||||
vender = itemList.get(PluginConstants.SyncML.VENDER_POSITION).getData();
|
||||
vendor = itemList.get(PluginConstants.SyncML.VENDOR_POSITION).getData();
|
||||
devMod = itemList.get(PluginConstants.SyncML.MODEL_POSITION).getData();
|
||||
macAddress = itemList.get(PluginConstants.SyncML.MACADDRESS_POSITION).getData();
|
||||
macAddress = itemList.get(PluginConstants.SyncML.MAC_ADDRESS_POSITION).getData();
|
||||
resolution = itemList.get(PluginConstants.SyncML.RESOLUTION_POSITION).getData();
|
||||
deviceName = itemList.get(PluginConstants.SyncML.DEVICE_NAME_POSITION).getData();
|
||||
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlDocument.
|
||||
getHeader().getSource().getLocURI());
|
||||
Device existingDevice = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||
|
||||
if (!existingDevice.getProperties().isEmpty()) {
|
||||
List<Device.Property> existingProperties = new ArrayList<>();
|
||||
|
||||
@ -380,10 +309,10 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
imsiProperty.setValue(imsi);
|
||||
existingProperties.add(imsiProperty);
|
||||
|
||||
Device.Property venderProperty = new Device.Property();
|
||||
venderProperty.setName(PluginConstants.SyncML.VENDOR);
|
||||
venderProperty.setValue(vender);
|
||||
existingProperties.add(venderProperty);
|
||||
Device.Property vendorProperty = new Device.Property();
|
||||
vendorProperty.setName(PluginConstants.SyncML.VENDOR);
|
||||
vendorProperty.setValue(vendor);
|
||||
existingProperties.add(vendorProperty);
|
||||
|
||||
Device.Property macAddressProperty = new Device.Property();
|
||||
macAddressProperty.setName(PluginConstants.SyncML.MAC_ADDRESS);
|
||||
@ -416,17 +345,9 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Failure occurred in enrolling device.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException(msg, e);
|
||||
} catch (SyncmlMessageFormatException e) {
|
||||
String msg = "Error occurred in bad format of the syncml payload.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
throw new WindowsDeviceEnrolmentException("Failure occurred while enrolling device.", e);
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred in getting effective policy.";
|
||||
log.error(msg, e);
|
||||
throw new WindowsOperationException(msg, e);
|
||||
throw new WindowsOperationException("Error occurred while getting effective policy.", e);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
@ -436,11 +357,10 @@ public class SyncmlServiceImpl implements SyncmlService {
|
||||
/**
|
||||
* Generate Device payloads.
|
||||
*
|
||||
* @param syncmlDocument parsed syncml payload from the syncml engine.
|
||||
* @param operations operations for generate payload.
|
||||
* @param syncmlDocument Parsed syncml payload from the syncml engine.
|
||||
* @param operations Operations for generate payload.
|
||||
* @return String type syncml payload.
|
||||
* @throws WindowsOperationException
|
||||
* @throws JSONException
|
||||
* @throws PolicyManagementException
|
||||
* @throws org.wso2.carbon.policy.mgt.common.FeatureManagementException
|
||||
*/
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -20,11 +20,7 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.wstep.beans;
|
||||
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "BinarySecurityToken", namespace = PluginConstants.WS_SECURITY_TARGET_NAMESPACE,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user