forked from community/device-mgt-plugins
parent
54de97ec27
commit
36cbc96713
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
|
|
||||||
|
|
||||||
import javax.jws.WebService;
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Endpoint for Enforce Effective Policy.
|
|
||||||
*/
|
|
||||||
@WebService
|
|
||||||
@Produces({ "application/json", "application/xml"})
|
|
||||||
@Consumes({"application/json", "application/xml"})
|
|
||||||
public interface PolicyManagementService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the applicable effective policy for an enrolled windows device.
|
|
||||||
*
|
|
||||||
* @param deviceId Device Id
|
|
||||||
* @return Returns retrieved devices.
|
|
||||||
* @throws WindowsConfigurationException occurred while retrieving all the devices from DB.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("{deviceId}")
|
|
||||||
Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader,
|
|
||||||
@PathParam("deviceId") String deviceId) throws WindowsConfigurationException;
|
|
||||||
}
|
|
@ -1,157 +1,157 @@
|
|||||||
/*
|
///*
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
// * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
// *
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
// * WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
// * Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
// * in compliance with the License.
|
||||||
* you may obtain a copy of the License at
|
// * you may obtain a copy of the License at
|
||||||
*
|
// *
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
// *
|
||||||
* Unless required by applicable law or agreed to in writing,
|
// * Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
// * software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
// * KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
// * specific language governing permissions and limitations
|
||||||
* under the License.
|
// * under the License.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.impl;
|
//package org.wso2.carbon.device.mgt.mobile.windows.api.services.impl;
|
||||||
|
//
|
||||||
import org.apache.commons.logging.Log;
|
//import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
//import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
//import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
//import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
//import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
//import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
//import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
//import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
|
//import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
//import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.DeviceManagementService;
|
//import org.wso2.carbon.device.mgt.mobile.windows.api.services.DeviceManagementService;
|
||||||
|
//
|
||||||
import javax.jws.WebService;
|
//import javax.jws.WebService;
|
||||||
import javax.ws.rs.*;
|
//import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
//import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
//import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Windows Device Management REST-API implementation.
|
// * Windows Device Management REST-API implementation.
|
||||||
* All end points supports JSON, XMl with content negotiation.
|
// * All end points supports JSON, XMl with content negotiation.
|
||||||
*/
|
// */
|
||||||
@WebService
|
//@WebService
|
||||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
//@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
//@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
public class DeviceManagementServiceImpl implements DeviceManagementService {
|
//public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||||
|
//
|
||||||
|
//
|
||||||
private static Log log = LogFactory.getLog(
|
// private static Log log = LogFactory.getLog(
|
||||||
org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.DeviceManagementServiceImpl.class);
|
// org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.DeviceManagementServiceImpl.class);
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Get all devices.Returns list of Windows devices registered in MDM.
|
// * Get all devices.Returns list of Windows devices registered in MDM.
|
||||||
*
|
// *
|
||||||
* @return Returns retrieved devices.
|
// * @return Returns retrieved devices.
|
||||||
* @throws WindowsConfigurationException occurred while retrieving all the devices from DB.
|
// * @throws WindowsConfigurationException occurred while retrieving all the devices from DB.
|
||||||
*/
|
// */
|
||||||
@GET
|
// @GET
|
||||||
public List<Device> getAllDevices() throws WindowsConfigurationException {
|
// public List<Device> getAllDevices() throws WindowsConfigurationException {
|
||||||
String msg;
|
// String msg;
|
||||||
List<Device> devices;
|
// List<Device> devices;
|
||||||
try {
|
// try {
|
||||||
devices = WindowsAPIUtils.getDeviceManagementService().
|
// devices = WindowsAPIUtils.getDeviceManagementService().
|
||||||
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
// getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||||
} catch (DeviceManagementException e) {
|
// } catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while fetching the device list.";
|
// msg = "Error occurred while fetching the device list.";
|
||||||
log.error(msg, e);
|
// log.error(msg, e);
|
||||||
throw new WindowsConfigurationException(msg, e);
|
// throw new WindowsConfigurationException(msg, e);
|
||||||
}
|
// }
|
||||||
return devices;
|
// return devices;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Fetch Windows device details of a given device Id.
|
// * Fetch Windows device details of a given device Id.
|
||||||
*
|
// *
|
||||||
* @param deviceId Device Id
|
// * @param deviceId Device Id
|
||||||
* @return Returns retrieved device.
|
// * @return Returns retrieved device.
|
||||||
* @throws WindowsConfigurationException occurred while getting device from DB.
|
// * @throws WindowsConfigurationException occurred while getting device from DB.
|
||||||
*/
|
// */
|
||||||
@GET
|
// @GET
|
||||||
@Path("{id}")
|
// @Path("{id}")
|
||||||
public Device getDevice(@PathParam("id") String deviceId) throws WindowsConfigurationException {
|
// public Device getDevice(@PathParam("id") String deviceId) throws WindowsConfigurationException {
|
||||||
String msg;
|
// String msg;
|
||||||
Device device;
|
// Device device;
|
||||||
try {
|
// try {
|
||||||
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(deviceId);
|
// DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(deviceId);
|
||||||
device = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
// device = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
if (device == null) {
|
// if (device == null) {
|
||||||
Response.status(Response.Status.NOT_FOUND);
|
// Response.status(Response.Status.NOT_FOUND);
|
||||||
}
|
// }
|
||||||
} catch (DeviceManagementException e) {
|
// } catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while fetching the device information.";
|
// msg = "Error occurred while fetching the device information.";
|
||||||
log.error(msg, e);
|
// log.error(msg, e);
|
||||||
throw new WindowsConfigurationException(msg, e);
|
// throw new WindowsConfigurationException(msg, e);
|
||||||
}
|
// }
|
||||||
return device;
|
// return device;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Update Windows device details of given device id.
|
// * Update Windows device details of given device id.
|
||||||
*
|
// *
|
||||||
* @param deviceId Device Id.
|
// * @param deviceId Device Id.
|
||||||
* @param device Device details to be updated.
|
// * @param device Device details to be updated.
|
||||||
* @return Returns the message whether device update or not.
|
// * @return Returns the message whether device update or not.
|
||||||
* @throws WindowsConfigurationException occurred while updating the Device Info.
|
// * @throws WindowsConfigurationException occurred while updating the Device Info.
|
||||||
*/
|
// */
|
||||||
@PUT
|
// @PUT
|
||||||
@Path("{id}")
|
// @Path("{id}")
|
||||||
public Message updateDevice(@PathParam("id") String deviceId, Device device) throws WindowsConfigurationException {
|
// public Message updateDevice(@PathParam("id") String deviceId, Device device) throws WindowsConfigurationException {
|
||||||
String msg;
|
// String msg;
|
||||||
Message responseMessage = new Message();
|
// Message responseMessage = new Message();
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
// DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
// deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
// deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||||
boolean isUpdated;
|
// boolean isUpdated;
|
||||||
try {
|
// try {
|
||||||
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
// device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||||
isUpdated = WindowsAPIUtils.getDeviceManagementService().updateDeviceInfo(deviceIdentifier, device);
|
// isUpdated = WindowsAPIUtils.getDeviceManagementService().updateDeviceInfo(deviceIdentifier, device);
|
||||||
if (isUpdated) {
|
// if (isUpdated) {
|
||||||
Response.status(Response.Status.ACCEPTED);
|
// Response.status(Response.Status.ACCEPTED);
|
||||||
responseMessage.setResponseMessage("Device information has modified successfully.");
|
// responseMessage.setResponseMessage("Device information has modified successfully.");
|
||||||
} else {
|
// } else {
|
||||||
Response.status(Response.Status.NOT_MODIFIED);
|
// Response.status(Response.Status.NOT_MODIFIED);
|
||||||
responseMessage.setResponseMessage("Device not found for the update.");
|
// responseMessage.setResponseMessage("Device not found for the update.");
|
||||||
}
|
// }
|
||||||
} catch (DeviceManagementException e) {
|
// } catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while modifying the device information.";
|
// msg = "Error occurred while modifying the device information.";
|
||||||
log.error(msg, e);
|
// log.error(msg, e);
|
||||||
throw new WindowsConfigurationException(msg, e);
|
// throw new WindowsConfigurationException(msg, e);
|
||||||
}
|
// }
|
||||||
return responseMessage;
|
// return responseMessage;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Fetch the Licence agreement for specific windows platform.
|
// * Fetch the Licence agreement for specific windows platform.
|
||||||
*
|
// *
|
||||||
* @return Returns License agreement.
|
// * @return Returns License agreement.
|
||||||
* @throws WindowsConfigurationException occurred while getting licence for specific platform and Language.
|
// * @throws WindowsConfigurationException occurred while getting licence for specific platform and Language.
|
||||||
*/
|
// */
|
||||||
@GET
|
// @GET
|
||||||
@Path("license")
|
// @Path("license")
|
||||||
@Produces("application/json")
|
// @Produces("application/json")
|
||||||
public License getLicense() throws WindowsConfigurationException {
|
// public License getLicense() throws WindowsConfigurationException {
|
||||||
License license;
|
// License license;
|
||||||
try {
|
// try {
|
||||||
license =
|
// license =
|
||||||
WindowsAPIUtils.getDeviceManagementService().getLicense(
|
// WindowsAPIUtils.getDeviceManagementService().getLicense(
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS,
|
// DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS,
|
||||||
DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US);
|
// DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US);
|
||||||
} catch (DeviceManagementException e) {
|
// } catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the license configured for Windows device enrollment";
|
// String msg = "Error occurred while retrieving the license configured for Windows device enrollment";
|
||||||
log.error(msg, e);
|
// log.error(msg, e);
|
||||||
throw new WindowsConfigurationException(msg, e);
|
// throw new WindowsConfigurationException(msg, e);
|
||||||
}
|
// }
|
||||||
return license;
|
// return license;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.windows.api.services.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.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.windows.api.services.PolicyManagementService;
|
|
||||||
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.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
@WebService
|
|
||||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
|
||||||
public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|
||||||
private static Log log = LogFactory.getLog(
|
|
||||||
org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.PolicyManagementServiceImpl.class);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{deviceId}")
|
|
||||||
public Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader,
|
|
||||||
@PathParam("deviceId") String deviceId) throws WindowsConfigurationException {
|
|
||||||
|
|
||||||
DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(deviceId);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue