forked from community/device-mgt-plugins
parent
ab037716ad
commit
8eb53927a6
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for dis-enrollment operation
|
|
||||||
*/
|
|
||||||
public class Disenrollment implements Serializable {
|
|
||||||
|
|
||||||
private boolean enabled;
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEnable() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans;
|
|
||||||
|
|
||||||
import org.wso2.carbon.mdm.mobileservices.windows.services.syncml.beans.BasicOperation;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for set basic operations.
|
|
||||||
*/
|
|
||||||
public class OperationRequest {
|
|
||||||
|
|
||||||
private List<Device> deviceList;
|
|
||||||
private BasicOperation basicOperation;
|
|
||||||
|
|
||||||
public BasicOperation getBasicOperation() {
|
|
||||||
return basicOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicOperation(BasicOperation basicOperation) {
|
|
||||||
this.basicOperation = basicOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Device> getDeviceList() {
|
|
||||||
return deviceList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceList(List<Device> deviceList) {
|
|
||||||
this.deviceList = deviceList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This bean class is for credentials coming from wab page at federated authentication step.
|
|
||||||
*/
|
|
||||||
public class OperationResponse {
|
|
||||||
|
|
||||||
private String errorCode;
|
|
||||||
private String statusCode;
|
|
||||||
|
|
||||||
public OperationResponse() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorCode() {
|
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorCode(String errorCode) {
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusCode(String statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents the information of encrypt operation.
|
|
||||||
*/
|
|
||||||
public class StorageEncryption implements Serializable {
|
|
||||||
private boolean encrypted;
|
|
||||||
|
|
||||||
public boolean isEncrypted() {
|
|
||||||
return encrypted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEncrypted(boolean encrypted) {
|
|
||||||
this.encrypted = encrypted;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +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.adminoperations.beans.wrapper;
|
|
||||||
|
|
||||||
import org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans.Disenrollment;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class is used to wrap dis-enrollment bean with the device
|
|
||||||
*/
|
|
||||||
public class DisenrollmentBeanWrapper {
|
|
||||||
|
|
||||||
private Disenrollment operation;
|
|
||||||
|
|
||||||
private List<String> deviceId;
|
|
||||||
|
|
||||||
public Disenrollment getOperation() {
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperation(Disenrollment operation) {
|
|
||||||
this.operation = operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(List<String> deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans.wrapper;
|
|
||||||
|
|
||||||
import org.wso2.carbon.mdm.mobileservices.windows.services.adminoperations.beans.StorageEncryption;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to wrap the Encrypt bean with devices.
|
|
||||||
*/
|
|
||||||
public class EncryptBeanWrapper {
|
|
||||||
|
|
||||||
private StorageEncryption operation;
|
|
||||||
private List<String> deviceIDs;
|
|
||||||
|
|
||||||
public StorageEncryption getOperation() {
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperation(StorageEncryption operation) {
|
|
||||||
this.operation = operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getDeviceIDs() {
|
|
||||||
return deviceIDs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceIDs(List<String> deviceIDs) {
|
|
||||||
this.deviceIDs = deviceIDs;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,112 +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.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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* 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.TenantConfiguration;
|
||||||
|
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(TenantConfiguration 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 TenantConfiguration getConfiguration() throws WindowsConfigurationException {
|
||||||
|
String msg;
|
||||||
|
TenantConfiguration tenantConfiguration = null;
|
||||||
|
try {
|
||||||
|
if (WindowsAPIUtils.getDeviceManagementService().
|
||||||
|
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS) != null) {
|
||||||
|
tenantConfiguration = WindowsAPIUtils.getDeviceManagementService().
|
||||||
|
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||||
|
List<ConfigurationEntry> configs = tenantConfiguration.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);
|
||||||
|
tenantConfiguration.setConfiguration(configs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
msg = "Error occurred while retrieving the Windows tenant configuration";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new WindowsConfigurationException(msg, e);
|
||||||
|
}
|
||||||
|
return tenantConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Tenant Configurations for the specific Device type.
|
||||||
|
*
|
||||||
|
* @param configuration Tenant configurations to be updated.
|
||||||
|
* @return Response message.
|
||||||
|
* @throws WindowsConfigurationException
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
public Message updateConfiguration(TenantConfiguration 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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||||
|
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||||
|
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.PolicyMgtService;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint for Enforce Effective Policy.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@WebService
|
||||||
|
@Produces({"application/json", "application/xml"})
|
||||||
|
@Consumes({"application/json", "application/xml"})
|
||||||
|
public class PolicyMgtServiceImpl implements PolicyMgtService {
|
||||||
|
private static Log log = LogFactory.getLog(PolicyMgtServiceImpl.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader,
|
||||||
|
@PathParam("id") String id) throws WindowsConfigurationException {
|
||||||
|
|
||||||
|
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id);
|
||||||
|
Message responseMessage = new Message();
|
||||||
|
Policy policy;
|
||||||
|
try {
|
||||||
|
PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService();
|
||||||
|
policy = policyManagerService.getEffectivePolicy(deviceIdentifier);
|
||||||
|
if (policy == null) {
|
||||||
|
responseMessage.setResponseCode(Response.Status.NO_CONTENT.toString());
|
||||||
|
responseMessage.setResponseMessage("No effective policy found");
|
||||||
|
return responseMessage;
|
||||||
|
} else {
|
||||||
|
responseMessage.setResponseCode(Response.Status.OK.toString());
|
||||||
|
responseMessage.setResponseMessage("Effective policy added to operation");
|
||||||
|
return responseMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String msg = "Error occurred while getting the policy.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new WindowsConfigurationException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,54 +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.syncml.util;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
|
||||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* implementation for PolicyManager
|
|
||||||
*/
|
|
||||||
public class PolicyManager {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(PolicyManager.class);
|
|
||||||
|
|
||||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws WindowsConfigurationException {
|
|
||||||
Policy policy;
|
|
||||||
PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService();
|
|
||||||
try {
|
|
||||||
policy = policyManagerService.getEffectivePolicy(deviceIdentifier);
|
|
||||||
if (policy != null) {
|
|
||||||
return policy;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Error occurred while getting policy.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new WindowsConfigurationException();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.mobileservices.windows.services.syncml.util;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for generate Device object from the received data.
|
|
||||||
*/
|
|
||||||
public class SyncmlUtils {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(SyncmlUtils.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns Device Management Object for certain tasks such as Device enrollment etc.
|
|
||||||
*
|
|
||||||
* @return DeviceManagementServiceObject
|
|
||||||
*/
|
|
||||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
|
|
||||||
return (DeviceManagementProviderService) context.getOSGiService(DeviceManagementProviderService.class,
|
|
||||||
null);
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue