forked from community/device-mgt-plugins
commit
fedd717561
@ -1 +1,29 @@
|
||||
{{unit "mdm.unit.policy.wizard"}}
|
||||
<div class="container col-centered wr-content policy-profile">
|
||||
<div class="wr-form">
|
||||
<h1 id="policy-profile-page-wizard-title" class="page-sub-title">ADD POLICY</h1>
|
||||
<hr>
|
||||
<div id="policy-profile-wizard-steps" class="row wr-wizard"></div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h4 class="visible-xs">Step 2: Configure profile</h4>
|
||||
<br>
|
||||
<div id="policy-profile-main-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
<div class="wr-advance-operations">
|
||||
<div class="wr-advance-operations-init">
|
||||
<br>
|
||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||
Loading platform features . . .
|
||||
<br><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wr-input-control wr-btn-grp">
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper" data-is-back-btn="true" data-current="policy-profile" data-next="policy-platform">Back</a>
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper" data-current="policy-profile" data-next="policy-criteria" data-validate="true">Continue</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -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,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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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,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) {
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
15
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Alert.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/AlertTag.java
15
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Alert.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/AlertTag.java
14
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Credential.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/CredentialTag.java
14
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Credential.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/CredentialTag.java
24
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Get.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/GetTag.java
24
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Get.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/GetTag.java
29
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Item.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/ItemTag.java
29
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Item.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/ItemTag.java
24
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Replace.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/ReplaceTag.java
24
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Replace.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/ReplaceTag.java
26
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Results.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/ResultsTag.java
26
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Results.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/ResultsTag.java
27
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Source.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/SourceTag.java
27
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Source.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/SourceTag.java
27
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Status.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/StatusTag.java
27
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Status.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/StatusTag.java
14
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Target.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/TargetTag.java
14
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/Target.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/TargetTag.java
@ -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,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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
24
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/SyncmlCredentials.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/SyncmlCredentialUtil.java
24
components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/SyncmlCredentials.java → components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/SyncmlCredentialUtil.java
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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,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,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue