mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
merged with upstream
This commit is contained in:
commit
087be385c4
@ -80,3 +80,4 @@ public interface AndroidSenseControllerService {
|
|||||||
@QueryParam("from") long from, @QueryParam("to") long to);
|
@QueryParam("from") long from, @QueryParam("to") long to);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,18 +24,11 @@ import org.wso2.carbon.analytics.dataservice.commons.SORT;
|
|||||||
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector;
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorData;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorRecord;
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorRecord;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ function onRequest(context) {
|
|||||||
var deviceType = context.uriParams.deviceType;
|
var deviceType = context.uriParams.deviceType;
|
||||||
var deviceId = request.getParameter("id");
|
var deviceId = request.getParameter("id");
|
||||||
|
|
||||||
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
if (deviceType && deviceId) {
|
||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
var device = deviceModule.viewDevice(deviceType, deviceId);
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
|
||||||
|
|||||||
@ -50,14 +50,6 @@ public interface ArduinoControllerService {
|
|||||||
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||||
@FormParam("state") String state);
|
@FormParam("state") String state);
|
||||||
|
|
||||||
@Path("device/{deviceId}/temperature")
|
|
||||||
@GET
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Feature(code = "temperature", name = "Temperature", type = "monitor", description = "Request temperature reading " +
|
|
||||||
"from Arduino agent")
|
|
||||||
Response requestTemperature(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol);
|
|
||||||
|
|
||||||
@Path("device/sensor")
|
@Path("device/sensor")
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
|||||||
@ -29,12 +29,19 @@ import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
|
|||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -49,7 +56,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) {
|
@Path("device/register/{deviceId}/{ip}/{port}")
|
||||||
|
@POST
|
||||||
|
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
||||||
|
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
|
||||||
String result;
|
String result;
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: ");
|
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: ");
|
||||||
@ -64,7 +74,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response switchBulb(String deviceId, String protocol, String state) {
|
@Path("device/{deviceId}/bulb")
|
||||||
|
@POST
|
||||||
|
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||||
|
@FormParam("state") String state) {
|
||||||
|
|
||||||
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
||||||
String operation = "BULB:" + state.toUpperCase();
|
String operation = "BULB:" + state.toUpperCase();
|
||||||
@ -80,24 +93,13 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response requestTemperature(String deviceId, String protocol) {
|
@Path("device/sensor")
|
||||||
try {
|
@POST
|
||||||
org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord =
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
SensorDataManager.getInstance().getSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE);
|
|
||||||
return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecord).build();
|
|
||||||
} catch (DeviceControllerException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Response pushData(DeviceData dataMsg) {
|
public Response pushData(DeviceData dataMsg) {
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
String deviceId = dataMsg.deviceId;
|
String deviceId = dataMsg.deviceId;
|
||||||
float pinData = dataMsg.value;
|
float pinData = dataMsg.value;
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
|
|
||||||
String.valueOf(pinData),
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
||||||
log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" +
|
log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" +
|
||||||
deviceId + "] of owner [" + owner + "]");
|
deviceId + "] of owner [" + owner + "]");
|
||||||
@ -107,7 +109,9 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response readControls(String deviceId, String protocol) {
|
@Path("device/{deviceId}/controls")
|
||||||
|
@GET
|
||||||
|
public Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol) {
|
||||||
String result;
|
String result;
|
||||||
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
@ -135,13 +139,13 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response pushTemperatureData(final DeviceData dataMsg, HttpServletRequest request) {
|
@Path("device/temperature")
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) {
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
String deviceId = dataMsg.deviceId;
|
String deviceId = dataMsg.deviceId;
|
||||||
float temperature = dataMsg.value;
|
float temperature = dataMsg.value;
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
|
|
||||||
String.valueOf(temperature),
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
||||||
log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId +
|
log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId +
|
||||||
"] of owner [" + owner + "]");
|
"] of owner [" + owner + "]");
|
||||||
@ -151,7 +155,12 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response getArduinoTemperatureStats(String deviceId, long from, long to) {
|
@Path("device/stats/{deviceId}/sensors/temperature")
|
||||||
|
@GET
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
|
||||||
|
@QueryParam("to") long to) {
|
||||||
String fromDate = String.valueOf(from);
|
String fromDate = String.valueOf(from);
|
||||||
String toDate = String.valueOf(to);
|
String toDate = String.valueOf(to);
|
||||||
String query = "deviceId:" + deviceId + " AND deviceType:" +
|
String query = "deviceId:" + deviceId + " AND deviceType:" +
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import javax.ws.rs.QueryParam;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
|
@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
|
||||||
@DeviceType(value = "arduino")
|
@DeviceType(value = "arduino")
|
||||||
public interface ArduinoManagerService {
|
public interface ArduinoManagerService {
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
|
package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
|
||||||
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
|
||||||
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
@ -27,7 +26,6 @@ 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.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
||||||
@ -37,6 +35,16 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
|||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -45,13 +53,16 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
||||||
|
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response removeDevice(String deviceId) {
|
@Path("devices/{device_id}")
|
||||||
|
@DELETE
|
||||||
|
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
@ -68,7 +79,9 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response updateDevice(String deviceId, String name) {
|
@Path("devices/{device_id}")
|
||||||
|
@PUT
|
||||||
|
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
@ -90,7 +103,11 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response getDevice(String deviceId) {
|
@Path("devices/{device_id}")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getDevice(@PathParam("device_id") String deviceId) {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
@ -103,6 +120,10 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Path("devices")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getArduinoDevices() {
|
public Response getArduinoDevices() {
|
||||||
try {
|
try {
|
||||||
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
|
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
|
||||||
@ -122,7 +143,10 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response downloadSketch(String customDeviceName) {
|
@Path("devices/download")
|
||||||
|
@GET
|
||||||
|
@Produces("application/octet-stream")
|
||||||
|
public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) {
|
||||||
try {
|
try {
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName);
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
@ -144,7 +168,9 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response generateSketchLink(String deviceName) {
|
@Path("devices/generate_link")
|
||||||
|
@GET
|
||||||
|
public Response generateSketchLink(@QueryParam("deviceName") String deviceName) {
|
||||||
try {
|
try {
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
|
|||||||
@ -7,56 +7,40 @@
|
|||||||
<display-name>Arduino</display-name>
|
<display-name>Arduino</display-name>
|
||||||
<description>Arduino</description>
|
<description>Arduino</description>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isAdminService</param-name>
|
||||||
|
<param-value>false</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>doAuthentication</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isSharedWithAllTenants</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>providerTenantDomain</param-name>
|
||||||
|
<param-value>carbon.super</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<!--publish to apim-->
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-enabled</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-owner</param-name>
|
||||||
|
<param-value>admin</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<servlet-mapping>
|
</web-app>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>isAdminService</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>doAuthentication</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>isSharedWithAllTenants</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>providerTenantDomain</param-name>
|
|
||||||
<param-value>carbon.super</param-value>
|
|
||||||
</context-param>
|
|
||||||
<!--publish to apim-->
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-enabled</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-owner</param-name>
|
|
||||||
<param-value>admin</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-context-template</param-name>
|
|
||||||
<param-value>/arduino/{version}</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-application</param-name>
|
|
||||||
<param-value>arduino</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-isSecured</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</web-app>
|
|
||||||
@ -21,11 +21,11 @@ package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl;
|
|||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
||||||
import javax.websocket.server.PathParam;
|
|
||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"})
|
@API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"})
|
||||||
@ -54,7 +54,7 @@ public interface DigitalDisplayControllerService {
|
|||||||
@POST
|
@POST
|
||||||
@Feature(code = "terminate-display", name = "Terminate Display", type = "operation",
|
@Feature(code = "terminate-display", name = "Terminate Display", type = "operation",
|
||||||
description = "Terminate all running process in Digital Display")
|
description = "Terminate all running process in Digital Display")
|
||||||
Response terminateDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId);
|
Response terminateDisplay(@HeaderParam("sessionId") String sessionId, @PathParam("deviceId") String deviceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reboot running digital display
|
* Reboot running digital display
|
||||||
|
|||||||
@ -20,10 +20,8 @@ package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.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.apimgt.annotations.api.API;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.exception.DigitalDisplayException;
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.exception.DigitalDisplayException;
|
||||||
@ -32,13 +30,11 @@ import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDis
|
|||||||
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.websocket.server.PathParam;
|
|
||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
public class DigitalDisplayControllerServiceImpl implements DigitalDisplayControllerService {
|
public class DigitalDisplayControllerServiceImpl implements DigitalDisplayControllerService {
|
||||||
@ -46,50 +42,9 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
private static Log log = LogFactory.getLog(DigitalDisplayControllerServiceImpl.class);
|
private static Log log = LogFactory.getLog(DigitalDisplayControllerServiceImpl.class);
|
||||||
private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector;
|
private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector;
|
||||||
|
|
||||||
private boolean waitForServerStartup() {
|
@Path("device/{deviceId}/restart-browser")
|
||||||
while (!IoTServerStartupListener.isServerReady()) {
|
@POST
|
||||||
try {
|
public Response restartBrowser(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DigitalDisplayMQTTConnector getDigitalDisplayMQTTConnector() {
|
|
||||||
return DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDigitalDisplayMQTTConnector(final
|
|
||||||
DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) {
|
|
||||||
|
|
||||||
Runnable connector = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (waitForServerStartup()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector = digitalDisplayMQTTConnector;
|
|
||||||
//The delay is added for the server starts up.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
if (MqttConfig.getInstance().isEnabled()) {
|
|
||||||
synchronized (digitalDisplayMQTTConnector) {
|
|
||||||
digitalDisplayMQTTConnector.connect();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, not started.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Thread connectorThread = new Thread(connector);
|
|
||||||
connectorThread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response restartBrowser(String deviceId, String sessionId) {
|
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -100,7 +55,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response terminateDisplay(String deviceId, String sessionId) {
|
@Path("device/{deviceId}/terminate-display")
|
||||||
|
@POST
|
||||||
|
public Response terminateDisplay(@HeaderParam("sessionId") String sessionId,
|
||||||
|
@PathParam("deviceId") String deviceId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -109,10 +67,11 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
} catch (DigitalDisplayException e) {
|
} catch (DigitalDisplayException e) {
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response restartDisplay(String deviceId, String sessionId) {
|
@Path("device/{deviceId}/restart-display")
|
||||||
|
@POST
|
||||||
|
public Response restartDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -123,7 +82,11 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response editSequence(String deviceId, String name, String attribute, String newValue, String sessionId) {
|
@Path("device/{deviceId}/edit-sequence")
|
||||||
|
@POST
|
||||||
|
public Response editSequence(@PathParam("deviceId") String deviceId, @FormParam("name") String name,
|
||||||
|
@FormParam("attribute") String attribute, @FormParam("new-value") String newValue,
|
||||||
|
@HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
String params = name + "|" + attribute + "|" + newValue;
|
String params = name + "|" + attribute + "|" + newValue;
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params);
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params);
|
||||||
@ -135,7 +98,12 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response uploadContent(String deviceId, String remotePath, String screenName, String sessionId) {
|
|
||||||
|
@Path("device/{deviceId}/upload-content")
|
||||||
|
@POST
|
||||||
|
public Response uploadContent(@PathParam("deviceId") String deviceId, @FormParam("remote-path") String remotePath,
|
||||||
|
@FormParam("screen-name") String screenName,
|
||||||
|
@HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
String params = remotePath + "|" + screenName;
|
String params = remotePath + "|" + screenName;
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::",
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::",
|
||||||
@ -148,8 +116,12 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response addNewResource(String deviceId, String type, String time, String path, String name, String position,
|
@Path("device/{deviceId}/add-resource")
|
||||||
String sessionId) {
|
@POST
|
||||||
|
public Response addNewResource(@PathParam("deviceId") String deviceId, @FormParam("type") String type,
|
||||||
|
@FormParam("time") String time, @FormParam("path") String path,
|
||||||
|
@FormParam("name") String name, @FormParam("position") String position,
|
||||||
|
@HeaderParam("sessionId") String sessionId) {
|
||||||
String params;
|
String params;
|
||||||
try {
|
try {
|
||||||
if (position.isEmpty()) {
|
if (position.isEmpty()) {
|
||||||
@ -167,7 +139,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response removeResource(String deviceId, String name, String sessionId) {
|
@Path("device/{deviceId}/remove-resource")
|
||||||
|
@POST
|
||||||
|
public Response removeResource(@PathParam("deviceId") String deviceId, @FormParam("name") String name,
|
||||||
|
@HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name);
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -178,7 +153,9 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response restartServer(String deviceId, String sessionId) {
|
@Path("device/{deviceId}/restart-server")
|
||||||
|
@POST
|
||||||
|
public Response restartServer(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -189,7 +166,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response showScreenshot(String deviceId, String sessionId) {
|
|
||||||
|
@Path("device/{deviceId}/screenshot")
|
||||||
|
@POST
|
||||||
|
public Response showScreenshot(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -200,7 +180,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getDevicestatus(String deviceId, String sessionId) {
|
@Path("device/{deviceId}/get-device-status")
|
||||||
|
@POST
|
||||||
|
public Response getDevicestatus(@PathParam("deviceId") String deviceId,
|
||||||
|
@HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -211,7 +194,9 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getResources(String deviceId, String sessionId) {
|
@Path("device/{deviceId}/get-content-list")
|
||||||
|
@POST
|
||||||
|
public Response getResources(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
|
||||||
try {
|
try {
|
||||||
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", "");
|
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", "");
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
@ -245,4 +230,40 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean waitForServerStartup() {
|
||||||
|
while (!IoTServerStartupListener.isServerReady()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayMQTTConnector getDigitalDisplayMQTTConnector() {
|
||||||
|
return DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDigitalDisplayMQTTConnector(final
|
||||||
|
DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) {
|
||||||
|
|
||||||
|
Runnable connector = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (waitForServerStartup()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector = digitalDisplayMQTTConnector;
|
||||||
|
if (MqttConfig.getInstance().isEnabled()) {
|
||||||
|
digitalDisplayMQTTConnector.connect();
|
||||||
|
} else {
|
||||||
|
log.warn("MQTT disabled in 'devicemgt-config.xml'. " +
|
||||||
|
"Hence, DigitalDisplayMQTTConnector not started.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Thread connectorThread = new Thread(connector);
|
||||||
|
connectorThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
|||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
@ -33,6 +32,7 @@ import javax.ws.rs.QueryParam;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
@API(name = "digital_display_mgt", version = "1.0.0", context = "/digital_display_mgt", tags = {"digital_display"})
|
@API(name = "digital_display_mgt", version = "1.0.0", context = "/digital_display_mgt", tags = {"digital_display"})
|
||||||
@DeviceType(value = "digital_display")
|
@DeviceType(value = "digital_display")
|
||||||
public interface DigitalDisplayManagerService {
|
public interface DigitalDisplayManagerService {
|
||||||
|
|||||||
@ -39,6 +39,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
|||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -46,12 +55,97 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerService {
|
public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerService {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DigitalDisplayManagerServiceImpl.class);
|
private static Log log = LogFactory.getLog(DigitalDisplayManagerServiceImpl.class);
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@DELETE
|
||||||
|
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
try {
|
||||||
|
boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
|
||||||
|
deviceIdentifier);
|
||||||
|
if (removed) {
|
||||||
|
return Response.ok().build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@PUT
|
||||||
|
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
try {
|
||||||
|
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||||
|
device.setName(name);
|
||||||
|
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
|
||||||
|
if (updated) {
|
||||||
|
return Response.ok().build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
try {
|
||||||
|
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
return Response.ok().entity(device).build();
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Path("devices/download")
|
||||||
|
@GET
|
||||||
|
@Produces("application/octet-stream")
|
||||||
|
public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) {
|
||||||
|
try {
|
||||||
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName);
|
||||||
|
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
||||||
|
response.type("application/zip");
|
||||||
|
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
|
return response.build();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (JWTClientException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (DeviceControllerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (APIManagerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (UserStoreException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean register(String deviceId, String name) {
|
private boolean register(String deviceId, String name) {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
@ -77,81 +171,6 @@ public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response removeDevice(String deviceId) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
|
||||||
try {
|
|
||||||
boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
|
|
||||||
deviceIdentifier);
|
|
||||||
if (removed) {
|
|
||||||
return Response.ok().build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response updateDevice(String deviceId, String name) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
|
||||||
try {
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
|
||||||
device.setDeviceIdentifier(deviceId);
|
|
||||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
|
||||||
device.setName(name);
|
|
||||||
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
|
||||||
boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
|
|
||||||
if (updated) {
|
|
||||||
return Response.ok().build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response getDevice(String deviceId) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
|
||||||
try {
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
|
||||||
return Response.ok().entity(device).build();
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response downloadSketch(String deviceName) {
|
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
|
|
||||||
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
|
||||||
response.type("application/zip");
|
|
||||||
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
|
||||||
return response.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String deviceName)
|
private ZipArchive createDownloadFile(String owner, String deviceName)
|
||||||
throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException,
|
throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException,
|
||||||
UserStoreException {
|
UserStoreException {
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
|
|
||||||
|
|
||||||
<jaxrs:server id="DigitalDisplayController" address="/controller">
|
<jaxrs:server id="DigitalDisplay" address="/">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<bean id="DigitalDisplayManagerControllerService"
|
<bean id="DigitalDisplayManagerControllerService"
|
||||||
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.DigitalDisplayControllerServiceImpl">
|
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.DigitalDisplayControllerServiceImpl">
|
||||||
|
|||||||
@ -21,28 +21,16 @@
|
|||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
version="2.5">
|
version="2.5">
|
||||||
<display-name>Digital-Display-Agent-Webapp</display-name>
|
<display-name>Digital-Display-Agent-Webapp</display-name>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<description>JAX-WS/JAX-RS MDM Android Endpoint</description>
|
|
||||||
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<servlet-class>
|
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||||
org.apache.cxf.transport.servlet.CXFServlet
|
|
||||||
</servlet-class>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>isSharedWithAllTenants</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>providerTenantDomain</param-name>
|
|
||||||
<param-value>carbon.super</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>isAdminService</param-name>
|
<param-name>isAdminService</param-name>
|
||||||
<param-value>false</param-value>
|
<param-value>false</param-value>
|
||||||
@ -51,6 +39,14 @@
|
|||||||
<param-name>doAuthentication</param-name>
|
<param-name>doAuthentication</param-name>
|
||||||
<param-value>true</param-value>
|
<param-value>true</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isSharedWithAllTenants</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>providerTenantDomain</param-name>
|
||||||
|
<param-value>carbon.super</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<!--publish to apim-->
|
<!--publish to apim-->
|
||||||
<context-param>
|
<context-param>
|
||||||
@ -61,17 +57,5 @@
|
|||||||
<param-name>managed-api-owner</param-name>
|
<param-name>managed-api-owner</param-name>
|
||||||
<param-value>admin</param-value>
|
<param-value>admin</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-context-template</param-name>
|
|
||||||
<param-value>/digital_display/{version}</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-application</param-name>
|
|
||||||
<param-value>digital_display</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-isSecured</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
||||||
@ -38,7 +38,10 @@ public class DroneControllerServiceImpl implements DroneControllerService {
|
|||||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
||||||
private DroneController droneController = new DroneControllerImpl();
|
private DroneController droneController = new DroneControllerImpl();
|
||||||
|
|
||||||
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort) {
|
@Path("device/register/{deviceId}/{ip}/{port}")
|
||||||
|
@POST
|
||||||
|
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
||||||
|
@PathParam("port") String devicePort) {
|
||||||
String result;
|
String result;
|
||||||
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
||||||
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
||||||
@ -49,7 +52,10 @@ public class DroneControllerServiceImpl implements DroneControllerService {
|
|||||||
return Response.ok(Response.Status.OK.getStatusCode()).build();
|
return Response.ok(Response.Status.OK.getStatusCode()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response droneController(String deviceId, String action, String duration, String speed) {
|
@Path("device/{deviceId}/send_command")
|
||||||
|
@POST
|
||||||
|
public Response droneController(@PathParam("deviceId") String deviceId, @FormParam("action") String action,
|
||||||
|
@FormParam("duration") String duration, @FormParam("speed") String speed) {
|
||||||
try {
|
try {
|
||||||
DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed),
|
DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed),
|
||||||
Double.valueOf(duration));
|
Double.valueOf(duration));
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
@API(name = "drone_analyzer_mgt", version = "1.0.0", context = "/drone_analyzer_mgt", tags = {"drone_analyzer"})
|
@API(name = "drone_analyzer_mgt", version = "1.0.0", context = "/drone_analyzer_mgt", tags = {"drone_analyzer"})
|
||||||
@DeviceType(value = "drone_analyzer")
|
@DeviceType(value = "drone_analyzer")
|
||||||
public interface DroneManagerService {
|
public interface DroneManagerService {
|
||||||
|
|||||||
@ -39,6 +39,15 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
|||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -47,39 +56,16 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
public class DroneManagerServiceImpl implements DroneManagerService {
|
public class DroneManagerServiceImpl implements DroneManagerService {
|
||||||
|
|
||||||
private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerServiceImpl.class);
|
private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerServiceImpl.class);
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
|
||||||
private boolean register(String deviceId, String name) {
|
@Path("devices/{device_id}")
|
||||||
try {
|
@DELETE
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(DroneConstants.DEVICE_TYPE);
|
|
||||||
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Device device = new Device();
|
|
||||||
device.setDeviceIdentifier(deviceId);
|
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
||||||
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
|
||||||
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
|
||||||
device.setName(name);
|
|
||||||
device.setType(DroneConstants.DEVICE_TYPE);
|
|
||||||
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
|
|
||||||
device.setEnrolmentInfo(enrolmentInfo);
|
|
||||||
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
|
|
||||||
return added;
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response removeDevice(String deviceId) {
|
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
@ -95,7 +81,10 @@ public class DroneManagerServiceImpl implements DroneManagerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response updateDevice(String deviceId, String name) {
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@PUT
|
||||||
|
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
@ -116,7 +105,11 @@ public class DroneManagerServiceImpl implements DroneManagerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getDevice(String deviceId) {
|
@Path("devices/{device_id}")
|
||||||
|
@GET
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getDevice(@PathParam("device_id") String deviceId) {
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
@ -128,6 +121,10 @@ public class DroneManagerServiceImpl implements DroneManagerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Path("devices")
|
||||||
|
@GET
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
public Response getDroneDevices() {
|
public Response getDroneDevices() {
|
||||||
try {
|
try {
|
||||||
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
|
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
|
||||||
@ -146,7 +143,11 @@ public class DroneManagerServiceImpl implements DroneManagerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response downloadSketch(String deviceName, String sketchType) {
|
@Path("devices/{sketch_type}/download")
|
||||||
|
@GET
|
||||||
|
@Produces("application/octet-stream")
|
||||||
|
public Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String
|
||||||
|
sketchType) {
|
||||||
|
|
||||||
//create new device id
|
//create new device id
|
||||||
String deviceId = shortUUID();
|
String deviceId = shortUUID();
|
||||||
@ -172,10 +173,12 @@ public class DroneManagerServiceImpl implements DroneManagerService {
|
|||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
return rb.build();
|
return rb.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response generateSketchLink(String deviceName, String sketchType) {
|
@Path("devices/{sketch_type}/generate_link")
|
||||||
|
@GET
|
||||||
|
public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
||||||
|
@PathParam("sketch_type") String sketchType) {
|
||||||
try {
|
try {
|
||||||
ZipArchive zipFile = createDownloadFile(deviceName, sketchType);
|
ZipArchive zipFile = createDownloadFile(deviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
@ -195,6 +198,32 @@ public class DroneManagerServiceImpl implements DroneManagerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean register(String deviceId, String name) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(DroneConstants.DEVICE_TYPE);
|
||||||
|
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Device device = new Device();
|
||||||
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
||||||
|
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
device.setName(name);
|
||||||
|
device.setType(DroneConstants.DEVICE_TYPE);
|
||||||
|
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
|
||||||
|
return added;
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String deviceName, String sketchType)
|
private ZipArchive createDownloadFile(String deviceName, String sketchType)
|
||||||
throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException,
|
throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException,
|
||||||
UserStoreException {
|
UserStoreException {
|
||||||
|
|||||||
@ -6,44 +6,41 @@
|
|||||||
metadata-complete="true">
|
metadata-complete="true">
|
||||||
<display-name>WSO2 IoT Server</display-name>
|
<display-name>WSO2 IoT Server</display-name>
|
||||||
<description>WSO2 IoT Server</description>
|
<description>WSO2 IoT Server</description>
|
||||||
<servlet>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<context-param>
|
<servlet>
|
||||||
<param-name>isAdminService</param-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<param-value>false</param-value>
|
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||||
</context-param>
|
<load-on-startup>1</load-on-startup>
|
||||||
<context-param>
|
</servlet>
|
||||||
<param-name>doAuthentication</param-name>
|
<servlet-mapping>
|
||||||
<param-value>false</param-value>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
</context-param>
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isAdminService</param-name>
|
||||||
|
<param-value>false</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>doAuthentication</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isSharedWithAllTenants</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>providerTenantDomain</param-name>
|
||||||
|
<param-value>carbon.super</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<!--publish to apim-->
|
<!--publish to apim-->
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>managed-api-enabled</param-name>
|
<param-name>managed-api-enabled</param-name>
|
||||||
<param-value>true</param-value>
|
<param-value>true</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>managed-api-owner</param-name>
|
<param-name>managed-api-owner</param-name>
|
||||||
<param-value>admin</param-value>
|
<param-value>admin</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-context-template</param-name>
|
</web-app>
|
||||||
<param-value>/drone_analyzer/{version}</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-application</param-name>
|
|
||||||
<param-value>drone_analyzer</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-isSecured</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
</web-app>
|
|
||||||
@ -1,139 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>iot-base-plugin</artifactId>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.iot.api</artifactId>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
<name>WSO2 Carbon - IoT Server API - Common APIs</name>
|
|
||||||
<description>WSO2 Carbon - IoT Server API for common device functionality</description>
|
|
||||||
<url>http://wso2.org</url>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- CDM -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--CXF -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-transports-http</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--IOT -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.iot</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--JAX-RS -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-core-asl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-jaxrs</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax</groupId>
|
|
||||||
<artifactId>javaee-web-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.ws.rs</groupId>
|
|
||||||
<artifactId>jsr311-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.analytics</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.analytics.datasource.commons</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<encoding>UTF-8</encoding>
|
|
||||||
<source>${wso2.maven.compiler.source}</source>
|
|
||||||
<target>${wso2.maven.compiler.target}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<warName>common</warName>
|
|
||||||
<!--devices.war-->
|
|
||||||
<!--<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>-->
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
# Root logger option
|
|
||||||
log4j.rootLogger=INFO, stdout
|
|
||||||
|
|
||||||
# Direct log messages to stdout
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.stdout.Target=System.out
|
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss} %c{1}:%L - %m%n
|
|
||||||
@ -1,567 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.device.mgt.iot.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.*;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.util.APIUtil;
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class DevicesManagerService {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DevicesManagerService.class);
|
|
||||||
|
|
||||||
private Device[] getActiveDevices(List<Device> devices) {
|
|
||||||
List<Device> activeDevices = new ArrayList<>();
|
|
||||||
if (devices != null) {
|
|
||||||
for (Device device : devices) {
|
|
||||||
if (device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
|
|
||||||
activeDevices.add(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return activeDevices.toArray(new Device[activeDevices.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/users/{userName}")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDevicesOfUser(@PathParam("userName") String userName) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getDevicesOfUser(userName);
|
|
||||||
Device[] devicesArr = this.getActiveDevices(devices);
|
|
||||||
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/users/{userName}/count")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDeviceCount(@PathParam("userName") String userName) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getDevicesOfUser(userName);
|
|
||||||
if (devices != null) {
|
|
||||||
List<Device> activeDevices = new ArrayList<>();
|
|
||||||
for (Device device : devices) {
|
|
||||||
if (device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
|
|
||||||
activeDevices.add(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(activeDevices.size()).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDevice(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(
|
|
||||||
deviceIdentifier);
|
|
||||||
if (device != null) {
|
|
||||||
return Response.status(Response.Status.OK).entity(device).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/types")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDeviceTypes() {
|
|
||||||
try {
|
|
||||||
List<DeviceType> deviceTypes = APIUtil.getDeviceManagementService()
|
|
||||||
.getAvailableDeviceTypes();
|
|
||||||
DeviceType[] deviceTypesArr = deviceTypes.toArray(new DeviceType[deviceTypes.size()]);
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceTypesArr).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getAllDevices(@PathParam("deviceType") String deviceType) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getAllDevices(deviceType);
|
|
||||||
Device[] devicesArr = this.getActiveDevices(devices);
|
|
||||||
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getAllDevices() {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getAllDevices();
|
|
||||||
return Response.status(Response.Status.OK).entity(this.getActiveDevices(devices)).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/config")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getConfiguration(@PathParam("deviceType") String deviceType) {
|
|
||||||
try {
|
|
||||||
TenantConfiguration tenantConfiguration = APIUtil.getDeviceManagementService().getConfiguration(deviceType);
|
|
||||||
if (tenantConfiguration != null) {
|
|
||||||
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/search/role")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getAllDevicesOfRole(@QueryParam("roleName") String roleName) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getAllDevicesOfRole(roleName);
|
|
||||||
Device[] devicesArr = this.getActiveDevices(devices);
|
|
||||||
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/search/name")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDevicesByName(@PathParam("deviceName") String deviceName) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getDevicesByName(deviceName);
|
|
||||||
Device[] devicesArr = this.getActiveDevices(devices);
|
|
||||||
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/status")
|
|
||||||
@PUT
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response updateDeviceEnrolmentInfo(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier,
|
|
||||||
@FormParam("status") EnrolmentInfo.Status status) {
|
|
||||||
try {
|
|
||||||
DeviceManagementProviderService providerService = APIUtil.getDeviceManagementService();
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
Device device = providerService.getDevice(deviceIdentifier);
|
|
||||||
providerService.updateDeviceEnrolmentInfo(device, status);
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/search/status")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDevicesByStatus(@QueryParam("status") EnrolmentInfo.Status status) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
||||||
.getDevicesByStatus(status);
|
|
||||||
Device[] devicesArr = this.getActiveDevices(devices);
|
|
||||||
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/license")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getLicense(@PathParam("deviceType") String deviceType,
|
|
||||||
@QueryParam("languageCode") String languageCode) {
|
|
||||||
try {
|
|
||||||
License license = APIUtil.getDeviceManagementService().getLicense(
|
|
||||||
deviceType, languageCode);
|
|
||||||
if (license != null) {
|
|
||||||
return Response.status(Response.Status.OK).entity(license).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/license")
|
|
||||||
@POST
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response addLicense(@PathParam("deviceType") String deviceType,
|
|
||||||
@FormParam("provider") String provider, @FormParam("name") String name,
|
|
||||||
@FormParam("version") String version, @FormParam("language") String language,
|
|
||||||
@FormParam("validFrom") Date validFrom, @FormParam("validTo") Date validTo,
|
|
||||||
@FormParam("text") String text) {
|
|
||||||
try {
|
|
||||||
License license = new License();
|
|
||||||
license.setProvider(provider);
|
|
||||||
license.setName(name);
|
|
||||||
license.setVersion(version);
|
|
||||||
license.setLanguage(language);
|
|
||||||
license.setValidFrom(validFrom);
|
|
||||||
license.setValidTo(validTo);
|
|
||||||
license.setText(text);
|
|
||||||
APIUtil.getDeviceManagementService().addLicense(deviceType, license);
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/enrollment")
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response modifyEnrollment(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier,
|
|
||||||
@FormParam("name") String name,
|
|
||||||
@FormParam("description") String description,
|
|
||||||
@FormParam("groupId") int groupId,
|
|
||||||
@FormParam("enrollmentId") int enrollmentId,
|
|
||||||
@FormParam("dateOfEnrolment") long dateOfEnrolment,
|
|
||||||
@FormParam("dateOfLastUpdate") long dateOfLastUpdate,
|
|
||||||
@FormParam("ownership") EnrolmentInfo.OwnerShip ownership,
|
|
||||||
@FormParam("status") EnrolmentInfo.Status status,
|
|
||||||
@FormParam("owner") String owner) {
|
|
||||||
|
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
||||||
enrolmentInfo.setId(enrollmentId);
|
|
||||||
enrolmentInfo.setDateOfEnrolment(dateOfEnrolment);
|
|
||||||
enrolmentInfo.setDateOfLastUpdate(dateOfLastUpdate);
|
|
||||||
enrolmentInfo.setOwnership(ownership);
|
|
||||||
enrolmentInfo.setStatus(status);
|
|
||||||
enrolmentInfo.setOwner(owner);
|
|
||||||
|
|
||||||
Device device = new Device();
|
|
||||||
device.setType(deviceType);
|
|
||||||
device.setDeviceIdentifier(identifier);
|
|
||||||
device.setName(name);
|
|
||||||
device.setDescription(description);
|
|
||||||
device.setEnrolmentInfo(enrolmentInfo);
|
|
||||||
try {
|
|
||||||
boolean isModified = APIUtil.getDeviceManagementService()
|
|
||||||
.modifyEnrollment(device);
|
|
||||||
if (isModified) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/enrollment")
|
|
||||||
@POST
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response enrollDevice(@PathParam("deviceType") String deviceType, @PathParam("identifier") String identifier,
|
|
||||||
@FormParam("name") String name, @FormParam("description") String description,
|
|
||||||
@FormParam("groupId") int groupId,
|
|
||||||
@FormParam("enrollmentId") int enrollmentId,
|
|
||||||
@FormParam("dateOfEnrolment") long dateOfEnrolment,
|
|
||||||
@FormParam("dateOfLastUpdate") long dateOfLastUpdate,
|
|
||||||
@FormParam("ownership") EnrolmentInfo.OwnerShip ownership,
|
|
||||||
@FormParam("status") EnrolmentInfo.Status status,
|
|
||||||
@FormParam("owner") String owner) {
|
|
||||||
|
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
||||||
enrolmentInfo.setId(enrollmentId);
|
|
||||||
enrolmentInfo.setDateOfEnrolment(dateOfEnrolment);
|
|
||||||
enrolmentInfo.setDateOfLastUpdate(dateOfLastUpdate);
|
|
||||||
enrolmentInfo.setOwnership(ownership);
|
|
||||||
enrolmentInfo.setStatus(status);
|
|
||||||
enrolmentInfo.setOwner(owner);
|
|
||||||
|
|
||||||
Device device = new Device();
|
|
||||||
device.setType(deviceType);
|
|
||||||
device.setDeviceIdentifier(identifier);
|
|
||||||
device.setName(name);
|
|
||||||
device.setDescription(description);
|
|
||||||
device.setEnrolmentInfo(enrolmentInfo);
|
|
||||||
try {
|
|
||||||
boolean isModified = APIUtil.getDeviceManagementService().enrollDevice(
|
|
||||||
device);
|
|
||||||
if (isModified) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/tenant/configuration")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getTenantConfiguration() {
|
|
||||||
try {
|
|
||||||
TenantConfiguration tenantConfiguration = APIUtil.getDeviceManagementService().getConfiguration();
|
|
||||||
if (tenantConfiguration != null) {
|
|
||||||
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/tenant/configuration")
|
|
||||||
@POST
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response saveTenantConfiguration(@FormParam("tenantConfiguration") TenantConfiguration tenantConfiguration) {
|
|
||||||
try {
|
|
||||||
boolean isSaved = APIUtil.getDeviceManagementService()
|
|
||||||
.saveConfiguration(tenantConfiguration);
|
|
||||||
if (isSaved) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}")
|
|
||||||
@DELETE
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response disenrollDevice(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
try {
|
|
||||||
boolean isDisEnrolled = APIUtil.getDeviceManagementService()
|
|
||||||
.disenrollDevice(deviceIdentifier);
|
|
||||||
if (isDisEnrolled) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/enrollment")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response isEnrolled(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
try {
|
|
||||||
boolean isEnrolled = APIUtil.getDeviceManagementService().isEnrolled(
|
|
||||||
deviceIdentifier);
|
|
||||||
if (isEnrolled) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/status")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response isActive(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
try {
|
|
||||||
boolean isActive = APIUtil.getDeviceManagementService().isActive(
|
|
||||||
deviceIdentifier);
|
|
||||||
if (isActive) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/status")
|
|
||||||
@PUT
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response changeDeviceStatus(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier,
|
|
||||||
@FormParam("status") boolean status) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
try {
|
|
||||||
boolean isActivated = APIUtil.getDeviceManagementService().setActive(
|
|
||||||
deviceIdentifier, status);
|
|
||||||
if (isActivated) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/ownership")
|
|
||||||
@PUT
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response setOwnership(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier,
|
|
||||||
@FormParam("ownership") String ownership) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
try {
|
|
||||||
boolean isOwnershipChanged = APIUtil.getDeviceManagementService()
|
|
||||||
.setOwnership(deviceIdentifier, ownership);
|
|
||||||
if (isOwnershipChanged) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/enrollment/status")
|
|
||||||
@PUT
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response setStatus(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String identifier, @FormParam("owner") String owner,
|
|
||||||
@FormParam("status") EnrolmentInfo.Status status) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(identifier);
|
|
||||||
try {
|
|
||||||
boolean isStatusChanged = APIUtil.getDeviceManagementService()
|
|
||||||
.setStatus(deviceIdentifier, owner, status);
|
|
||||||
if (isStatusChanged) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/sensors/{sensorName}")
|
|
||||||
@POST
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response setSensorValue(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String deviceId,
|
|
||||||
@PathParam("sensorName") String sensorName,
|
|
||||||
@FormParam("sensorValue") String sensorValue) {
|
|
||||||
boolean isValueSet = SensorDataManager.getInstance().setSensorRecord(deviceId, sensorName,
|
|
||||||
sensorValue, Calendar.getInstance().getTimeInMillis());
|
|
||||||
if (isValueSet) {
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/devices/{deviceType}/{identifier}/sensors/{sensorName}")
|
|
||||||
@GET
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getSensorValue(@PathParam("deviceType") String deviceType,
|
|
||||||
@PathParam("identifier") String deviceId,
|
|
||||||
@PathParam("sensorName") String sensorName,
|
|
||||||
@QueryParam("defaultValue") String defaultValue) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, sensorName);
|
|
||||||
if (sensorRecord != null) {
|
|
||||||
return Response.status(Response.Status.OK).entity(sensorRecord).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceControllerException e) {
|
|
||||||
log.error("Error on reading sensor value: " + e.getMessage());
|
|
||||||
if (defaultValue != null) {
|
|
||||||
SensorRecord sensorRecord = new SensorRecord(defaultValue,
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
return Response.status(Response.Status.OK).entity(sensorRecord).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,356 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.device.mgt.iot.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.util.APIUtil;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
|
||||||
|
|
||||||
import javax.jws.WebService;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PolicyManagementService {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(PolicyManagementService.class);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/policies/inactive")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response addInactivePolicy(@FormParam("policy") Policy policy) {
|
|
||||||
return addPolicy(policy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/policies/active")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response addActivePolicy(@FormParam("policy") Policy policy) {
|
|
||||||
policy.setActive(true);
|
|
||||||
return addPolicy(policy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Response addPolicy(Policy policy) {
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
pap.addPolicy(policy);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy has been added successfully.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Policy Management related exception.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/policies")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getAllPolicies() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagerService.getPAP();
|
|
||||||
List<Policy> policies = policyAdministratorPoint.getPolicies();
|
|
||||||
Policy[] policyArr = policyAdministratorPoint.getPolicies().toArray(new Policy[policies.size()]);
|
|
||||||
return Response.status(Response.Status.OK).entity(policyArr).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Policy Management related exception";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/policies/{policyId}")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getPolicy(@PathParam("policyId") int policyId) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagerService.getPAP();
|
|
||||||
Policy policy = policyAdministratorPoint.getPolicy(policyId);
|
|
||||||
if (policy != null) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Sending policy for ID " + policyId);
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(policy).build();
|
|
||||||
} else {
|
|
||||||
log.error("Policy for ID " + policyId + " not found.");
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Policy Management related exception";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/policies/inactive/count")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getPolicyCount() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagerService.getPAP();
|
|
||||||
int policyCount = policyAdministratorPoint.getPolicyCount();
|
|
||||||
return Response.status(Response.Status.OK).entity(policyCount).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Policy Management related exception";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/{policyId}")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response updatePolicy(@FormParam("policy") Policy policy, @PathParam("policyId") int policyId) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
Policy previousPolicy = pap.getPolicy(policyId);
|
|
||||||
policy.setProfile(pap.getProfile(previousPolicy.getProfileId()));
|
|
||||||
policy.setPolicyName(previousPolicy.getPolicyName());
|
|
||||||
pap.updatePolicy(policy);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy with ID " + policyId + " has been updated successfully.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Policy Management related exception";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/priorities")
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response updatePolicyPriorities(@FormParam("policies") List<Policy> priorityUpdatedPolicies) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
boolean policiesUpdated = pap.updatePolicyPriorities(priorityUpdatedPolicies);
|
|
||||||
if (policiesUpdated) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy Priorities successfully updated.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy priorities did not update. Bad Request.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Exception in updating policy priorities.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/policies/{policyId}")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response deletePolicy(@PathParam("policyId") int policyId) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
Policy policy = pap.getPolicy(policyId);
|
|
||||||
boolean policyDeleted = pap.deletePolicy(policy);
|
|
||||||
if (policyDeleted) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy by id:" + policyId + " has been successfully deleted.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy by id:" + policyId + " does not exist.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Exception in deleting policy by id:" + policyId;
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/{policyId}/activate")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response activatePolicy(@PathParam("policyId") int policyId) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
pap.activatePolicy(policyId);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy by id:" + policyId + " has been successfully activated.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Exception in activating policy by id:" + policyId;
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/{policyId}/inactivate")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response inactivatePolicy(@PathParam("policyId") int policyId) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
pap.inactivatePolicy(policyId);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy by id:" + policyId + " has been successfully inactivated.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Exception in inactivating policy by id:" + policyId;
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/publish-changes")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response publishChanges() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagerService.getPAP();
|
|
||||||
pap.publishChanges();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Changes have been successfully updated.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Exception in applying changes.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/monitor-task/start")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response startTaskService(@FormParam("milliseconds") int monitoringFrequency) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
TaskScheduleService taskScheduleService = policyManagerService.getTaskScheduleService();
|
|
||||||
taskScheduleService.startTask(monitoringFrequency);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy monitoring service started successfully.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
String error = "Policy Management related exception.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/monitor-task/update")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response updateTaskService(@FormParam("milliseconds") int monitoringFrequency) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();;
|
|
||||||
TaskScheduleService taskScheduleService = policyManagerService.getTaskScheduleService();
|
|
||||||
taskScheduleService.updateTask(monitoringFrequency);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy monitoring service updated successfully.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
String error = "Policy Management related exception.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/policies/monitor-task/stop")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response stopTaskService() {
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
TaskScheduleService taskScheduleService = policyManagerService.getTaskScheduleService();
|
|
||||||
taskScheduleService.stopTask();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Policy monitoring service stopped successfully.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
String error = "Policy Management related exception.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/policies/compliance/{deviceType}/{deviceId}")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getComplianceDataOfDevice(@PathParam("deviceId") String deviceId,
|
|
||||||
@PathParam("deviceType") String deviceType) {
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagerService = APIUtil.getPolicyManagerService();
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
ComplianceData complianceData = policyManagerService.getDeviceCompliance(deviceIdentifier);
|
|
||||||
return Response.status(Response.Status.OK).entity(complianceData).build();
|
|
||||||
} catch (PolicyComplianceException e) {
|
|
||||||
String error = "Error occurred while getting the compliance data.";
|
|
||||||
log.error(error, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.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;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides utility functions used by REST-API.
|
|
||||||
*/
|
|
||||||
public class APIUtil {
|
|
||||||
private static Log log = LogFactory.getLog(APIUtil.class);
|
|
||||||
|
|
||||||
public static GroupManagementProviderService getGroupManagementProviderService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
GroupManagementProviderService groupManagementProviderService =
|
|
||||||
(GroupManagementProviderService) ctx.getOSGiService(GroupManagementProviderService.class, null);
|
|
||||||
if (groupManagementProviderService == null) {
|
|
||||||
String msg = "Group Management service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return groupManagementProviderService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService =
|
|
||||||
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
|
||||||
if (deviceManagementProviderService == null) {
|
|
||||||
String msg = "Device Management service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return deviceManagementProviderService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PolicyManagerService getPolicyManagerService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
PolicyManagerService policyManagerService =
|
|
||||||
(PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null);
|
|
||||||
if (policyManagerService == null) {
|
|
||||||
String msg = "Policy management service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return policyManagerService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,108 +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.iot.util;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class ResponsePayload {
|
|
||||||
|
|
||||||
private int statusCode;
|
|
||||||
private String messageFromServer;
|
|
||||||
private Object responseContent;
|
|
||||||
|
|
||||||
public static ResponsePayloadBuilder statusCode(int statusCode) {
|
|
||||||
ResponsePayload message = new ResponsePayload();
|
|
||||||
return message.getBuilder().statusCode(statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResponsePayloadBuilder messageFromServer(
|
|
||||||
String messageFromServer) {
|
|
||||||
ResponsePayload message = new ResponsePayload();
|
|
||||||
return message.getBuilder().messageFromServer(messageFromServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResponsePayloadBuilder responseContent(String responseContent) {
|
|
||||||
ResponsePayload message = new ResponsePayload();
|
|
||||||
return message.getBuilder().responseContent(responseContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public int getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusCode(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public String getMessageFromServer() {
|
|
||||||
return messageFromServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageFromServer(String messageFromServer) {
|
|
||||||
this.messageFromServer = messageFromServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public Object getResponseContent() {
|
|
||||||
return responseContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseContent(Object responseContent) {
|
|
||||||
this.responseContent = responseContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResponsePayloadBuilder getBuilder() {
|
|
||||||
return new ResponsePayloadBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ResponsePayloadBuilder {
|
|
||||||
|
|
||||||
private int statusCode;
|
|
||||||
private String messageFromServer;
|
|
||||||
private Object responseContent;
|
|
||||||
|
|
||||||
public ResponsePayloadBuilder statusCode(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
|
||||||
this.messageFromServer = messageFromServer;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponsePayloadBuilder responseContent(String responseContent) {
|
|
||||||
this.responseContent = responseContent;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponsePayload build() {
|
|
||||||
ResponsePayload payload = new ResponsePayload();
|
|
||||||
payload.setStatusCode(statusCode);
|
|
||||||
payload.setMessageFromServer(messageFromServer);
|
|
||||||
payload.setResponseContent(responseContent);
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,113 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- This file contains the list of permissions that are associated with URL end points
|
|
||||||
of the web app. Each permission should contain the name, permission path, API path
|
|
||||||
(URL) , HTTP method and authorization scope (OAuth2).
|
|
||||||
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
|
||||||
For ex:
|
|
||||||
Actual API endpoint: mdm-android-agent/1.0.0/operation/{device-id}
|
|
||||||
URL to be represented here: /operation/*
|
|
||||||
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
|
||||||
it will result 403 error at the runtime.
|
|
||||||
-->
|
|
||||||
<PermissionConfiguration>
|
|
||||||
<APIVersion></APIVersion>
|
|
||||||
<!-- Operations management related permissions for admin -->
|
|
||||||
<Permission>
|
|
||||||
<name>Get Device of user</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/user/{username}/all</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get ungrouped devices of user</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/user/{username}/ungrouped</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get Device of user</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device_manager/device/user/{username}/ungrouped</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get count of all the devices</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/user/{username}/all/count</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get specific device</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/type/{type}/identifier/{identifier}</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get the device type</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/type/all</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get all devices</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/all</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Get the device by name</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/name/{name}/all</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Update device enrollment info</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/type/{type}/identifier/{identifier}/status</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Update device enrollment info</name>
|
|
||||||
<path>/login</path>
|
|
||||||
<url>/device_manager/device/type/{type}/identifier/{identifier}/status</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope></scope>
|
|
||||||
</Permission>
|
|
||||||
|
|
||||||
</PermissionConfiguration>
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ Copyright 2005-2013 WSO2, Inc. (http://wso2.com)
|
|
||||||
~
|
|
||||||
~ Licensed 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
|
||||||
-->
|
|
||||||
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
|
||||||
|
|
||||||
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
|
||||||
<ParentFirst>false</ParentFirst>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
|
||||||
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
|
||||||
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
|
||||||
-->
|
|
||||||
<Environments>CXF,Carbon</Environments>
|
|
||||||
</Classloading>
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
|
||||||
xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xsi:schemaLocation="
|
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
|
||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
|
||||||
|
|
||||||
<jaxrs:server id="DevicesManager" address="/device_manager">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<bean id="DevicesManagerService"
|
|
||||||
class="org.wso2.carbon.device.mgt.iot.api.DevicesManagerService"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
|
|
||||||
<jaxrs:server id="PolicyManager" address="/policy_manager">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<bean id="PolicyManagerService"
|
|
||||||
class="org.wso2.carbon.device.mgt.iot.api.PolicyManagementService"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<web-app version="2.5"
|
|
||||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
|
||||||
metadata-complete="true">
|
|
||||||
<display-name>WSO2 IoT Server</display-name>
|
|
||||||
<description>WSO2 IoT Server</description>
|
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
<context-param>
|
|
||||||
<param-name>isAdminService</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>doAuthentication</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
</web-app>
|
|
||||||
@ -20,12 +20,6 @@ function onRequest(context) {
|
|||||||
var log = new Log("operation.js");
|
var log = new Log("operation.js");
|
||||||
var operationModule = require("/app/modules/operation.js").operationModule;
|
var operationModule = require("/app/modules/operation.js").operationModule;
|
||||||
var device = context.unit.params.device;
|
var device = context.unit.params.device;
|
||||||
var controlOperations;
|
var controlOperations = operationModule.getControlOperations(device.type);
|
||||||
try {
|
|
||||||
controlOperations = operationModule.getControlOperations(device.type);
|
|
||||||
}catch(e){
|
|
||||||
log.error("Control operation loading failed.");
|
|
||||||
controlOperations = null;
|
|
||||||
}
|
|
||||||
return {"control_operations": controlOperations, "device": device};
|
return {"control_operations": controlOperations, "device": device};
|
||||||
}
|
}
|
||||||
@ -1,21 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2014, 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.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>org.wso2.carbon.device.mgt.iot</module>
|
<module>org.wso2.carbon.device.mgt.iot</module>
|
||||||
<module>org.wso2.carbon.device.mgt.iot.api</module>
|
|
||||||
<module>org.wso2.carbon.device.mgt.iot.ui</module>
|
<module>org.wso2.carbon.device.mgt.iot.ui</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|||||||
@ -51,14 +51,6 @@ public interface RaspberryPiControllerService {
|
|||||||
description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
|
description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
|
||||||
Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state);
|
Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state);
|
||||||
|
|
||||||
@Path("device/{deviceId}/readtemperature")
|
|
||||||
@GET
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Feature(code = "readtemperature", name = "Temperature", type = "monitor",
|
|
||||||
description = "Request temperature reading from Raspberry Pi agent")
|
|
||||||
Response requestTemperature(@PathParam("deviceId") String deviceId);
|
|
||||||
|
|
||||||
@Path("device/push_temperature")
|
@Path("device/push_temperature")
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ -71,7 +63,7 @@ public interface RaspberryPiControllerService {
|
|||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("username") String user,
|
Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("username") String user,
|
||||||
@QueryParam("from") long from, @QueryParam("to") long to);
|
@QueryParam("from") long from, @QueryParam("to") long to);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,18 +25,25 @@ import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
|||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -49,49 +56,10 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
||||||
private RaspberryPiMQTTConnector raspberryPiMQTTConnector;
|
private RaspberryPiMQTTConnector raspberryPiMQTTConnector;
|
||||||
|
|
||||||
private boolean waitForServerStartup() {
|
@Path("device/register/{deviceId}/{ip}/{port}")
|
||||||
while (!IoTServerStartupListener.isServerReady()) {
|
@POST
|
||||||
try {
|
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
||||||
Thread.sleep(1000);
|
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RaspberryPiMQTTConnector getRaspberryPiMQTTConnector() {
|
|
||||||
return raspberryPiMQTTConnector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRaspberryPiMQTTConnector(
|
|
||||||
final RaspberryPiMQTTConnector raspberryPiMQTTConnector) {
|
|
||||||
Runnable connector = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (waitForServerStartup()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
RaspberryPiControllerServiceImpl.this.raspberryPiMQTTConnector = raspberryPiMQTTConnector;
|
|
||||||
//The delay is added for the server starts up.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
if (MqttConfig.getInstance().isEnabled()) {
|
|
||||||
synchronized (raspberryPiMQTTConnector) {
|
|
||||||
raspberryPiMQTTConnector.connect();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, not started.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Thread connectorThread = new Thread(connector);
|
|
||||||
connectorThread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) {
|
|
||||||
String result;
|
String result;
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId);
|
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId);
|
||||||
@ -105,7 +73,9 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
return Response.ok().entity(result).build();
|
return Response.ok().entity(result).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response switchBulb(String deviceId, String state) {
|
@Path("device/{deviceId}/bulb")
|
||||||
|
@POST
|
||||||
|
public Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state) {
|
||||||
String switchToState = state.toUpperCase();
|
String switchToState = state.toUpperCase();
|
||||||
if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals(
|
if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals(
|
||||||
RaspberrypiConstants.STATE_OFF)) {
|
RaspberrypiConstants.STATE_OFF)) {
|
||||||
@ -126,32 +96,10 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response requestTemperature(@PathParam("deviceId") String deviceId) {
|
@Path("device/push_temperature")
|
||||||
org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = null;
|
@POST
|
||||||
if (log.isDebugEnabled()) {
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
log.debug("Sending request to read raspberrypi-temperature of device [" + deviceId + "] via ");
|
public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) {
|
||||||
}
|
|
||||||
try {
|
|
||||||
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
||||||
if (deviceHTTPEndpoint == null) {
|
|
||||||
return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
String temperatureValue = RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
|
|
||||||
RaspberrypiConstants
|
|
||||||
.TEMPERATURE_CONTEXT,
|
|
||||||
false);
|
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE,
|
|
||||||
temperatureValue, Calendar.getInstance()
|
|
||||||
.getTimeInMillis());
|
|
||||||
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
|
|
||||||
RaspberrypiConstants.SENSOR_TEMPERATURE);
|
|
||||||
} catch (DeviceManagementException | DeviceControllerException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
return Response.ok().entity(sensorRecord).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response pushTemperatureData(final DeviceData dataMsg, HttpServletRequest request) {
|
|
||||||
String owner = dataMsg.owner;
|
String owner = dataMsg.owner;
|
||||||
String deviceId = dataMsg.deviceId;
|
String deviceId = dataMsg.deviceId;
|
||||||
String deviceIp = dataMsg.reply;
|
String deviceIp = dataMsg.reply;
|
||||||
@ -169,9 +117,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Received Pin Data Value: " + temperature + " degrees C");
|
log.debug("Received Pin Data Value: " + temperature + " degrees C");
|
||||||
}
|
}
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE,
|
|
||||||
String.valueOf(temperature),
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
||||||
log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" +
|
log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" +
|
||||||
deviceId + "] of owner [" + owner + "]");
|
deviceId + "] of owner [" + owner + "]");
|
||||||
@ -180,7 +125,13 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getArduinoTemperatureStats(String deviceId, String user, long from, long to) {
|
@Path("device/stats/{deviceId}/sensors/temperature")
|
||||||
|
@GET
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("username") String user,
|
||||||
|
@QueryParam("from") long from, @QueryParam("to") long to) {
|
||||||
String fromDate = String.valueOf(from);
|
String fromDate = String.valueOf(from);
|
||||||
String toDate = String.valueOf(to);
|
String toDate = String.valueOf(to);
|
||||||
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
|
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
|
||||||
@ -199,4 +150,38 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean waitForServerStartup() {
|
||||||
|
while (!IoTServerStartupListener.isServerReady()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RaspberryPiMQTTConnector getRaspberryPiMQTTConnector() {
|
||||||
|
return raspberryPiMQTTConnector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRaspberryPiMQTTConnector(
|
||||||
|
final RaspberryPiMQTTConnector raspberryPiMQTTConnector) {
|
||||||
|
Runnable connector = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (waitForServerStartup()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RaspberryPiControllerServiceImpl.this.raspberryPiMQTTConnector = raspberryPiMQTTConnector;
|
||||||
|
if (MqttConfig.getInstance().isEnabled()) {
|
||||||
|
raspberryPiMQTTConnector.connect();
|
||||||
|
} else {
|
||||||
|
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, RaspberryPiMQTTConnector not started.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Thread connectorThread = new Thread(connector);
|
||||||
|
connectorThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import javax.ws.rs.QueryParam;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
@API(name = "raspberrypi_mgt", version = "1.0.0", context = "/raspberrypi_mgt", tags = {"raspberrypi"})
|
@API(name = "raspberrypi_mgt", version = "1.0.0", context = "/raspberrypi_mgt", tags = {"raspberrypi"})
|
||||||
@DeviceType(value = "raspberrypi")
|
@DeviceType(value = "raspberrypi")
|
||||||
public interface RaspberryPiManagerService {
|
public interface RaspberryPiManagerService {
|
||||||
@ -43,7 +44,7 @@ public interface RaspberryPiManagerService {
|
|||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@PUT
|
@PUT
|
||||||
Response updateDevice(@PathParam("device_id") String deviceId,
|
Response updateDevice(@PathParam("device_id") String deviceId,
|
||||||
@QueryParam("name") String name);
|
@QueryParam("name") String name);
|
||||||
|
|
||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@GET
|
@GET
|
||||||
@ -57,16 +58,15 @@ public interface RaspberryPiManagerService {
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
Response getRaspberrypiDevices();
|
Response getRaspberrypiDevices();
|
||||||
|
|
||||||
|
|
||||||
@Path("devices/{sketch_type}/download")
|
@Path("devices/{sketch_type}/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String
|
Response downloadSketch(@QueryParam("deviceName") String deviceName,
|
||||||
sketchType);
|
@PathParam("sketch_type") String sketchType);
|
||||||
|
|
||||||
@Path("devices/{sketch_type}/generate_link")
|
@Path("devices/{sketch_type}/generate_link")
|
||||||
@GET
|
@GET
|
||||||
Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
||||||
@PathParam("sketch_type") String sketchType);
|
@PathParam("sketch_type") String sketchType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
|||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -51,13 +60,147 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService {
|
public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(RaspberryPiManagerServiceImpl.class);
|
private static Log log = LogFactory.getLog(RaspberryPiManagerServiceImpl.class);
|
||||||
|
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@DELETE
|
||||||
|
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
|
boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
|
||||||
|
deviceIdentifier);
|
||||||
|
if (removed) {
|
||||||
|
return Response.ok().build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@PUT
|
||||||
|
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
|
try {
|
||||||
|
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||||
|
device.setName(name);
|
||||||
|
device.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
|
boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
|
||||||
|
if (updated) {
|
||||||
|
return Response.ok().build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e.getErrorMessage());
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
|
try {
|
||||||
|
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
return Response.ok().entity(device).build();
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getRaspberrypiDevices() {
|
||||||
|
try {
|
||||||
|
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
|
||||||
|
APIUtil.getAuthenticatedUser());
|
||||||
|
ArrayList<Device> usersRaspberrypiDevices = new ArrayList<>();
|
||||||
|
for (Device device : userDevices) {
|
||||||
|
if (device.getType().equals(RaspberrypiConstants.DEVICE_TYPE) &&
|
||||||
|
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
|
||||||
|
usersRaspberrypiDevices.add(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Device[] devices = usersRaspberrypiDevices.toArray(new Device[]{});
|
||||||
|
return Response.ok().entity(devices).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Path("devices/{sketch_type}/download")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response downloadSketch(@QueryParam("deviceName") String deviceName,
|
||||||
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
try {
|
||||||
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
||||||
|
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
||||||
|
response.type("application/zip");
|
||||||
|
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
|
return response.build();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (JWTClientException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (DeviceControllerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (APIManagerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (UserStoreException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/{sketch_type}/generate_link")
|
||||||
|
@GET
|
||||||
|
public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
||||||
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
try {
|
||||||
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
||||||
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
|
return rb.build();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (JWTClientException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (DeviceControllerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (APIManagerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (UserStoreException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean register(String deviceId, String name) {
|
private boolean register(String deviceId, String name) {
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
@ -83,122 +226,6 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response removeDevice(String deviceId) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
|
||||||
boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
|
|
||||||
deviceIdentifier);
|
|
||||||
if (removed) {
|
|
||||||
return Response.ok().build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response updateDevice(String deviceId, String name) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
|
||||||
try {
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
|
||||||
device.setDeviceIdentifier(deviceId);
|
|
||||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
|
||||||
device.setName(name);
|
|
||||||
device.setType(RaspberrypiConstants.DEVICE_TYPE);
|
|
||||||
boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
|
|
||||||
if (updated) {
|
|
||||||
return Response.ok().build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
log.error(e.getErrorMessage());
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response getDevice(String deviceId) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
|
||||||
try {
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
|
||||||
return Response.ok().entity(device).build();
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response getRaspberrypiDevices() {
|
|
||||||
try {
|
|
||||||
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
|
|
||||||
APIUtil.getAuthenticatedUser());
|
|
||||||
ArrayList<Device> usersRaspberrypiDevices = new ArrayList<>();
|
|
||||||
for (Device device : userDevices) {
|
|
||||||
if (device.getType().equals(RaspberrypiConstants.DEVICE_TYPE) &&
|
|
||||||
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
|
|
||||||
usersRaspberrypiDevices.add(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Device[] devices = usersRaspberrypiDevices.toArray(new Device[]{});
|
|
||||||
return Response.ok().entity(devices).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response downloadSketch(String deviceName, String sketchType) {
|
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
|
||||||
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
|
||||||
response.type("application/zip");
|
|
||||||
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
|
||||||
return response.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response generateSketchLink(String deviceName, String sketchType) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
|
||||||
return rb.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
|
private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
|
||||||
throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException,
|
throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException,
|
||||||
UserStoreException {
|
UserStoreException {
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|||||||
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
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;
|
||||||
@ -35,7 +34,6 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
|||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
|
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||||
@ -160,8 +158,7 @@ public class RaspberryPiMQTTConnector extends MQTTTransportHandler {
|
|||||||
|
|
||||||
} else if (receivedMessage.contains("TEMPERATURE")) {
|
} else if (receivedMessage.contains("TEMPERATURE")) {
|
||||||
String temperatureValue = receivedMessage.split(":")[1];
|
String temperatureValue = receivedMessage.split(":")[1];
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE,
|
|
||||||
temperatureValue, Calendar.getInstance().getTimeInMillis());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,48 +7,40 @@
|
|||||||
<display-name>RaspberryPi</display-name>
|
<display-name>RaspberryPi</display-name>
|
||||||
<description>RaspberryPi</description>
|
<description>RaspberryPi</description>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isAdminService</param-name>
|
||||||
|
<param-value>false</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>doAuthentication</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isSharedWithAllTenants</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>providerTenantDomain</param-name>
|
||||||
|
<param-value>carbon.super</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<!--publish to apim-->
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-enabled</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-owner</param-name>
|
||||||
|
<param-value>admin</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<servlet-mapping>
|
</web-app>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>isAdminService</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>doAuthentication</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<!--publish to apim-->
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-enabled</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-owner</param-name>
|
|
||||||
<param-value>admin</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-context-template</param-name>
|
|
||||||
<param-value>/raspberrypi/{version}</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-application</param-name>
|
|
||||||
<param-value>raspberrypi</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-isSecured</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
|
|
||||||
</web-app>
|
|
||||||
@ -56,7 +56,7 @@ public interface VirtualFireAlarmControllerService {
|
|||||||
* @return a custom message indicating whether the DeviceID to IP mapping was successful.
|
* @return a custom message indicating whether the DeviceID to IP mapping was successful.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("register/{deviceId}/{ip}/{port}")
|
@Path("device/register/{deviceId}/{ip}/{port}")
|
||||||
Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
||||||
@PathParam("port") String devicePort, @Context HttpServletRequest request);
|
@PathParam("port") String devicePort, @Context HttpServletRequest request);
|
||||||
|
|
||||||
@ -72,31 +72,12 @@ public interface VirtualFireAlarmControllerService {
|
|||||||
* (Case-Insensitive String)
|
* (Case-Insensitive String)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("{deviceId}/buzz")
|
@Path("device/{deviceId}/buzz")
|
||||||
@Feature(code = "buzz", name = "Buzzer On / Off", type = "operation",
|
@Feature(code = "buzz", name = "Buzzer On / Off", type = "operation",
|
||||||
description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
|
description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
|
||||||
Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||||
@FormParam("state") String state);
|
@FormParam("state") String state);
|
||||||
|
|
||||||
/**
|
|
||||||
* This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command
|
|
||||||
* to the VirtualFirealarm device to 'tell what's its current temperature reading'. The method also takes in the
|
|
||||||
* protocol to be used to connect-to and send the command to the device.
|
|
||||||
*
|
|
||||||
* @param deviceId the ID of the VirtualFirealarm device on which the temperature reading is be read-from.
|
|
||||||
* @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device.
|
|
||||||
* @return an instance of the 'SensorRecord' object that holds the last updated temperature of the VirtualFirealarm
|
|
||||||
* whose temperature reading was requested.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("{deviceId}/temperature")
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Feature(code = "temperature", name = "Temperature", type = "monitor",
|
|
||||||
description = "Request Temperature reading from Virtual Fire Alarm")
|
|
||||||
Response requestTemperature(@PathParam("deviceId") String deviceId,
|
|
||||||
@QueryParam("protocol") String protocol);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an API called/used by the VirtualFirealarm device to publish its temperature to the IoT-Server. The
|
* This is an API called/used by the VirtualFirealarm device to publish its temperature to the IoT-Server. The
|
||||||
* received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager'
|
* received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager'
|
||||||
@ -105,7 +86,7 @@ public interface VirtualFireAlarmControllerService {
|
|||||||
* @param dataMsg the temperature data received from the device in JSON format complying to type 'DeviceData'.
|
* @param dataMsg the temperature data received from the device in JSON format complying to type 'DeviceData'.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("temperature")
|
@Path("device/temperature")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
Response pushTemperatureData(final DeviceData dataMsg);
|
Response pushTemperatureData(final DeviceData dataMsg);
|
||||||
|
|
||||||
@ -123,7 +104,7 @@ public interface VirtualFireAlarmControllerService {
|
|||||||
* @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation.
|
* @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("scep")
|
@Path("device/scep")
|
||||||
Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message);
|
Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message);
|
||||||
|
|
||||||
|
|
||||||
@ -140,13 +121,13 @@ public interface VirtualFireAlarmControllerService {
|
|||||||
* @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server.
|
* @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("scep")
|
@Path("device/scep")
|
||||||
Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream);
|
Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve Sensor data for the device type
|
* Retrieve Sensor data for the device type
|
||||||
*/
|
*/
|
||||||
@Path("stats/{deviceId}/sensors/{sensorName}")
|
@Path("device/stats/{deviceId}/sensors/{sensorName}")
|
||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
|
|||||||
@ -29,8 +29,6 @@ import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData;
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData;
|
||||||
@ -46,11 +44,19 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep.SC
|
|||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
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.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -77,6 +83,208 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|||||||
// holds a mapping of the IP addresses to Device-IDs for HTTP communication
|
// holds a mapping of the IP addresses to Device-IDs for HTTP communication
|
||||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("device/register/{deviceId}/{ip}/{port}")
|
||||||
|
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
||||||
|
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
|
||||||
|
String result;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId);
|
||||||
|
}
|
||||||
|
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
||||||
|
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
||||||
|
result = "Device-IP Registered";
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(result);
|
||||||
|
}
|
||||||
|
return Response.ok().entity(result).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("device/{deviceId}/buzz")
|
||||||
|
public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||||
|
@FormParam("state") String state) {
|
||||||
|
String switchToState = state.toUpperCase();
|
||||||
|
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
|
||||||
|
VirtualFireAlarmConstants.STATE_OFF)) {
|
||||||
|
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
String protocolString = protocol.toUpperCase();
|
||||||
|
String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " +
|
||||||
|
protocolString);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
switch (protocolString) {
|
||||||
|
case HTTP_PROTOCOL:
|
||||||
|
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
||||||
|
if (deviceHTTPEndpoint == null) {
|
||||||
|
return Response.status(Response.Status.PRECONDITION_FAILED).build();
|
||||||
|
}
|
||||||
|
VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
|
||||||
|
break;
|
||||||
|
case XMPP_PROTOCOL:
|
||||||
|
String xmppResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
||||||
|
virtualFireAlarmXMPPConnector.publishDeviceData(deviceId, xmppResource, switchToState);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
String mqttResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
||||||
|
virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, switchToState);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Response.ok().build();
|
||||||
|
} catch (DeviceManagementException | TransportHandlerException e) {
|
||||||
|
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("device/temperature")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public Response pushTemperatureData(final DeviceData dataMsg) {
|
||||||
|
String deviceId = dataMsg.deviceId;
|
||||||
|
String deviceIp = dataMsg.reply;
|
||||||
|
float temperature = dataMsg.value;
|
||||||
|
String registeredIp = deviceToIpMap.get(deviceId);
|
||||||
|
if (registeredIp == null) {
|
||||||
|
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
||||||
|
deviceIp + " for device ID - " + deviceId);
|
||||||
|
return Response.status(Response.Status.PRECONDITION_FAILED).build();
|
||||||
|
} else if (!registeredIp.equals(deviceIp)) {
|
||||||
|
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId +
|
||||||
|
" is already registered under some other IP. Re-registration required");
|
||||||
|
return Response.status(Response.Status.CONFLICT).build();
|
||||||
|
}
|
||||||
|
if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
return Response.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("device/scep")
|
||||||
|
public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Invoking SCEP operation " + operation);
|
||||||
|
}
|
||||||
|
if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Invoking GetCACert");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CertificateManagementService certificateManagementService =
|
||||||
|
VirtualFireAlarmServiceUtils.getCertificateManagementService();
|
||||||
|
SCEPResponse scepResponse = certificateManagementService.getCACertSCEP();
|
||||||
|
Response.ResponseBuilder responseBuilder;
|
||||||
|
switch (scepResponse.getResultCriteria()) {
|
||||||
|
case CA_CERT_FAILED:
|
||||||
|
log.error("CA cert failed");
|
||||||
|
responseBuilder = Response.serverError();
|
||||||
|
break;
|
||||||
|
case CA_CERT_RECEIVED:
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("CA certificate received in GetCACert");
|
||||||
|
}
|
||||||
|
responseBuilder = Response.ok(scepResponse.getEncodedResponse(),
|
||||||
|
ContentType.X_X509_CA_CERT);
|
||||||
|
break;
|
||||||
|
case CA_RA_CERT_RECEIVED:
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("CA and RA certificates received in GetCACert");
|
||||||
|
}
|
||||||
|
responseBuilder = Response.ok(scepResponse.getEncodedResponse(),
|
||||||
|
ContentType.X_X509_CA_RA_CERT);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.error("Invalid SCEP request");
|
||||||
|
responseBuilder = Response.serverError();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseBuilder.build();
|
||||||
|
} catch (VirtualFireAlarmException e) {
|
||||||
|
log.error("Error occurred while enrolling the VirtualFireAlarm device", e);
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
log.error("Keystore error occurred while enrolling the VirtualFireAlarm device", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Invoking GetCACaps");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils.
|
||||||
|
getCertificateManagementService();
|
||||||
|
byte caCaps[] = certificateManagementService.getCACapsSCEP();
|
||||||
|
|
||||||
|
return Response.ok(caCaps, MediaType.TEXT_PLAIN).build();
|
||||||
|
|
||||||
|
} catch (VirtualFireAlarmException e) {
|
||||||
|
log.error("Error occurred while enrolling the device", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("Invalid SCEP operation " + operation);
|
||||||
|
}
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("device/scep")
|
||||||
|
public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Invoking SCEP operation " + operation);
|
||||||
|
}
|
||||||
|
if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Invoking PKIOperation");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils.
|
||||||
|
getCertificateManagementService();
|
||||||
|
byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream);
|
||||||
|
return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build();
|
||||||
|
} catch (VirtualFireAlarmException e) {
|
||||||
|
log.error("Error occurred while enrolling the device", e);
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
log.error("Keystore error occurred while enrolling the device", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("device/stats/{deviceId}/sensors/{sensorName}")
|
||||||
|
@GET
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getVirtualFirealarmStats(@PathParam("deviceId") String deviceId,
|
||||||
|
@PathParam("sensorName") String sensor,
|
||||||
|
@QueryParam("username") String user, @QueryParam("from") long from,
|
||||||
|
@QueryParam("to") long to) {
|
||||||
|
String fromDate = String.valueOf(from);
|
||||||
|
String toDate = String.valueOf(to);
|
||||||
|
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
|
||||||
|
VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
|
||||||
|
String sensorTableName = getSensorEventTableName(sensor);
|
||||||
|
try {
|
||||||
|
if (sensorTableName != null) {
|
||||||
|
List<SortByField> sortByFields = new ArrayList<>();
|
||||||
|
SortByField sortByField = new SortByField("time", SORT.ASC, false);
|
||||||
|
sortByFields.add(sortByField);
|
||||||
|
List<SensorRecord> sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
|
||||||
|
return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
|
||||||
|
}
|
||||||
|
} catch (AnalyticsException e) {
|
||||||
|
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
|
||||||
|
log.error(errorMsg);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean waitForServerStartup() {
|
private boolean waitForServerStartup() {
|
||||||
while (!IoTServerStartupListener.isServerReady()) {
|
while (!IoTServerStartupListener.isServerReady()) {
|
||||||
try {
|
try {
|
||||||
@ -147,6 +355,7 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|||||||
};
|
};
|
||||||
|
|
||||||
Thread xmppStarterThread = new Thread(xmppStarter);
|
Thread xmppStarterThread = new Thread(xmppStarter);
|
||||||
|
xmppStarterThread.setDaemon(true);
|
||||||
xmppStarterThread.start();
|
xmppStarterThread.start();
|
||||||
} else {
|
} else {
|
||||||
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
|
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
|
||||||
@ -183,16 +392,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
||||||
//The delay is added for the server starts up.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
if (MqttConfig.getInstance().isEnabled()) {
|
if (MqttConfig.getInstance().isEnabled()) {
|
||||||
synchronized (virtualFireAlarmMQTTConnector) {
|
virtualFireAlarmMQTTConnector.connect();
|
||||||
virtualFireAlarmMQTTConnector.connect();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
|
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
|
||||||
}
|
}
|
||||||
@ -202,232 +403,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|||||||
connectorThread.start();
|
connectorThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) {
|
|
||||||
String result;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId);
|
|
||||||
}
|
|
||||||
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
|
||||||
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
|
||||||
result = "Device-IP Registered";
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug(result);
|
|
||||||
}
|
|
||||||
return Response.ok().entity(result).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response switchBuzzer(String deviceId, String protocol, String state) {
|
|
||||||
String switchToState = state.toUpperCase();
|
|
||||||
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
|
|
||||||
VirtualFireAlarmConstants.STATE_OFF)) {
|
|
||||||
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
||||||
}
|
|
||||||
String protocolString = protocol.toUpperCase();
|
|
||||||
String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " +
|
|
||||||
protocolString);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
switch (protocolString) {
|
|
||||||
case HTTP_PROTOCOL:
|
|
||||||
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
||||||
if (deviceHTTPEndpoint == null) {
|
|
||||||
return Response.status(Response.Status.PRECONDITION_FAILED).build();
|
|
||||||
}
|
|
||||||
VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
|
|
||||||
break;
|
|
||||||
case XMPP_PROTOCOL:
|
|
||||||
String xmppResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
|
||||||
virtualFireAlarmXMPPConnector.publishDeviceData(deviceId, xmppResource, switchToState);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String mqttResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
|
||||||
virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, switchToState);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return Response.ok().build();
|
|
||||||
} catch (DeviceManagementException | TransportHandlerException e) {
|
|
||||||
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response requestTemperature(String deviceId, String protocol) {
|
|
||||||
org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = null;
|
|
||||||
String protocolString = protocol.toUpperCase();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Sending request to read virtual-firealarm-temperature of device " +
|
|
||||||
"[" + deviceId + "] via " + protocolString);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
switch (protocolString) {
|
|
||||||
case HTTP_PROTOCOL:
|
|
||||||
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
||||||
if (deviceHTTPEndpoint == null) {
|
|
||||||
return Response.status(Response.Status.PRECONDITION_FAILED).build();
|
|
||||||
}
|
|
||||||
String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(
|
|
||||||
deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
||||||
temperatureValue,
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
break;
|
|
||||||
case XMPP_PROTOCOL:
|
|
||||||
String xmppResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
||||||
virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, xmppResource, "");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String mqttResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
||||||
virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, VirtualFireAlarmConstants
|
|
||||||
.SENSOR_TEMP);
|
|
||||||
return Response.ok().entity(sensorRecord).build();
|
|
||||||
} catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response pushTemperatureData(final DeviceData dataMsg) {
|
|
||||||
String deviceId = dataMsg.deviceId;
|
|
||||||
String deviceIp = dataMsg.reply;
|
|
||||||
float temperature = dataMsg.value;
|
|
||||||
String registeredIp = deviceToIpMap.get(deviceId);
|
|
||||||
if (registeredIp == null) {
|
|
||||||
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
|
||||||
deviceIp + " for device ID - " + deviceId);
|
|
||||||
return Response.status(Response.Status.PRECONDITION_FAILED).build();
|
|
||||||
} else if (!registeredIp.equals(deviceIp)) {
|
|
||||||
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId +
|
|
||||||
" is already registered under some other IP. Re-registration required");
|
|
||||||
return Response.status(Response.Status.CONFLICT).build();
|
|
||||||
}
|
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
||||||
String.valueOf(temperature),
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
||||||
}
|
|
||||||
return Response.ok().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response scepRequest(String operation, String message) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Invoking SCEP operation " + operation);
|
|
||||||
}
|
|
||||||
if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Invoking GetCACert");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
CertificateManagementService certificateManagementService =
|
|
||||||
VirtualFireAlarmServiceUtils.getCertificateManagementService();
|
|
||||||
SCEPResponse scepResponse = certificateManagementService.getCACertSCEP();
|
|
||||||
Response.ResponseBuilder responseBuilder;
|
|
||||||
switch (scepResponse.getResultCriteria()) {
|
|
||||||
case CA_CERT_FAILED:
|
|
||||||
log.error("CA cert failed");
|
|
||||||
responseBuilder = Response.serverError();
|
|
||||||
break;
|
|
||||||
case CA_CERT_RECEIVED:
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("CA certificate received in GetCACert");
|
|
||||||
}
|
|
||||||
responseBuilder = Response.ok(scepResponse.getEncodedResponse(),
|
|
||||||
ContentType.X_X509_CA_CERT);
|
|
||||||
break;
|
|
||||||
case CA_RA_CERT_RECEIVED:
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("CA and RA certificates received in GetCACert");
|
|
||||||
}
|
|
||||||
responseBuilder = Response.ok(scepResponse.getEncodedResponse(),
|
|
||||||
ContentType.X_X509_CA_RA_CERT);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log.error("Invalid SCEP request");
|
|
||||||
responseBuilder = Response.serverError();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBuilder.build();
|
|
||||||
} catch (VirtualFireAlarmException e) {
|
|
||||||
log.error("Error occurred while enrolling the VirtualFireAlarm device", e);
|
|
||||||
} catch (KeystoreException e) {
|
|
||||||
log.error("Keystore error occurred while enrolling the VirtualFireAlarm device", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) {
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Invoking GetCACaps");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils.
|
|
||||||
getCertificateManagementService();
|
|
||||||
byte caCaps[] = certificateManagementService.getCACapsSCEP();
|
|
||||||
|
|
||||||
return Response.ok(caCaps, MediaType.TEXT_PLAIN).build();
|
|
||||||
|
|
||||||
} catch (VirtualFireAlarmException e) {
|
|
||||||
log.error("Error occurred while enrolling the device", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.error("Invalid SCEP operation " + operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response.serverError().build();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response scepRequestPost(String operation, InputStream inputStream) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Invoking SCEP operation " + operation);
|
|
||||||
}
|
|
||||||
if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Invoking PKIOperation");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils.
|
|
||||||
getCertificateManagementService();
|
|
||||||
byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream);
|
|
||||||
return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build();
|
|
||||||
} catch (VirtualFireAlarmException e) {
|
|
||||||
log.error("Error occurred while enrolling the device", e);
|
|
||||||
} catch (KeystoreException e) {
|
|
||||||
log.error("Keystore error occurred while enrolling the device", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Response.serverError().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response getVirtualFirealarmStats(String deviceId, String sensor, String user, long from, long to) {
|
|
||||||
String fromDate = String.valueOf(from);
|
|
||||||
String toDate = String.valueOf(to);
|
|
||||||
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
|
|
||||||
VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
|
|
||||||
String sensorTableName = getSensorEventTableName(sensor);
|
|
||||||
try {
|
|
||||||
if (sensorTableName != null) {
|
|
||||||
List<SortByField> sortByFields = new ArrayList<>();
|
|
||||||
SortByField sortByField = new SortByField("time", SORT.ASC, false);
|
|
||||||
sortByFields.add(sortByField);
|
|
||||||
List<SensorRecord> sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
|
|
||||||
return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
|
|
||||||
}
|
|
||||||
} catch (AnalyticsException e) {
|
|
||||||
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
|
|
||||||
log.error(errorMsg);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the event table from the sensor name.
|
* get the event table from the sensor name.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -32,20 +32,21 @@ import javax.ws.rs.QueryParam;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
@API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = "virtual_firealarm")
|
@API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = "virtual_firealarm")
|
||||||
@DeviceType(value = "virtual_firealarm")
|
@DeviceType(value = "virtual_firealarm")
|
||||||
public interface VirtualFireAlarmManagerService {
|
public interface VirtualFireAlarmManagerService {
|
||||||
|
|
||||||
@Path("{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@DELETE
|
@DELETE
|
||||||
Response removeDevice(@PathParam("device_id") String deviceId);
|
Response removeDevice(@PathParam("device_id") String deviceId);
|
||||||
|
|
||||||
|
|
||||||
@Path("{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@PUT
|
@PUT
|
||||||
Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name);
|
Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name);
|
||||||
|
|
||||||
@Path("{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@GET
|
@GET
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ -57,13 +58,13 @@ public interface VirtualFireAlarmManagerService {
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
Response getFirealarmDevices();
|
Response getFirealarmDevices();
|
||||||
|
|
||||||
@Path("download")
|
@Path("devices/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType);
|
Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType);
|
||||||
|
|
||||||
|
|
||||||
@Path("generate_link")
|
@Path("devices/generate_link")
|
||||||
@GET
|
@GET
|
||||||
Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
||||||
@QueryParam("sketchType") String sketchType);
|
@QueryParam("sketchType") String sketchType);
|
||||||
|
|||||||
@ -40,6 +40,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
|||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -49,11 +58,143 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Path("enrollment")
|
||||||
public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManagerService {
|
public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManagerService {
|
||||||
|
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@DELETE
|
||||||
|
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
||||||
|
boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
|
||||||
|
deviceIdentifier);
|
||||||
|
if (removed) {
|
||||||
|
return Response.ok().build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@PUT
|
||||||
|
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
||||||
|
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||||
|
device.setName(name);
|
||||||
|
device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
||||||
|
boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
|
||||||
|
if (updated) {
|
||||||
|
return Response.ok().build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/{device_id}")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
||||||
|
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
return Response.ok().entity(device).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getFirealarmDevices() {
|
||||||
|
try {
|
||||||
|
List<Device> userDevices =
|
||||||
|
APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
|
||||||
|
ArrayList<Device> userDevicesforFirealarm = new ArrayList<>();
|
||||||
|
for (Device device : userDevices) {
|
||||||
|
if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) &&
|
||||||
|
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
|
||||||
|
userDevicesforFirealarm.add(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Device[] devices = userDevicesforFirealarm.toArray(new Device[]{});
|
||||||
|
return Response.ok().entity(devices).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/download")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response downloadSketch(@QueryParam("deviceName") String deviceName,
|
||||||
|
@QueryParam("sketchType") String sketchType) {
|
||||||
|
try {
|
||||||
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
||||||
|
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
||||||
|
response.type("application/zip");
|
||||||
|
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
|
return response.build();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (JWTClientException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (APIManagerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (DeviceControllerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (UserStoreException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("devices/generate_link")
|
||||||
|
@GET
|
||||||
|
public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
||||||
|
@QueryParam("sketchType") String sketchType) {
|
||||||
|
try {
|
||||||
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
||||||
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
|
return rb.build();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
|
} catch (DeviceManagementException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (JWTClientException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (APIManagerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (DeviceControllerException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (UserStoreException ex) {
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean register(String deviceId, String name) {
|
private boolean register(String deviceId, String name) {
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
@ -80,122 +221,6 @@ public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response removeDevice(String deviceId) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
|
||||||
boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
|
|
||||||
deviceIdentifier);
|
|
||||||
if (removed) {
|
|
||||||
return Response.ok().build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response updateDevice(String deviceId, String name) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
|
||||||
device.setDeviceIdentifier(deviceId);
|
|
||||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
|
||||||
device.setName(name);
|
|
||||||
device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
|
||||||
boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
|
|
||||||
if (updated) {
|
|
||||||
return Response.ok().build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response getDevice(String deviceId) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
|
||||||
Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
|
|
||||||
return Response.ok().entity(device).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response getFirealarmDevices() {
|
|
||||||
try {
|
|
||||||
List<Device> userDevices =
|
|
||||||
APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
|
|
||||||
ArrayList<Device> userDevicesforFirealarm = new ArrayList<>();
|
|
||||||
for (Device device : userDevices) {
|
|
||||||
if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) &&
|
|
||||||
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
|
|
||||||
userDevicesforFirealarm.add(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Device[] devices = userDevicesforFirealarm.toArray(new Device[]{});
|
|
||||||
return Response.ok().entity(devices).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response downloadSketch(String deviceName, String sketchType) {
|
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
|
||||||
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
|
||||||
response.type("application/zip");
|
|
||||||
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
|
||||||
return response.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response generateSketchLink(String deviceName, String sketchType) {
|
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
|
||||||
return rb.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
|
private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
|
||||||
throws DeviceManagementException, APIManagerException, JWTClientException, DeviceControllerException,
|
throws DeviceManagementException, APIManagerException, JWTClientException, DeviceControllerException,
|
||||||
UserStoreException {
|
UserStoreException {
|
||||||
|
|||||||
@ -25,14 +25,12 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|||||||
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
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.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
|
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException;
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException;
|
||||||
@ -207,9 +205,6 @@ public class VirtualFireAlarmMQTTConnector extends MQTTTransportHandler {
|
|||||||
|
|
||||||
} else if (actualMessage.contains("TEMPERATURE")) {
|
} else if (actualMessage.contains("TEMPERATURE")) {
|
||||||
String temperatureValue = actualMessage.split(":")[1];
|
String temperatureValue = actualMessage.split(":")[1];
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
||||||
temperatureValue,
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
}
|
}
|
||||||
} catch (VirtualFireAlarmException e) {
|
} catch (VirtualFireAlarmException e) {
|
||||||
String errorMsg =
|
String errorMsg =
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
|
|||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler;
|
import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler;
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
||||||
@ -182,10 +181,6 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler {
|
|||||||
break;
|
break;
|
||||||
case "CONTROL-REPLY":
|
case "CONTROL-REPLY":
|
||||||
String tempVal = actualMessage.split(":")[1];
|
String tempVal = actualMessage.split(":")[1];
|
||||||
SensorDataManager.getInstance().setSensorRecord(deviceId,
|
|
||||||
VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
||||||
tempVal,
|
|
||||||
Calendar.getInstance().getTimeInMillis());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
|
|
||||||
<jaxrs:server id="VirtualFireAlarmController" address="/device">
|
<jaxrs:server id="VirtualFireAlarm" address="/">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<bean id="VirtualFireAlarmControllerService"
|
<bean id="VirtualFireAlarmControllerService"
|
||||||
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.VirtualFireAlarmControllerServiceImpl">
|
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.VirtualFireAlarmControllerServiceImpl">
|
||||||
@ -31,14 +31,6 @@
|
|||||||
<property name="virtualFireAlarmMQTTConnector" ref="mqttConnectorBean"/>
|
<property name="virtualFireAlarmMQTTConnector" ref="mqttConnectorBean"/>
|
||||||
<property name="virtualFireAlarmXMPPConnector" ref="xmppConnectorBean"/>
|
<property name="virtualFireAlarmXMPPConnector" ref="xmppConnectorBean"/>
|
||||||
</bean>
|
</bean>
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
|
|
||||||
<jaxrs:server id="VirtualFireAlarmManager" address="/devices">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<bean id="VirtualFireAlarmManagerService"
|
<bean id="VirtualFireAlarmManagerService"
|
||||||
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.VirtualFireAlarmManagerServiceImpl">
|
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.VirtualFireAlarmManagerServiceImpl">
|
||||||
</bean>
|
</bean>
|
||||||
|
|||||||
@ -7,59 +7,40 @@
|
|||||||
<display-name>WSO2 IoT Server</display-name>
|
<display-name>WSO2 IoT Server</display-name>
|
||||||
<description>WSO2 IoT Server</description>
|
<description>WSO2 IoT Server</description>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<servlet-mapping>
|
<url-pattern>/*</url-pattern>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
</servlet-mapping>
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>isAdminService</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>doAuthentication</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<!--publish to apim-->
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-enabled</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-owner</param-name>
|
|
||||||
<param-value>admin</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>managed-api-context-template</param-name>
|
<param-name>isAdminService</param-name>
|
||||||
<param-value>/virtual_firealarm/{version}</param-value>
|
<param-value>false</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>managed-api-application</param-name>
|
<param-name>doAuthentication</param-name>
|
||||||
<param-value>virtual_firealarm</param-value>
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>isSharedWithAllTenants</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>providerTenantDomain</param-name>
|
||||||
|
<param-value>carbon.super</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-isSecured</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<!-- Below configuration is used to redirect http requests to https -->
|
<!--publish to apim-->
|
||||||
<!--<security-constraint>-->
|
<context-param>
|
||||||
<!--<web-resource-collection>-->
|
<param-name>managed-api-enabled</param-name>
|
||||||
<!--<web-resource-name>IoT</web-resource-name>-->
|
<param-value>true</param-value>
|
||||||
<!--<url-pattern>/*</url-pattern>-->
|
</context-param>
|
||||||
<!--</web-resource-collection>-->
|
<context-param>
|
||||||
<!--<user-data-constraint>-->
|
<param-name>managed-api-owner</param-name>
|
||||||
<!--<transport-guarantee>CONFIDENTIAL</transport-guarantee>-->
|
<param-value>admin</param-value>
|
||||||
<!--</user-data-constraint>-->
|
</context-param>
|
||||||
<!--</security-constraint>-->
|
|
||||||
|
|
||||||
|
</web-app>
|
||||||
</web-app>
|
|
||||||
@ -1,212 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>mobile-base-plugin</artifactId>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.mobile.api</artifactId>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
<name>WSO2 Carbon - Mobile Device Management API</name>
|
|
||||||
<description>WSO2 Carbon - Mobile Device Management API</description>
|
|
||||||
<url>http://wso2.org</url>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>1.7</source>
|
|
||||||
<target>1.7</target>
|
|
||||||
</configuration>
|
|
||||||
<version>2.3.2</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
|
||||||
<version>2.2</version>
|
|
||||||
<configuration>
|
|
||||||
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
|
|
||||||
<warName>${project.artifactId}</warName>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>deploy</id>
|
|
||||||
<build>
|
|
||||||
<defaultGoal>compile</defaultGoal>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-antrun-plugin</artifactId>
|
|
||||||
<version>1.7</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>run</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<tasks>
|
|
||||||
<copy todir="${basedir}/../../../repository/deployment/server/webapps"
|
|
||||||
overwrite="true">
|
|
||||||
<fileset dir="${basedir}/target">
|
|
||||||
<include name="${project.artifactId}.war"/>
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
</tasks>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>client</id>
|
|
||||||
<build>
|
|
||||||
<defaultGoal>test</defaultGoal>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<version>1.2.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>java</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-transports-http</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-httpclient.wso2</groupId>
|
|
||||||
<artifactId>commons-httpclient</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.ws.rs</groupId>
|
|
||||||
<artifactId>jsr311-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.commons</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.user.mgt</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.axis2.wso2</groupId>
|
|
||||||
<artifactId>axis2-client</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.axis2.wso2</groupId>
|
|
||||||
<artifactId>axis2-client</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.identity</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.axis2.wso2</groupId>
|
|
||||||
<artifactId>axis2-client</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec.wso2</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Authentication related REST-API implementation.
|
|
||||||
*/
|
|
||||||
@Produces({ "application/json", "application/xml" })
|
|
||||||
@Consumes({ "application/json", "application/xml" })
|
|
||||||
public class Authentication {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Authentication.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,194 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.beans.EnrollmentCertificate;
|
|
||||||
import org.wso2.carbon.mdm.exception.Message;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.HeaderParam;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All the certificate related tasks such as saving certificates, can be done through this endpoint.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
@Produces({"application/json", "application/xml"})
|
|
||||||
@Consumes({ "application/json", "application/xml" })
|
|
||||||
public class Certificate {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Operation.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save a list of certificates and relevant information in the database.
|
|
||||||
*
|
|
||||||
* @param enrollmentCertificates List of all the certificates which includes the tenant id, certificate as
|
|
||||||
* a pem and a serial number.
|
|
||||||
* @return Status of the data persist operation.
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("saveCertificate")
|
|
||||||
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
|
|
||||||
EnrollmentCertificate[] enrollmentCertificates) {
|
|
||||||
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
|
||||||
CertificateManagementService certificateService;
|
|
||||||
List<org.wso2.carbon.certificate.mgt.core.bean.Certificate> certificates = new ArrayList<>();
|
|
||||||
org.wso2.carbon.certificate.mgt.core.bean.Certificate certificate;
|
|
||||||
certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
|
||||||
try {
|
|
||||||
for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) {
|
|
||||||
certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
|
|
||||||
certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
||||||
certificate.setSerial(enrollmentCertificate.getSerial());
|
|
||||||
certificate.setCertificate(certificateService.pemToX509Certificate(enrollmentCertificate.getPem()));
|
|
||||||
certificates.add(certificate);
|
|
||||||
}
|
|
||||||
certificateService.saveCertificate(certificates);
|
|
||||||
return Response.status(Response.Status.CREATED).entity("Added successfully.").
|
|
||||||
type(responseMediaType).build();
|
|
||||||
} catch (KeystoreException e) {
|
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a certificate when the serial number is given.
|
|
||||||
*
|
|
||||||
* @param serialNumber serial of the certificate needed.
|
|
||||||
* @return certificate response.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("{serialNumber}")
|
|
||||||
public Response getCertificate(@HeaderParam("Accept") String acceptHeader,
|
|
||||||
@PathParam("serialNumber") String serialNumber) {
|
|
||||||
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
|
||||||
Message message = new Message();
|
|
||||||
|
|
||||||
if (serialNumber == null || serialNumber.isEmpty()) {
|
|
||||||
message.setErrorMessage("Invalid serial number");
|
|
||||||
message.setDiscription("Serial number is missing or invalid.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
|
||||||
CertificateResponse certificateResponse;
|
|
||||||
try {
|
|
||||||
certificateResponse = certificateService.getCertificateBySerial(serialNumber);
|
|
||||||
if(certificateResponse != null) {
|
|
||||||
certificateResponse.setCertificate(null); //avoid sending byte array in response.
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build();
|
|
||||||
} catch (KeystoreException e) {
|
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all certificates in a paginated manner.
|
|
||||||
*
|
|
||||||
* @param startIndex index of the first record to be fetched
|
|
||||||
* @param length number of records to be fetched starting from the start index.
|
|
||||||
* @return paginated result of certificate.
|
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("paginate")
|
|
||||||
public Response getAllCertificates(@HeaderParam("Accept") String acceptHeader,
|
|
||||||
@QueryParam("start") int startIndex,
|
|
||||||
@QueryParam("length") int length)
|
|
||||||
throws MDMAPIException {
|
|
||||||
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
|
||||||
Message message = new Message();
|
|
||||||
|
|
||||||
if (startIndex < 0) {
|
|
||||||
message.setErrorMessage("Invalid start index.");
|
|
||||||
message.setDiscription("Start index cannot be less that 0.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
|
||||||
} else if (length <= 0) {
|
|
||||||
message.setErrorMessage("Invalid length value.");
|
|
||||||
message.setDiscription("Length should be a positive integer.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
|
||||||
PaginationRequest paginationRequest = new PaginationRequest(startIndex, length);
|
|
||||||
try {
|
|
||||||
PaginationResult certificates = certificateService.getAllCertificates(paginationRequest);
|
|
||||||
return Response.status(Response.Status.OK).entity(certificates).type(responseMediaType).build();
|
|
||||||
} catch (CertificateManagementDAOException e) {
|
|
||||||
String msg = "Error occurred while fetching all certificates.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("{serialNumber}")
|
|
||||||
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,
|
|
||||||
@PathParam("serialNumber") String serialNumber) throws MDMAPIException {
|
|
||||||
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
|
||||||
Message message = new Message();
|
|
||||||
|
|
||||||
if (serialNumber == null || serialNumber.isEmpty()) {
|
|
||||||
message.setErrorMessage("Invalid serial number");
|
|
||||||
message.setDiscription("Serial number is missing or invalid.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
|
||||||
boolean deleted;
|
|
||||||
try {
|
|
||||||
deleted = certificateService.removeCertificate(serialNumber);
|
|
||||||
if(deleted){
|
|
||||||
return Response.status(Response.Status.OK).entity(deleted).type(responseMediaType).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.GONE).entity(deleted).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
} catch (CertificateManagementDAOException e) {
|
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,113 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAppConstants;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* General Tenant Configuration REST-API implementation.
|
|
||||||
* All end points support JSON, XMl with content negotiation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
@Produces({"application/json", "application/xml"})
|
|
||||||
@Consumes({ "application/json", "application/xml" })
|
|
||||||
public class Configuration {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Configuration.class);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
public Response saveTenantConfiguration(TenantConfiguration configuration) {
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
|
||||||
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
|
||||||
//Schedule the task service
|
|
||||||
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(configuration));
|
|
||||||
responseMsg.setMessageFromServer("Tenant configuration saved successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (ConfigurationManagementException e) {
|
|
||||||
String msg = "Error occurred while saving the tenant configuration.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
public Response getConfiguration() {
|
|
||||||
String msg;
|
|
||||||
try {
|
|
||||||
TenantConfiguration tenantConfiguration = DeviceMgtAPIUtils.getTenantConfigurationManagementService().
|
|
||||||
getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
|
||||||
ConfigurationEntry configurationEntry = new ConfigurationEntry();
|
|
||||||
configurationEntry.setContentType("text");
|
|
||||||
configurationEntry.setName("notifierFrequency");
|
|
||||||
configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency());
|
|
||||||
List<ConfigurationEntry> configList = tenantConfiguration.getConfiguration();
|
|
||||||
if (configList == null) {
|
|
||||||
configList = new ArrayList<>();
|
|
||||||
}
|
|
||||||
configList.add(configurationEntry);
|
|
||||||
tenantConfiguration.setConfiguration(configList);
|
|
||||||
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
|
||||||
} catch (ConfigurationManagementException e) {
|
|
||||||
msg = "Error occurred while retrieving the tenant configuration.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
public Response updateConfiguration(TenantConfiguration configuration) {
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
|
||||||
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
|
||||||
//Schedule the task service
|
|
||||||
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(configuration));
|
|
||||||
responseMsg.setMessageFromServer("Tenant configuration updated successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (ConfigurationManagementException e) {
|
|
||||||
String msg = "Error occurred while updating the tenant configuration.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,234 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device related operations
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class Device {
|
|
||||||
private static Log log = LogFactory.getLog(Device.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all devices. We have to use accept all the necessary query parameters sent by datatable.
|
|
||||||
* Hence had to put lot of query params here.
|
|
||||||
*
|
|
||||||
* @return Device List
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
public Response getAllDevices(@QueryParam("type") String type, @QueryParam("user") String user,
|
|
||||||
@QueryParam("role") String role, @QueryParam("status") EnrolmentInfo.Status status,
|
|
||||||
@QueryParam("start") int startIdx, @QueryParam("length") int length,
|
|
||||||
@QueryParam("device-name") String deviceName,
|
|
||||||
@QueryParam("ownership") EnrolmentInfo.OwnerShip ownership) {
|
|
||||||
try {
|
|
||||||
DeviceManagementProviderService service = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
//Length > 0 means this is a pagination request.
|
|
||||||
if (length > 0) {
|
|
||||||
PaginationRequest paginationRequest = new PaginationRequest(startIdx, length);
|
|
||||||
paginationRequest.setDeviceName(deviceName);
|
|
||||||
paginationRequest.setOwner(user);
|
|
||||||
if (ownership != null) {
|
|
||||||
paginationRequest.setOwnership(ownership.toString());
|
|
||||||
}
|
|
||||||
if (status != null) {
|
|
||||||
paginationRequest.setStatus(status.toString());
|
|
||||||
}
|
|
||||||
paginationRequest.setDeviceType(type);
|
|
||||||
return Response.status(Response.Status.OK).entity(service.getAllDevices(paginationRequest)).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<org.wso2.carbon.device.mgt.common.Device> allDevices;
|
|
||||||
if ((type != null) && !type.isEmpty()) {
|
|
||||||
allDevices = service.getAllDevices(type);
|
|
||||||
} else if ((user != null) && !user.isEmpty()) {
|
|
||||||
allDevices = service.getDevicesOfUser(user);
|
|
||||||
} else if ((role != null) && !role.isEmpty()) {
|
|
||||||
allDevices = service.getAllDevicesOfRole(role);
|
|
||||||
} else if (status != null) {
|
|
||||||
allDevices = service.getDevicesByStatus(status);
|
|
||||||
} else if (deviceName != null) {
|
|
||||||
allDevices = service.getDevicesByName(deviceName);
|
|
||||||
} else {
|
|
||||||
allDevices = service.getAllDevices();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(allDevices).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the device list.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch device details for a given device type and device Id.
|
|
||||||
*
|
|
||||||
* @return Device wrapped inside Response
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("view")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getDevice(@QueryParam("type") String type,
|
|
||||||
@QueryParam("id") String id) {
|
|
||||||
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
org.wso2.carbon.device.mgt.common.Device device;
|
|
||||||
try {
|
|
||||||
device = deviceManagementProviderService.getDevice(deviceIdentifier);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the device information.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
if (device == null) {
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
|
||||||
responsePayload.setMessageFromServer("Requested device by type: " +
|
|
||||||
type + " and id: " + id + " does not exist.");
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Sending Requested device by type: " + type + " and id: " + id + ".");
|
|
||||||
responsePayload.setResponseContent(device);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch device details of a given user.
|
|
||||||
*
|
|
||||||
* @param user User Name
|
|
||||||
* @return Device
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("user/{user}")
|
|
||||||
public Response getDevice(@PathParam("user") String user) {
|
|
||||||
List<org.wso2.carbon.device.mgt.common.Device> devices;
|
|
||||||
try {
|
|
||||||
devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(user);
|
|
||||||
if (devices == null) {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(devices).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the devices list of given user.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch device count of a given user.
|
|
||||||
*
|
|
||||||
* @param user User Name
|
|
||||||
* @return Device
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("user/{user}/count")
|
|
||||||
public Response getDeviceCount(@PathParam("user") String user) {
|
|
||||||
try {
|
|
||||||
Integer count = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount(user);
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the devices list of given user.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current device count
|
|
||||||
*
|
|
||||||
* @return device count
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("count")
|
|
||||||
public Response getDeviceCount() {
|
|
||||||
try {
|
|
||||||
Integer count = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount();
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the device count.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of devices that matches with the given name.
|
|
||||||
*
|
|
||||||
* @param deviceName Device name
|
|
||||||
* @param tenantDomain Callee tenant domain
|
|
||||||
* @return list of devices.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("name/{name}/{tenantDomain}")
|
|
||||||
public Response getDevicesByName(@PathParam("name") String deviceName,
|
|
||||||
@PathParam("tenantDomain") String tenantDomain) {
|
|
||||||
List<org.wso2.carbon.device.mgt.common.Device> devices;
|
|
||||||
try {
|
|
||||||
devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesByName(deviceName);
|
|
||||||
return Response.status(Response.Status.OK).entity(devices).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the devices list of device name.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of available device types.
|
|
||||||
*
|
|
||||||
* @return list of device types.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("types")
|
|
||||||
public Response getDeviceTypes() {
|
|
||||||
List<DeviceType> deviceTypes;
|
|
||||||
try {
|
|
||||||
deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes();
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceTypes).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the list of device types.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,80 +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.api;
|
|
||||||
|
|
||||||
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.common.device.details.DeviceInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class DeviceInformation {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceInformation.class);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{type}/{id}")
|
|
||||||
public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id) {
|
|
||||||
DeviceInformationManager informationManager;
|
|
||||||
DeviceInfo deviceInfo;
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(id);
|
|
||||||
deviceIdentifier.setType(type);
|
|
||||||
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
|
|
||||||
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
|
|
||||||
} catch (DeviceDetailsMgtException e) {
|
|
||||||
String msg = "Error occurred while getting the device information.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceInfo).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("location/{type}/{id}")
|
|
||||||
public Response getDeviceLocation(@PathParam("type") String type, @PathParam("id") String id) {
|
|
||||||
DeviceInformationManager informationManager;
|
|
||||||
DeviceLocation deviceLocation;
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(id);
|
|
||||||
deviceIdentifier.setType(type);
|
|
||||||
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
|
|
||||||
deviceLocation = informationManager.getDeviceLocation(deviceIdentifier);
|
|
||||||
} catch (DeviceDetailsMgtException e) {
|
|
||||||
String msg = "Error occurred while getting the device location.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceLocation).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,109 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DeviceNotification management REST-API implementation.
|
|
||||||
* All end points support JSON, XMl with content negotiation.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
@Produces({"application/json", "application/xml"})
|
|
||||||
@Consumes({ "application/json", "application/xml" })
|
|
||||||
public class DeviceNotification {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Configuration.class);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
public Response getNotifications() {
|
|
||||||
String msg;
|
|
||||||
try {
|
|
||||||
List<Notification> notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
|
|
||||||
return Response.status(Response.Status.OK).entity(notifications).build();
|
|
||||||
} catch (NotificationManagementException e) {
|
|
||||||
msg = "Error occurred while retrieving the notification list.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{status}")
|
|
||||||
public Response getNotificationsByStatus(@PathParam("status") Notification.Status status) {
|
|
||||||
String msg;
|
|
||||||
try {
|
|
||||||
List<Notification> notifications = DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(status);
|
|
||||||
return Response.status(Response.Status.OK).entity(notifications).build();
|
|
||||||
} catch (NotificationManagementException e) {
|
|
||||||
msg = "Error occurred while retrieving the notification list.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("{id}/{status}")
|
|
||||||
public Response updateNotificationStatus(@PathParam("id") int id,
|
|
||||||
@PathParam("status") Notification.Status status) {
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
|
|
||||||
responseMsg.setMessageFromServer("Notification status updated successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_ACCEPTED);
|
|
||||||
return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build();
|
|
||||||
} catch (NotificationManagementException e) {
|
|
||||||
String msg = "Error occurred while updating notification status.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
public Response addNotification(Notification notification) {
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getNotificationManagementService().addNotification(notification);
|
|
||||||
responseMsg.setMessageFromServer("Notification has added successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (NotificationManagementException e) {
|
|
||||||
String msg = "Error occurred while updating notification status.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
|
||||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class DeviceSearch {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceSearch.class);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
public Response getDeviceInfo(SearchContext searchContext) {
|
|
||||||
SearchManagerService searchManagerService;
|
|
||||||
List<DeviceWrapper> devices;
|
|
||||||
try {
|
|
||||||
searchManagerService = DeviceMgtAPIUtils.getSearchManagerService();
|
|
||||||
devices = searchManagerService.search(searchContext);
|
|
||||||
|
|
||||||
} catch (SearchMgtException e) {
|
|
||||||
String msg = "Error occurred while searching the device information.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(devices).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,65 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Features
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
@Produces({"application/json", "application/xml"})
|
|
||||||
@Consumes({"application/json", "application/xml"})
|
|
||||||
public class Feature {
|
|
||||||
private static Log log = LogFactory.getLog(Feature.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all features for Mobile Device Type
|
|
||||||
*
|
|
||||||
* @return Feature
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("/{type}")
|
|
||||||
public Response getFeatures(@PathParam("type") String type) {
|
|
||||||
List<org.wso2.carbon.device.mgt.common.Feature> features;
|
|
||||||
DeviceManagementProviderService dmService;
|
|
||||||
try {
|
|
||||||
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
features = dmService.getFeatureManager(type).getFeatures();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of features";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(features).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,443 +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.api;
|
|
||||||
|
|
||||||
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.Device;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.FormParam;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class Group {
|
|
||||||
|
|
||||||
private static final String DEFAULT_ADMIN_ROLE = "admin";
|
|
||||||
private static final String DEFAULT_OPERATOR_ROLE = "invoke-device-operations";
|
|
||||||
private static final String DEFAULT_STATS_MONITOR_ROLE = "view-statistics";
|
|
||||||
private static final String DEFAULT_VIEW_POLICIES = "view-policies";
|
|
||||||
private static final String DEFAULT_MANAGE_POLICIES = "mange-policies";
|
|
||||||
private static final String DEFAULT_VIEW_EVENTS = "view-events";
|
|
||||||
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
|
|
||||||
"/permission/device-mgt/user/groups"};
|
|
||||||
private static final String[] DEFAULT_OPERATOR_PERMISSIONS = {"/permission/device-mgt/user/groups/device_operation"};
|
|
||||||
private static final String[] DEFAULT_STATS_MONITOR_PERMISSIONS = {"/permission/device-mgt/user/groups/device_monitor"};
|
|
||||||
private static final String[] DEFAULT_MANAGE_POLICIES_PERMISSIONS = {"/permission/device-mgt/user/groups/device_policies/add"};
|
|
||||||
private static final String[] DEFAULT_VIEW_POLICIES_PERMISSIONS = {"/permission/device-mgt/user/groups/device_policies/view"};
|
|
||||||
private static final String[] DEFAULT_VIEW_EVENTS_PERMISSIONS = {"/permission/device-mgt/user/groups/device_events"};
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Group.class);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Consumes("application/json")
|
|
||||||
public Response createGroup(DeviceGroup group) {
|
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
||||||
if (group == null) {
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
||||||
}
|
|
||||||
group.setOwner(owner);
|
|
||||||
group.setDateOfCreation(new Date().getTime());
|
|
||||||
group.setDateOfLastUpdate(new Date().getTime());
|
|
||||||
try {
|
|
||||||
GroupManagementProviderService groupManagementService = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
|
||||||
groupManagementService.createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
||||||
groupManagementService.addGroupSharingRole(owner, group.getName(), owner,
|
|
||||||
DEFAULT_OPERATOR_ROLE,
|
|
||||||
DEFAULT_OPERATOR_PERMISSIONS);
|
|
||||||
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_STATS_MONITOR_ROLE,
|
|
||||||
DEFAULT_STATS_MONITOR_PERMISSIONS);
|
|
||||||
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_VIEW_POLICIES,
|
|
||||||
DEFAULT_VIEW_POLICIES_PERMISSIONS);
|
|
||||||
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_MANAGE_POLICIES,
|
|
||||||
DEFAULT_MANAGE_POLICIES_PERMISSIONS);
|
|
||||||
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_VIEW_EVENTS,
|
|
||||||
DEFAULT_VIEW_EVENTS_PERMISSIONS);
|
|
||||||
return Response.status(Response.Status.CREATED).build();
|
|
||||||
} catch (GroupAlreadyEixistException e) {
|
|
||||||
return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getErrorMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/{owner}/{groupName}")
|
|
||||||
@PUT
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response updateGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
|
||||||
DeviceGroup deviceGroup) {
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupName, owner);
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getErrorMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/{owner}/{groupName}")
|
|
||||||
@DELETE
|
|
||||||
public Response deleteGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner) {
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupName, owner);
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getGroups(@QueryParam("start") int startIndex, @PathParam("rowCount") int rowCount) {
|
|
||||||
try {
|
|
||||||
PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
|
||||||
.getGroups(startIndex, rowCount);
|
|
||||||
if (paginationResult.getRecordsTotal() > 0) {
|
|
||||||
return Response.status(Response.Status.OK).entity(paginationResult).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/user/{user}")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getGroups(@PathParam("user") String userName, @QueryParam("start") int startIndex,
|
|
||||||
@QueryParam("rowCount") int rowCount) {
|
|
||||||
try {
|
|
||||||
PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
|
||||||
.getGroups(userName, startIndex, rowCount);
|
|
||||||
if (paginationResult.getRecordsTotal() > 0) {
|
|
||||||
return Response.status(Response.Status.OK).entity(paginationResult).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/{owner}/{groupName}")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner) {
|
|
||||||
try {
|
|
||||||
DeviceGroup deviceGroup = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroup(groupName, owner);
|
|
||||||
if (deviceGroup != null) {
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceGroup).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/search")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response findGroups(@QueryParam("groupName") String groupName,
|
|
||||||
@QueryParam("userName") String userName) {
|
|
||||||
try {
|
|
||||||
List<DeviceGroup> groups = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
|
||||||
.findInGroups(groupName, userName);
|
|
||||||
DeviceGroup[] deviceGroups = new DeviceGroup[groups.size()];
|
|
||||||
groups.toArray(deviceGroups);
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceGroups).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/user/{user}/all")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getGroups(@PathParam("user") String userName,
|
|
||||||
@QueryParam("permission") String permission) {
|
|
||||||
try {
|
|
||||||
GroupManagementProviderService groupManagementService = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
|
||||||
List<DeviceGroup> groups;
|
|
||||||
if (permission != null) {
|
|
||||||
groups = groupManagementService.getGroups(userName, permission);
|
|
||||||
} else {
|
|
||||||
groups = groupManagementService.getGroups(userName);
|
|
||||||
}
|
|
||||||
DeviceGroup[] deviceGroups = new DeviceGroup[groups.size()];
|
|
||||||
groups.toArray(deviceGroups);
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceGroups).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/user/{user}/count")
|
|
||||||
@GET
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getGroupCount(@PathParam("user") String userName) {
|
|
||||||
try {
|
|
||||||
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(userName);
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/{owner}/{groupName}/share")
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response shareGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
|
||||||
@FormParam("shareUser") String shareUser,
|
|
||||||
@FormParam("roleName") String sharingRole) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean isShared = DeviceMgtAPIUtils.getGroupManagementProviderService().shareGroup(
|
|
||||||
shareUser, groupName, owner, sharingRole);
|
|
||||||
if (isShared) {
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/{owner}/{groupName}/unshare")
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response unShareGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
|
||||||
@FormParam("unShareUser") String unShareUser,
|
|
||||||
@FormParam("roleName") String sharingRole) {
|
|
||||||
try {
|
|
||||||
boolean isUnShared = DeviceMgtAPIUtils.getGroupManagementProviderService().unshareGroup(
|
|
||||||
unShareUser, groupName, owner, sharingRole);
|
|
||||||
if (isUnShared) {
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/{owner}/{groupName}/share/roles/{roleName}/permissions")
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response addSharing(@QueryParam("shareUser") String shareUser, @PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner,
|
|
||||||
@PathParam("roleName") String roleName,
|
|
||||||
@FormParam("permissions") String[] permissions) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addGroupSharingRole(
|
|
||||||
shareUser, groupName, owner, roleName, permissions);
|
|
||||||
if (isAdded) {
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{owner}/{groupName}/share/roles/{roleName}/permissions")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response removeSharing(@QueryParam("userName") String userName, @PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner,
|
|
||||||
@PathParam("roleName") String roleName) {
|
|
||||||
try {
|
|
||||||
boolean isRemoved = DeviceMgtAPIUtils.getGroupManagementProviderService().removeGroupSharingRole(
|
|
||||||
groupName, owner, roleName);
|
|
||||||
if (isRemoved) {
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{owner}/{groupName}/share/roles")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getRoles(@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner, @QueryParam("userName") String userName) {
|
|
||||||
try {
|
|
||||||
List<String> roles;
|
|
||||||
if (userName != null && !userName.isEmpty()) {
|
|
||||||
roles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(userName, groupName, owner);
|
|
||||||
} else {
|
|
||||||
roles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupName, owner);
|
|
||||||
}
|
|
||||||
String[] rolesArray = new String[roles.size()];
|
|
||||||
roles.toArray(rolesArray);
|
|
||||||
return Response.status(Response.Status.OK).entity(rolesArray).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{owner}/{groupName}/users")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getUsers(@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner) {
|
|
||||||
try {
|
|
||||||
List<GroupUser> users = DeviceMgtAPIUtils.getGroupManagementProviderService().getUsers(
|
|
||||||
groupName, owner);
|
|
||||||
GroupUser[] usersArray = new GroupUser[users.size()];
|
|
||||||
users.toArray(usersArray);
|
|
||||||
return Response.status(Response.Status.OK).entity(usersArray).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{owner}/{groupName}/devices/all")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDevices(@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner) {
|
|
||||||
try {
|
|
||||||
List<Device> devices = DeviceMgtAPIUtils.getGroupManagementProviderService().getDevices(
|
|
||||||
groupName, owner);
|
|
||||||
Device[] deviceArray = new Device[devices.size()];
|
|
||||||
devices.toArray(deviceArray);
|
|
||||||
return Response.status(Response.Status.OK).entity(deviceArray).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{owner}/{groupName}/devices/count")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getDeviceCount(@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner) {
|
|
||||||
try {
|
|
||||||
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupName, owner);
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{owner}/{groupName}/devices/{deviceType}/{deviceId}")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response addDevice(@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
|
|
||||||
@PathParam("deviceType") String deviceType,
|
|
||||||
@FormParam("userName") String userName) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
|
||||||
boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addDevice(
|
|
||||||
deviceIdentifier, groupName, owner);
|
|
||||||
if (isAdded) {
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{owner}/{groupName}/devices/{deviceType}/{deviceId}")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response removeDevice(@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
|
|
||||||
@PathParam("deviceType") String deviceType) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
|
||||||
boolean isRemoved = DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(
|
|
||||||
deviceIdentifier, groupName, owner);
|
|
||||||
if (isRemoved) {
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
} else {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{owner}/{groupName}/users/{userName}/permissions")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response getPermissions(@PathParam("userName") String userName,
|
|
||||||
@PathParam("groupName") String groupName,
|
|
||||||
@PathParam("owner") String owner) {
|
|
||||||
try {
|
|
||||||
String[] permissions = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
|
||||||
.getPermissions(userName, groupName, owner);
|
|
||||||
return Response.status(Response.Status.OK).entity(permissions).build();
|
|
||||||
} catch (GroupManagementException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,101 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents license related operations.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class License {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(License.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns the license text related to a given device type and language code.
|
|
||||||
*
|
|
||||||
* @param deviceType Device type, ex: android, ios
|
|
||||||
* @param languageCode Language code, ex: en_US
|
|
||||||
* @return Returns the license text
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path ("{deviceType}/{languageCode}")
|
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getLicense(@PathParam ("deviceType") String deviceType,
|
|
||||||
@PathParam("languageCode") String languageCode) {
|
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.common.license.mgt.License license;
|
|
||||||
ResponsePayload responsePayload;
|
|
||||||
try {
|
|
||||||
license = DeviceMgtAPIUtils.getDeviceManagementService().getLicense(deviceType, languageCode);
|
|
||||||
if (license == null) {
|
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK).
|
|
||||||
messageFromServer("License for '" + deviceType + "' was retrieved successfully").
|
|
||||||
responseContent(license.getText()).
|
|
||||||
build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while retrieving the license configured for '" + deviceType + "' device type";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to add license to a specific device type.
|
|
||||||
*
|
|
||||||
* @param deviceType Device type, ex: android, ios
|
|
||||||
* @param license License object
|
|
||||||
* @return Returns the acknowledgement for the action
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path ("{deviceType}")
|
|
||||||
public Response addLicense(@PathParam ("deviceType") String deviceType,
|
|
||||||
org.wso2.carbon.device.mgt.common.license.mgt.License license) {
|
|
||||||
|
|
||||||
ResponsePayload responsePayload;
|
|
||||||
try {
|
|
||||||
DeviceMgtAPIUtils.getDeviceManagementService().addLicense(deviceType, license);
|
|
||||||
responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK).
|
|
||||||
messageFromServer("License added successfully for '" + deviceType + "' device type").
|
|
||||||
build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while adding license for '" + deviceType + "' device type";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,220 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.common.PaginationRequest;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
||||||
import org.wso2.carbon.device.mgt.common.Platform;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.api.context.DeviceOperationContext;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAndroidOperationUtil;
|
|
||||||
import org.wso2.carbon.mdm.api.util.MDMIOSOperationUtil;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.mdm.beans.ApplicationWrapper;
|
|
||||||
import org.wso2.carbon.mdm.beans.MobileApp;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Operation related REST-API implementation.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
@Produces({"application/json", "application/xml"})
|
|
||||||
@Consumes({"application/json", "application/xml"})
|
|
||||||
public class Operation {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Operation.class);
|
|
||||||
|
|
||||||
/* @deprecated */
|
|
||||||
@GET
|
|
||||||
public Response getAllOperations() {
|
|
||||||
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
|
||||||
DeviceManagementProviderService dmService;
|
|
||||||
try {
|
|
||||||
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
operations = dmService.getOperations(null);
|
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the operations for the device.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(operations).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("paginate/{type}/{id}")
|
|
||||||
public Response getDeviceOperations(
|
|
||||||
@PathParam("type") String type, @PathParam("id") String id, @QueryParam("start") int startIdx,
|
|
||||||
@QueryParam("length") int length, @QueryParam("search") String search) {
|
|
||||||
PaginationResult operations;
|
|
||||||
DeviceManagementProviderService dmService;
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
PaginationRequest paginationRequest = new PaginationRequest(startIdx, length);
|
|
||||||
try {
|
|
||||||
deviceIdentifier.setType(type);
|
|
||||||
deviceIdentifier.setId(id);
|
|
||||||
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
operations = dmService.getOperations(deviceIdentifier, paginationRequest);
|
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the operations for the device.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(operations).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{type}/{id}")
|
|
||||||
public Response getDeviceOperations(@PathParam("type") String type, @PathParam("id") String id) {
|
|
||||||
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
|
||||||
DeviceManagementProviderService dmService;
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
try {
|
|
||||||
deviceIdentifier.setType(type);
|
|
||||||
deviceIdentifier.setId(id);
|
|
||||||
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
operations = dmService.getOperations(deviceIdentifier);
|
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the operations for the device.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(operations).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @deprecated */
|
|
||||||
@POST
|
|
||||||
public Response addOperation(DeviceOperationContext operationContext) {
|
|
||||||
DeviceManagementProviderService dmService;
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
int operationId = dmService.addOperation(operationContext.getOperation(), operationContext.getDevices());
|
|
||||||
if (operationId > 0) {
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Operation has added successfully.");
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
String msg = "Error occurred while saving the operation";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{type}/{id}/apps")
|
|
||||||
public Response getInstalledApps(@PathParam("type") String type, @PathParam("id") String id) {
|
|
||||||
List<Application> applications;
|
|
||||||
ApplicationManagementProviderService appManagerConnector;
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
try {
|
|
||||||
deviceIdentifier.setType(type);
|
|
||||||
deviceIdentifier.setId(id);
|
|
||||||
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
|
||||||
applications = appManagerConnector.getApplicationListForDevice(deviceIdentifier);
|
|
||||||
} catch (ApplicationManagementException e) {
|
|
||||||
String msg = "Error occurred while fetching the apps of the device.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.CREATED).entity(applications).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("installApp/{tenantDomain}")
|
|
||||||
public Response installApplication(ApplicationWrapper applicationWrapper,
|
|
||||||
@PathParam("tenantDomain") String tenantDomain) {
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
ApplicationManager appManagerConnector;
|
|
||||||
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
|
||||||
try {
|
|
||||||
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
|
||||||
MobileApp mobileApp = applicationWrapper.getApplication();
|
|
||||||
|
|
||||||
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
|
||||||
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
|
||||||
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
|
||||||
operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp);
|
|
||||||
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
|
||||||
operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
|
||||||
}
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Application installation request has been sent to the device.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (ApplicationManagementException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while saving the operation";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("uninstallApp/{tenantDomain}")
|
|
||||||
public Response uninstallApplication(ApplicationWrapper applicationWrapper,
|
|
||||||
@PathParam("tenantDomain") String tenantDomain) {
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
ApplicationManager appManagerConnector;
|
|
||||||
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
|
||||||
try {
|
|
||||||
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
|
||||||
MobileApp mobileApp = applicationWrapper.getApplication();
|
|
||||||
|
|
||||||
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
|
||||||
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
|
||||||
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
|
||||||
operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp);
|
|
||||||
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
|
||||||
operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
|
||||||
}
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Application removal request has been sent to the device.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (ApplicationManagementException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while saving the operation";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,430 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.mdm.beans.PolicyWrapper;
|
|
||||||
import org.wso2.carbon.mdm.beans.PriorityUpdatedPolicyWrapper;
|
|
||||||
import org.wso2.carbon.mdm.util.MDMUtil;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class Policy {
|
|
||||||
private static Log log = LogFactory.getLog(Policy.class);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("inactive-policy")
|
|
||||||
public Response addPolicy(PolicyWrapper policyWrapper) {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
|
||||||
policy.setProfileId(policyWrapper.getProfileId());
|
|
||||||
policy.setDescription(policyWrapper.getDescription());
|
|
||||||
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
|
|
||||||
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
|
||||||
policy.setRoles(policyWrapper.getRoles());
|
|
||||||
policy.setUsers(policyWrapper.getUsers());
|
|
||||||
policy.setTenantId(policyWrapper.getTenantId());
|
|
||||||
policy.setCompliance(policyWrapper.getCompliance());
|
|
||||||
|
|
||||||
return addPolicy(policyManagementService, responseMsg, policy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("active-policy")
|
|
||||||
public Response addActivePolicy(PolicyWrapper policyWrapper) {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
|
||||||
policy.setProfileId(policyWrapper.getProfileId());
|
|
||||||
policy.setDescription(policyWrapper.getDescription());
|
|
||||||
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
|
|
||||||
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
|
||||||
policy.setRoles(policyWrapper.getRoles());
|
|
||||||
policy.setUsers(policyWrapper.getUsers());
|
|
||||||
policy.setTenantId(policyWrapper.getTenantId());
|
|
||||||
policy.setCompliance(policyWrapper.getCompliance());
|
|
||||||
policy.setActive(true);
|
|
||||||
|
|
||||||
return addPolicy(policyManagementService, responseMsg, policy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Response addPolicy(PolicyManagerService policyManagementService, ResponsePayload responseMsg,
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy) {
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
pap.addPolicy(policy);
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Policy has been added successfully.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getAllPolicies() {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
List<org.wso2.carbon.policy.mgt.common.Policy> policies;
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
|
||||||
policies = policyAdministratorPoint.getPolicies();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
|
||||||
responsePayload.setResponseContent(policies);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
@Path("{id}")
|
|
||||||
public Response getPolicy(@PathParam("id") int policyId) {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
final org.wso2.carbon.policy.mgt.common.Policy policy;
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
|
||||||
policy = policyAdministratorPoint.getPolicy(policyId);
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
if (policy == null){
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
|
||||||
responsePayload.setMessageFromServer("Policy for ID " + policyId + " not found.");
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
|
||||||
responsePayload.setResponseContent(policy);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("count")
|
|
||||||
public Response getPolicyCount() {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
|
||||||
Integer count = policyAdministratorPoint.getPolicyCount();
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("{id}")
|
|
||||||
public Response updatePolicy(PolicyWrapper policyWrapper, @PathParam("id") int policyId) {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
|
||||||
policy.setId(policyId);
|
|
||||||
policy.setProfileId(policyWrapper.getProfileId());
|
|
||||||
policy.setDescription(policyWrapper.getDescription());
|
|
||||||
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
|
|
||||||
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
|
||||||
policy.setRoles(policyWrapper.getRoles());
|
|
||||||
policy.setUsers(policyWrapper.getUsers());
|
|
||||||
policy.setTenantId(policyWrapper.getTenantId());
|
|
||||||
policy.setCompliance(policyWrapper.getCompliance());
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
pap.updatePolicy(policy);
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Policy has been updated successfully.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception in policy update.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("priorities")
|
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies) {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
List<org.wso2.carbon.policy.mgt.common.Policy> policiesToUpdate =
|
|
||||||
new ArrayList<>(priorityUpdatedPolicies.size());
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policyObj = new org.wso2.carbon.policy.mgt.common.Policy();
|
|
||||||
policyObj.setId(priorityUpdatedPolicies.get(i).getId());
|
|
||||||
policyObj.setPriorityId(priorityUpdatedPolicies.get(i).getPriority());
|
|
||||||
policiesToUpdate.add(policyObj);
|
|
||||||
}
|
|
||||||
boolean policiesUpdated;
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Exception in updating policy priorities.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
if (policiesUpdated) {
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Policy Priorities successfully updated.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer("Policy priorities did not update. Bad Request.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("bulk-remove")
|
|
||||||
@Consumes("application/json")
|
|
||||||
@Produces("application/json")
|
|
||||||
public Response bulkRemovePolicy(List<Integer> policyIds) {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
boolean policyDeleted = true;
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
for(int i : policyIds) {
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = pap.getPolicy(i);
|
|
||||||
if(!pap.deletePolicy(policy)){
|
|
||||||
policyDeleted = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Exception in deleting policies.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
if (policyDeleted) {
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Policies have been successfully deleted.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer("Policy does not exist.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
@Path("activate")
|
|
||||||
public Response activatePolicy(List<Integer> policyIds) {
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
for(int i : policyIds) {
|
|
||||||
pap.activatePolicy(i);
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Exception in activating policies.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Selected policies have been successfully activated.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
@Path("inactivate")
|
|
||||||
public Response inactivatePolicy(List<Integer> policyIds) throws MDMAPIException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
for(int i : policyIds) {
|
|
||||||
pap.inactivatePolicy(i);
|
|
||||||
}
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Exception in inactivating policies.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Selected policies have been successfully inactivated.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Produces("application/json")
|
|
||||||
@Path("apply-changes")
|
|
||||||
public Response applyChanges() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
pap.publishChanges();
|
|
||||||
|
|
||||||
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Exception in applying changes.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Changes have been successfully updated.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("start-task/{milliseconds}")
|
|
||||||
public Response startTaskService(@PathParam("milliseconds") int monitoringFrequency) {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
try {
|
|
||||||
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
|
||||||
taskScheduleService.startTask(monitoringFrequency);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
String msg = "Policy Management related exception.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Policy monitoring service started successfully.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("update-task/{milliseconds}")
|
|
||||||
public Response updateTaskService(@PathParam("milliseconds") int monitoringFrequency) {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
try {
|
|
||||||
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
|
||||||
taskScheduleService.updateTask(monitoringFrequency);
|
|
||||||
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
String msg = "Policy Management related exception.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Policy monitoring service updated successfully.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("stop-task")
|
|
||||||
public Response stopTaskService() {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
try {
|
|
||||||
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
|
||||||
taskScheduleService.stopTask();
|
|
||||||
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
String msg = "Policy Management related exception.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Policy monitoring service stopped successfully.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{type}/{id}")
|
|
||||||
public Response getComplianceDataOfDevice(@PathParam("type") String type, @PathParam("id") String id) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
ComplianceData complianceData = policyManagementService.getDeviceCompliance(deviceIdentifier);
|
|
||||||
return Response.status(Response.Status.OK).entity(complianceData).build();
|
|
||||||
} catch (PolicyComplianceException e) {
|
|
||||||
String msg = "Error occurred while getting the compliance data.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{type}/{id}/active-policy")
|
|
||||||
public Response getDeviceActivePolicy(@PathParam("type") String type,
|
|
||||||
@PathParam("id") String id) {
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = policyManagementService
|
|
||||||
.getAppliedPolicyToDevice(deviceIdentifier);
|
|
||||||
return Response.status(Response.Status.OK).entity(policy).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Error occurred while getting the current policy.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.mdm.api;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class Profile {
|
|
||||||
private static Log log = LogFactory.getLog(Profile.class);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
public Response addProfile(org.wso2.carbon.policy.mgt.common.Profile profile) {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
profile = pap.addProfile(profile);
|
|
||||||
return Response.status(Response.Status.OK).entity(profile).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@POST
|
|
||||||
@Path("{id}")
|
|
||||||
public Response updateProfile(org.wso2.carbon.policy.mgt.common.Profile profile,
|
|
||||||
@PathParam("id") String profileId) {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
pap.updateProfile(profile);
|
|
||||||
responseMsg.setMessageFromServer("Profile has been updated successfully.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@DELETE
|
|
||||||
@Path("{id}")
|
|
||||||
public Response deleteProfile(@PathParam("id") int profileId) {
|
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
org.wso2.carbon.policy.mgt.common.Profile profile = pap.getProfile(profileId);
|
|
||||||
pap.deleteProfile(profile);
|
|
||||||
responseMsg.setMessageFromServer("Profile has been deleted successfully.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String msg = "Policy Management related exception";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,440 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.CarbonConstants;
|
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.mdm.beans.RoleWrapper;
|
|
||||||
import org.wso2.carbon.mdm.util.SetReferenceTransformer;
|
|
||||||
import org.wso2.carbon.user.api.AuthorizationManager;
|
|
||||||
import org.wso2.carbon.user.api.Permission;
|
|
||||||
import org.wso2.carbon.user.api.UserRealm;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
|
||||||
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
|
||||||
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
|
||||||
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class Role {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Role.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user roles (except all internal roles) from system.
|
|
||||||
*
|
|
||||||
* @return A list of users
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getRoles() {
|
|
||||||
List<String> filteredRoles;
|
|
||||||
try {
|
|
||||||
filteredRoles = getRolesFromUserStore();
|
|
||||||
} catch (MDMAPIException e) {
|
|
||||||
log.error(e.getErrorMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
|
||||||
responsePayload.setResponseContent(filteredRoles);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user roles by user store(except all internal roles) from system.
|
|
||||||
*
|
|
||||||
* @return A list of users
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("{userStore}")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getRoles(@PathParam("userStore") String userStore) {
|
|
||||||
String[] roles;
|
|
||||||
try {
|
|
||||||
AbstractUserStoreManager abstractUserStoreManager =
|
|
||||||
(AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of user roles");
|
|
||||||
}
|
|
||||||
roles = abstractUserStoreManager.getRoleNames(userStore + "/*", -1, false, true, true);
|
|
||||||
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of user roles.";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
// removing all internal roles and roles created for Service-providers
|
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
|
||||||
for (String role : roles) {
|
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
|
||||||
filteredRoles.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
|
||||||
responsePayload.setResponseContent(filteredRoles);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user roles by providing a filtering criteria(except all internal roles & system roles) from system.
|
|
||||||
*
|
|
||||||
* @return A list of users
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("search")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getMatchingRoles(@QueryParam("filter") String filter) {
|
|
||||||
String[] roles;
|
|
||||||
try {
|
|
||||||
AbstractUserStoreManager abstractUserStoreManager =
|
|
||||||
(AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of user roles using filter : " + filter);
|
|
||||||
}
|
|
||||||
roles = abstractUserStoreManager.getRoleNames("*" + filter + "*", -1, true, true, true);
|
|
||||||
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of user roles using the filter : " + filter;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
// removing all internal roles and roles created for Service-providers
|
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
|
||||||
for (String role : roles) {
|
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
|
||||||
filteredRoles.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("All matching user roles were successfully retrieved.");
|
|
||||||
responsePayload.setResponseContent(filteredRoles);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get role permissions.
|
|
||||||
*
|
|
||||||
* @return list of permissions
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("permissions")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getPermissions(@QueryParam("rolename") String roleName) {
|
|
||||||
try {
|
|
||||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
|
||||||
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
|
||||||
final UIPermissionNode rolePermissions;
|
|
||||||
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
|
||||||
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
|
||||||
}
|
|
||||||
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
|
||||||
rolePermissions = getUIPermissionNode(roleName, userRealmProxy);
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("All permissions retrieved");
|
|
||||||
responsePayload.setResponseContent(rolePermissions);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
} catch (UserAdminException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the user role";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user role of the system
|
|
||||||
*
|
|
||||||
* @return user role
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("role")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getRole(@QueryParam("rolename") String roleName) {
|
|
||||||
RoleWrapper roleWrapper = new RoleWrapper();
|
|
||||||
try {
|
|
||||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
|
||||||
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
|
||||||
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
|
||||||
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of user roles");
|
|
||||||
}
|
|
||||||
if (userStoreManager.isExistingRole(roleName)) {
|
|
||||||
roleWrapper.setRoleName(roleName);
|
|
||||||
roleWrapper.setUsers(userStoreManager.getUserListOfRole(roleName));
|
|
||||||
// Get the permission nodes and hand picking only device management and login perms
|
|
||||||
final UIPermissionNode rolePermissions = getUIPermissionNode(roleName, userRealmProxy);
|
|
||||||
ArrayList<String> permList = new ArrayList<>();
|
|
||||||
iteratePermissions(rolePermissions, permList);
|
|
||||||
roleWrapper.setPermissionList(rolePermissions);
|
|
||||||
String[] permListAr = new String[permList.size()];
|
|
||||||
roleWrapper.setPermissions(permList.toArray(permListAr));
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | UserAdminException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the user role";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
|
||||||
responsePayload.setResponseContent(roleWrapper);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private UIPermissionNode getUIPermissionNode(String roleName, UserRealmProxy userRealmProxy)
|
|
||||||
throws UserAdminException {
|
|
||||||
final UIPermissionNode rolePermissions =
|
|
||||||
userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
|
||||||
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
|
||||||
|
|
||||||
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
|
||||||
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
|
||||||
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
|
||||||
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
|
||||||
deviceMgtPermissions[0] = node;
|
|
||||||
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
|
||||||
deviceMgtPermissions[1] = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rolePermissions.setNodeList(deviceMgtPermissions);
|
|
||||||
return rolePermissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API is used to persist a new Role
|
|
||||||
*
|
|
||||||
* @param roleWrapper for role
|
|
||||||
* @return response
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response addRole(RoleWrapper roleWrapper) {
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Persisting the role to user store");
|
|
||||||
}
|
|
||||||
Permission[] permissions = null;
|
|
||||||
if (roleWrapper.getPermissions() != null && roleWrapper.getPermissions().length > 0) {
|
|
||||||
permissions = new Permission[roleWrapper.getPermissions().length];
|
|
||||||
|
|
||||||
for (int i = 0; i < permissions.length; i++) {
|
|
||||||
String permission = roleWrapper.getPermissions()[i];
|
|
||||||
permissions[i] = new Permission(permission, CarbonConstants.UI_PERMISSION_ACTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userStoreManager.addRole(roleWrapper.getRoleName(), roleWrapper.getUsers(), permissions);
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = e.getMessage();
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API is used to update a role Role
|
|
||||||
*
|
|
||||||
* @param roleWrapper for role
|
|
||||||
* @return response
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response updateRole(@QueryParam("rolename") String roleName, RoleWrapper roleWrapper) {
|
|
||||||
String newRoleName = roleWrapper.getRoleName();
|
|
||||||
try {
|
|
||||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Updating the role to user store");
|
|
||||||
}
|
|
||||||
if (newRoleName != null && !roleName.equals(newRoleName)) {
|
|
||||||
userStoreManager.updateRoleName(roleName, newRoleName);
|
|
||||||
}
|
|
||||||
if (roleWrapper.getUsers() != null) {
|
|
||||||
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
|
||||||
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)),
|
|
||||||
Arrays.asList(roleWrapper.getUsers()));
|
|
||||||
final String[] usersToAdd = transformer.getObjectsToAdd().toArray(new String[transformer
|
|
||||||
.getObjectsToAdd().size()]);
|
|
||||||
final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer
|
|
||||||
.getObjectsToRemove().size()]);
|
|
||||||
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
|
|
||||||
}
|
|
||||||
if (roleWrapper.getPermissions() != null) {
|
|
||||||
// Delete all authorizations for the current role before authorizing the permission tree
|
|
||||||
authorizationManager.clearRoleAuthorization(roleName);
|
|
||||||
if (roleWrapper.getPermissions().length > 0) {
|
|
||||||
for (int i = 0; i < roleWrapper.getPermissions().length; i++) {
|
|
||||||
String permission = roleWrapper.getPermissions()[i];
|
|
||||||
authorizationManager.authorizeRole(roleName, permission, CarbonConstants.UI_PERMISSION_ACTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = e.getMessage();
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API is used to delete a role and authorizations
|
|
||||||
*
|
|
||||||
* @param roleName to delete
|
|
||||||
* @return response
|
|
||||||
*/
|
|
||||||
@DELETE
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response deleteRole(@QueryParam("rolename") String roleName) {
|
|
||||||
try {
|
|
||||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Deleting the role in user store");
|
|
||||||
}
|
|
||||||
userStoreManager.deleteRole(roleName);
|
|
||||||
// Delete all authorizations for the current role before deleting
|
|
||||||
authorizationManager.clearRoleAuthorization(roleName);
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while deleting the role: " + roleName;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API is used to update users of a role
|
|
||||||
*
|
|
||||||
* @param roleName to update
|
|
||||||
* @param userList of the users
|
|
||||||
* @return response
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path("users")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response updateUsers(@QueryParam("rolename") String roleName, List<String> userList) {
|
|
||||||
try {
|
|
||||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Updating the users of a role");
|
|
||||||
}
|
|
||||||
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
|
||||||
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(roleName)),
|
|
||||||
userList);
|
|
||||||
final String[] usersToAdd = transformer.getObjectsToAdd().toArray(new String[transformer
|
|
||||||
.getObjectsToAdd().size()]);
|
|
||||||
final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer
|
|
||||||
.getObjectsToRemove().size()]);
|
|
||||||
|
|
||||||
userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd);
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while saving the users of the role: " + roleName;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<String> iteratePermissions(UIPermissionNode uiPermissionNode, ArrayList<String> list) {
|
|
||||||
for (UIPermissionNode permissionNode : uiPermissionNode.getNodeList()) {
|
|
||||||
list.add(permissionNode.getResourcePath());
|
|
||||||
if (permissionNode.getNodeList() != null && permissionNode.getNodeList().length > 0) {
|
|
||||||
iteratePermissions(permissionNode, list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to retrieve the role count of the system.
|
|
||||||
*
|
|
||||||
* @return returns the count.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("count")
|
|
||||||
public Response getRoleCount() {
|
|
||||||
try {
|
|
||||||
List<String> filteredRoles = getRolesFromUserStore();
|
|
||||||
Integer count = filteredRoles.size();
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (MDMAPIException e) {
|
|
||||||
log.error(e.getErrorMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getRolesFromUserStore() throws MDMAPIException {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
String[] roles;
|
|
||||||
try {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of user roles");
|
|
||||||
}
|
|
||||||
roles = userStoreManager.getRoleNames();
|
|
||||||
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of user roles.";
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
}
|
|
||||||
// removing all internal roles and roles created for Service-providers
|
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
|
||||||
for (String role : roles) {
|
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
|
||||||
filteredRoles.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredRoles;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,757 +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.api;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.api.util.CredentialManagementResponseBuilder;
|
|
||||||
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.mdm.beans.UserCredentialWrapper;
|
|
||||||
import org.wso2.carbon.mdm.beans.UserWrapper;
|
|
||||||
import org.wso2.carbon.mdm.util.Constants;
|
|
||||||
import org.wso2.carbon.mdm.util.SetReferenceTransformer;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents the JAX-RS services of User related functionality.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class User {
|
|
||||||
|
|
||||||
private static final String ROLE_EVERYONE = "Internal/everyone";
|
|
||||||
private static Log log = LogFactory.getLog(User.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to add user to emm-user-store.
|
|
||||||
*
|
|
||||||
* @param userWrapper Wrapper object representing input json payload
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response addUser(UserWrapper userWrapper) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
|
||||||
// if user already exists
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + userWrapper.getUsername() +
|
|
||||||
" already exists. Therefore, request made to add user was refused.");
|
|
||||||
}
|
|
||||||
// returning response with bad request state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CONFLICT);
|
|
||||||
responsePayload.
|
|
||||||
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
|
||||||
" already exists. Therefore, request made to add user was refused.");
|
|
||||||
return Response.status(Response.Status.CONFLICT).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
String initialUserPassword = generateInitialUserPassword();
|
|
||||||
Map<String, String> defaultUserClaims =
|
|
||||||
buildDefaultUserClaims(userWrapper.getFirstname(), userWrapper.getLastname(),
|
|
||||||
userWrapper.getEmailAddress());
|
|
||||||
// calling addUser method of carbon user api
|
|
||||||
userStoreManager.addUser(userWrapper.getUsername(), initialUserPassword,
|
|
||||||
userWrapper.getRoles(), defaultUserClaims, null);
|
|
||||||
// invite newly added user to enroll device
|
|
||||||
inviteNewlyAddedUserToEnrollDevice(userWrapper.getUsername(), initialUserPassword);
|
|
||||||
// Outputting debug message upon successful addition of user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + userWrapper.getUsername() + " was successfully added.");
|
|
||||||
}
|
|
||||||
// returning response with success state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
|
||||||
" was successfully added.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Exception in trying to add user by username: " + userWrapper.getUsername();
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to get user information from emm-user-store.
|
|
||||||
*
|
|
||||||
* @param username User-name of the user
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("view")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getUser(@QueryParam("username") String username) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (userStoreManager.isExistingUser(username)) {
|
|
||||||
UserWrapper user = new UserWrapper();
|
|
||||||
user.setUsername(username);
|
|
||||||
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
|
||||||
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
||||||
// Outputting debug message upon successful retrieval of user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + username + " was found.");
|
|
||||||
}
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("User information was retrieved successfully.");
|
|
||||||
responsePayload.setResponseContent(user);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
// Outputting debug message upon trying to remove non-existing user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + username + " does not exist.");
|
|
||||||
}
|
|
||||||
// returning response with bad request state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer(
|
|
||||||
"User by username: " + username + " does not exist.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Exception in trying to retrieve user by username: " + username;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update user in user store
|
|
||||||
*
|
|
||||||
* @param userWrapper Wrapper object representing input json payload
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response updateUser(UserWrapper userWrapper, @QueryParam("username") String username) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
|
||||||
Map<String, String> defaultUserClaims =
|
|
||||||
buildDefaultUserClaims(userWrapper.getFirstname(), userWrapper.getLastname(),
|
|
||||||
userWrapper.getEmailAddress());
|
|
||||||
if (StringUtils.isNotEmpty(userWrapper.getPassword())) {
|
|
||||||
// Decoding Base64 encoded password
|
|
||||||
byte[] decodedBytes = Base64.decodeBase64(userWrapper.getPassword());
|
|
||||||
userStoreManager.updateCredentialByAdmin(userWrapper.getUsername(),
|
|
||||||
new String(decodedBytes, "UTF-8"));
|
|
||||||
log.debug("User credential of username: " + userWrapper.getUsername() + " has been changed");
|
|
||||||
}
|
|
||||||
List<String> listofFilteredRoles = getFilteredRoles(userStoreManager, userWrapper.getUsername());
|
|
||||||
final String[] existingRoles = listofFilteredRoles.toArray(new String[listofFilteredRoles.size()]);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Use the Set theory to find the roles to delete and roles to add
|
|
||||||
The difference of roles in existingRolesSet and newRolesSet needed to be deleted
|
|
||||||
new roles to add = newRolesSet - The intersection of roles in existingRolesSet and newRolesSet
|
|
||||||
*/
|
|
||||||
final TreeSet<String> existingRolesSet = new TreeSet<>();
|
|
||||||
Collections.addAll(existingRolesSet, existingRoles);
|
|
||||||
final TreeSet<String> newRolesSet = new TreeSet<>();
|
|
||||||
Collections.addAll(newRolesSet, userWrapper.getRoles());
|
|
||||||
existingRolesSet.removeAll(newRolesSet);
|
|
||||||
// Now we have the roles to delete
|
|
||||||
String[] rolesToDelete = existingRolesSet.toArray(new String[existingRolesSet.size()]);
|
|
||||||
List<String> roles = new ArrayList<>(Arrays.asList(rolesToDelete));
|
|
||||||
roles.remove(ROLE_EVERYONE);
|
|
||||||
rolesToDelete = new String[0];
|
|
||||||
// Clearing and re-initializing the set
|
|
||||||
existingRolesSet.clear();
|
|
||||||
Collections.addAll(existingRolesSet, existingRoles);
|
|
||||||
newRolesSet.removeAll(existingRolesSet);
|
|
||||||
// Now we have the roles to add
|
|
||||||
String[] rolesToAdd = newRolesSet.toArray(new String[newRolesSet.size()]);
|
|
||||||
userStoreManager.updateRoleListOfUser(userWrapper.getUsername(), rolesToDelete, rolesToAdd);
|
|
||||||
userStoreManager.setUserClaimValues(userWrapper.getUsername(), defaultUserClaims, null);
|
|
||||||
// Outputting debug message upon successful addition of user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + userWrapper.getUsername() + " was successfully updated.");
|
|
||||||
}
|
|
||||||
// returning response with success state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
|
||||||
" was successfully updated.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + userWrapper.getUsername() +
|
|
||||||
" doesn't exists. Therefore, request made to update user was refused.");
|
|
||||||
}
|
|
||||||
// returning response with bad request state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CONFLICT);
|
|
||||||
responsePayload.
|
|
||||||
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
|
||||||
" doesn't exists. Therefore, request made to update user was refused.");
|
|
||||||
return Response.status(Response.Status.CONFLICT).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | UnsupportedEncodingException | MDMAPIException e) {
|
|
||||||
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private method to be used by addUser() to
|
|
||||||
* generate an initial user password for a user.
|
|
||||||
* This will be the password used by a user for his initial login to the system.
|
|
||||||
*
|
|
||||||
* @return {string} Initial User Password
|
|
||||||
*/
|
|
||||||
private String generateInitialUserPassword() {
|
|
||||||
int passwordLength = 6;
|
|
||||||
//defining the pool of characters to be used for initial password generation
|
|
||||||
String lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz";
|
|
||||||
String upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
||||||
String numericCharset = "0123456789";
|
|
||||||
Random randomGenerator = new Random();
|
|
||||||
String totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset;
|
|
||||||
int totalCharsetLength = totalCharset.length();
|
|
||||||
StringBuilder initialUserPassword = new StringBuilder();
|
|
||||||
for (int i = 0; i < passwordLength; i++) {
|
|
||||||
initialUserPassword
|
|
||||||
.append(totalCharset.charAt(randomGenerator.nextInt(totalCharsetLength)));
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Initial user password is created for new user: " + initialUserPassword);
|
|
||||||
}
|
|
||||||
return initialUserPassword.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to build default user claims.
|
|
||||||
*
|
|
||||||
* @param firstname First name of the user
|
|
||||||
* @param lastname Last name of the user
|
|
||||||
* @param emailAddress Email address of the user
|
|
||||||
* @return {Object} Default user claims to be provided
|
|
||||||
*/
|
|
||||||
private Map<String, String> buildDefaultUserClaims(String firstname, String lastname, String emailAddress) {
|
|
||||||
Map<String, String> defaultUserClaims = new HashMap<>();
|
|
||||||
defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstname);
|
|
||||||
defaultUserClaims.put(Constants.USER_CLAIM_LAST_NAME, lastname);
|
|
||||||
defaultUserClaims.put(Constants.USER_CLAIM_EMAIL_ADDRESS, emailAddress);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Default claim map is created for new user: " + defaultUserClaims.toString());
|
|
||||||
}
|
|
||||||
return defaultUserClaims;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to remove user from emm-user-store.
|
|
||||||
*
|
|
||||||
* @param username Username of the user
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
|
||||||
*/
|
|
||||||
@DELETE
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response removeUser(@QueryParam("username") String username) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (userStoreManager.isExistingUser(username)) {
|
|
||||||
// if user already exists, trying to remove user
|
|
||||||
userStoreManager.deleteUser(username);
|
|
||||||
// Outputting debug message upon successful removal of user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + username + " was successfully removed.");
|
|
||||||
}
|
|
||||||
// returning response with success state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer(
|
|
||||||
"User by username: " + username + " was successfully removed.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
// Outputting debug message upon trying to remove non-existing user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + username + " does not exist for removal.");
|
|
||||||
}
|
|
||||||
// returning response with bad request state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer(
|
|
||||||
"User by username: " + username + " does not exist for removal.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Exception in trying to remove user by username: " + username;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get all the roles except for the internal/xxx and application/xxx
|
|
||||||
*
|
|
||||||
* @param userStoreManager User Store Manager associated with the currently logged in user
|
|
||||||
* @param username Username of the currently logged in user
|
|
||||||
* @return the list of filtered roles
|
|
||||||
*/
|
|
||||||
private List<String> getFilteredRoles(UserStoreManager userStoreManager, String username) {
|
|
||||||
String[] roleListOfUser = new String[0];
|
|
||||||
try {
|
|
||||||
roleListOfUser = userStoreManager.getRoleListOfUser(username);
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
|
||||||
for (String role : roleListOfUser) {
|
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
|
||||||
filteredRoles.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user's roles by username
|
|
||||||
*
|
|
||||||
* @param username Username of the user
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("roles")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getRoles(@QueryParam("username") String username) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (userStoreManager.isExistingUser(username)) {
|
|
||||||
responsePayload.setResponseContent(Collections.singletonList(getFilteredRoles(userStoreManager, username)));
|
|
||||||
// Outputting debug message upon successful removal of user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + username + " was successfully removed.");
|
|
||||||
}
|
|
||||||
// returning response with success state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer(
|
|
||||||
"User roles obtained for user " + username);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
} else {
|
|
||||||
// Outputting debug message upon trying to remove non-existing user
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("User by username: " + username + " does not exist for role retrieval.");
|
|
||||||
}
|
|
||||||
// returning response with bad request state
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer(
|
|
||||||
"User by username: " + username + " does not exist for role retrieval.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Exception in trying to retrieve roles for user by username: " + username;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of all users with all user-related info.
|
|
||||||
*
|
|
||||||
* @return A list of users
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getAllUsers() {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of users with all user-related information");
|
|
||||||
}
|
|
||||||
List<UserWrapper> userList;
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
String[] users = userStoreManager.listUsers("*", -1);
|
|
||||||
userList = new ArrayList<>(users.length);
|
|
||||||
UserWrapper user;
|
|
||||||
for (String username : users) {
|
|
||||||
user = new UserWrapper();
|
|
||||||
user.setUsername(username);
|
|
||||||
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
|
||||||
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
||||||
userList.add(user);
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of users";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
int count;
|
|
||||||
count = userList.size();
|
|
||||||
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
|
||||||
"Obtained user count: " + count);
|
|
||||||
responsePayload.setResponseContent(userList);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of all users with all user-related info.
|
|
||||||
*
|
|
||||||
* @return A list of users
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("{filter}")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response getMatchingUsers(@PathParam("filter") String filter) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of users with all user-related information using the filter : " + filter);
|
|
||||||
}
|
|
||||||
List<UserWrapper> userList;
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
String[] users = userStoreManager.listUsers(filter + "*", -1);
|
|
||||||
userList = new ArrayList<>(users.length);
|
|
||||||
UserWrapper user;
|
|
||||||
for (String username : users) {
|
|
||||||
user = new UserWrapper();
|
|
||||||
user.setUsername(username);
|
|
||||||
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
|
||||||
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
||||||
userList.add(user);
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
int count;
|
|
||||||
count = userList.size();
|
|
||||||
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
|
||||||
"Obtained user count: " + count);
|
|
||||||
responsePayload.setResponseContent(userList);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of user names in the system.
|
|
||||||
*
|
|
||||||
* @return A list of user names.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("view-users")
|
|
||||||
public Response getAllUsersByUsername(@QueryParam("username") String userName) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of users by name");
|
|
||||||
}
|
|
||||||
List<UserWrapper> userList;
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
|
||||||
userList = new ArrayList<>(users.length);
|
|
||||||
UserWrapper user;
|
|
||||||
for (String username : users) {
|
|
||||||
user = new UserWrapper();
|
|
||||||
user.setUsername(username);
|
|
||||||
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
|
||||||
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
||||||
userList.add(user);
|
|
||||||
}
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of users";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
int count;
|
|
||||||
count = userList.size();
|
|
||||||
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
|
||||||
"Obtained user count: " + count);
|
|
||||||
responsePayload.setResponseContent(userList);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of user names in the system.
|
|
||||||
*
|
|
||||||
* @return A list of user names.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("users-by-username")
|
|
||||||
public Response getAllUserNamesByUsername(@QueryParam("username") String userName) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the list of users by name");
|
|
||||||
}
|
|
||||||
List<String> userList;
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
|
||||||
userList = new ArrayList<>(users.length);
|
|
||||||
Collections.addAll(userList, users);
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of users";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
int count;
|
|
||||||
count = userList.size();
|
|
||||||
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
|
||||||
"Obtained user count: " + count);
|
|
||||||
responsePayload.setResponseContent(userList);
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a claim-value from user-store.
|
|
||||||
*
|
|
||||||
* @param username Username of the user
|
|
||||||
* @param claimUri required ClaimUri
|
|
||||||
* @return claim value
|
|
||||||
*/
|
|
||||||
private String getClaimValue(String username, String claimUri) throws MDMAPIException {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
try {
|
|
||||||
return userStoreManager.getUserClaimValue(username, claimUri, null);
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
throw new MDMAPIException("Error occurred while retrieving value assigned to the claim '" +
|
|
||||||
claimUri + "'", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method used to send an invitation email to a new user to enroll a device.
|
|
||||||
*
|
|
||||||
* @param username Username of the user
|
|
||||||
*/
|
|
||||||
private void inviteNewlyAddedUserToEnrollDevice(String username, String password) throws MDMAPIException {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Sending invitation mail to user by username: " + username);
|
|
||||||
}
|
|
||||||
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
||||||
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
|
|
||||||
tenantDomain = "";
|
|
||||||
}
|
|
||||||
if (!username.contains("/")) {
|
|
||||||
username = "/" + username;
|
|
||||||
}
|
|
||||||
String[] usernameBits = username.split("/");
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.setProperty("username", usernameBits[1]);
|
|
||||||
props.setProperty("domain-name", tenantDomain);
|
|
||||||
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
||||||
props.setProperty("password", password);
|
|
||||||
|
|
||||||
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
|
||||||
|
|
||||||
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
|
||||||
try {
|
|
||||||
deviceManagementProviderService.sendRegistrationEmail(metaInfo);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Error occurred while sending registration email to user '" + username + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method used to send an invitation email to a existing user to enroll a device.
|
|
||||||
*
|
|
||||||
* @param usernames Username list of the users to be invited
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("email-invitation")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response inviteExistingUsersToEnrollDevice(List<String> usernames) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Sending enrollment invitation mail to existing user.");
|
|
||||||
}
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
try {
|
|
||||||
for (String username : usernames) {
|
|
||||||
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
||||||
props.setProperty("username", username);
|
|
||||||
|
|
||||||
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
|
||||||
deviceManagementProviderService.sendEnrolmentInvitation(metaInfo);
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while inviting user to enrol their device";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("Email invitation was successfully sent to user.");
|
|
||||||
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of devices based on the username.
|
|
||||||
*
|
|
||||||
* @param username Username of the device owner
|
|
||||||
* @return A list of devices
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
@Path("devices")
|
|
||||||
public Response getAllDeviceOfUser(@QueryParam("username") String username, @QueryParam("start") int startIdx,
|
|
||||||
@QueryParam("length") int length) {
|
|
||||||
DeviceManagementProviderService dmService;
|
|
||||||
try {
|
|
||||||
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
if (length > 0) {
|
|
||||||
PaginationRequest request = new PaginationRequest(startIdx, length);
|
|
||||||
request.setOwner(username);
|
|
||||||
return Response.status(Response.Status.OK).entity(dmService.getDevicesOfUser(request)).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(dmService.getDevicesOfUser(username)).build();
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Device management error";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to retrieve the user count of the system.
|
|
||||||
*
|
|
||||||
* @return returns the count.
|
|
||||||
* @
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("count")
|
|
||||||
public Response getUserCount() {
|
|
||||||
try {
|
|
||||||
String[] users = DeviceMgtAPIUtils.getUserStoreManager().listUsers("*", -1);
|
|
||||||
Integer count = 0;
|
|
||||||
if (users != null) {
|
|
||||||
count = users.length;
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(count).build();
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg =
|
|
||||||
"Error occurred while retrieving the list of users that exist within the current tenant";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API is used to update roles of a user
|
|
||||||
*
|
|
||||||
* @param username
|
|
||||||
* @param userList
|
|
||||||
* @return
|
|
||||||
* @
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path("{roleName}/users")
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response updateRoles(@PathParam("username") String username, List<String> userList) {
|
|
||||||
try {
|
|
||||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Updating the roles of a user");
|
|
||||||
}
|
|
||||||
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
|
||||||
transformer.transform(Arrays.asList(userStoreManager.getRoleListOfUser(username)),
|
|
||||||
userList);
|
|
||||||
final String[] rolesToAdd = transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
|
||||||
final String[] rolesToDelete = transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
|
||||||
|
|
||||||
userStoreManager.updateRoleListOfUser(username, rolesToDelete, rolesToAdd);
|
|
||||||
} catch (UserStoreException | MDMAPIException e) {
|
|
||||||
String msg = "Error occurred while saving the roles for user: " + username;
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to change the user password.
|
|
||||||
*
|
|
||||||
* @param credentials Wrapper object representing user credentials.
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
|
||||||
* @
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("change-password")
|
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response resetPassword(UserCredentialWrapper credentials) {
|
|
||||||
return CredentialManagementResponseBuilder.buildChangePasswordResponse(credentials);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to change the user password.
|
|
||||||
*
|
|
||||||
* @param credentials Wrapper object representing user credentials.
|
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
|
||||||
* @
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("reset-password")
|
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
|
||||||
public Response resetPasswordByAdmin(UserCredentialWrapper credentials) {
|
|
||||||
return CredentialManagementResponseBuilder.buildResetPasswordResponse(credentials);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.api.common;
|
|
||||||
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
|
||||||
|
|
||||||
@Produces({ "application/json", "application/xml" })
|
|
||||||
public class ErrorHandler implements ExceptionMapper<MDMAPIException> {
|
|
||||||
|
|
||||||
public Response toResponse(MDMAPIException exception) {
|
|
||||||
ErrorMessage errorMessage = new ErrorMessage();
|
|
||||||
errorMessage.setErrorMessage(exception.getErrorMessage());
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.api.common;
|
|
||||||
|
|
||||||
|
|
||||||
public class ErrorMessage {
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
private String errorCode;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorCode() {
|
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorCode(String errorCode) {
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.api.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom exception class for handling CDM API related exceptions.
|
|
||||||
*/
|
|
||||||
public class MDMAPIException extends Exception {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7950151650447893900L;
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MDMAPIException(String msg, Exception e) {
|
|
||||||
super(msg, e);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MDMAPIException(String msg, Throwable cause) {
|
|
||||||
super(msg, cause);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MDMAPIException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MDMAPIException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MDMAPIException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.api.context;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model object of DeviceOperation.
|
|
||||||
*/
|
|
||||||
@XmlRootElement
|
|
||||||
public class DeviceOperationContext {
|
|
||||||
|
|
||||||
private List<DeviceIdentifier> devices;
|
|
||||||
private Operation operation;
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public List<DeviceIdentifier> getDevices() {
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDevices(List<DeviceIdentifier> devices) {
|
|
||||||
this.devices = devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public Operation getOperation() {
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperation(Operation operation) {
|
|
||||||
this.operation = operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,106 +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.api.util;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.beans.UserCredentialWrapper;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class builds Credential modification related Responses
|
|
||||||
*/
|
|
||||||
public class CredentialManagementResponseBuilder {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(CredentialManagementResponseBuilder.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds the response to change the password of a user
|
|
||||||
* @param credentials - User credentials
|
|
||||||
* @return Response Object
|
|
||||||
*/
|
|
||||||
public static Response buildChangePasswordResponse(UserCredentialWrapper credentials) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
|
||||||
byte[] decodedOldPassword = Base64.decodeBase64(credentials.getOldPassword());
|
|
||||||
userStoreManager.updateCredential(credentials.getUsername(), new String(
|
|
||||||
decodedNewPassword, "UTF-8"), new String(decodedOldPassword, "UTF-8"));
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
|
||||||
" was successfully changed.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer("Old password does not match.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
|
||||||
". The Character Encoding is not supported.";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build();
|
|
||||||
} catch (MDMAPIException e) {
|
|
||||||
log.error(e.getErrorMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds the response to reset the password of a user
|
|
||||||
* @param credentials - User credentials
|
|
||||||
* @return Response Object
|
|
||||||
*/
|
|
||||||
public static Response buildResetPasswordResponse(UserCredentialWrapper credentials) {
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
try {
|
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
||||||
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
|
||||||
userStoreManager.updateCredentialByAdmin(credentials.getUsername(), new String(
|
|
||||||
decodedNewPassword, "UTF-8"));
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
|
||||||
" was successfully changed.");
|
|
||||||
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
|
||||||
responsePayload.setMessageFromServer("Could not change the password.");
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
|
||||||
". The Character Encoding is not supported.";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build();
|
|
||||||
} catch (MDMAPIException e) {
|
|
||||||
log.error(e.getErrorMessage(), e);
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,322 +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.api.util;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
||||||
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.configuration.mgt.TenantConfigurationManagementService;
|
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
|
||||||
import org.wso2.carbon.user.api.AuthorizationManager;
|
|
||||||
import org.wso2.carbon.user.api.UserRealm;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MDMAPIUtils class provides utility function used by CDM REST-API classes.
|
|
||||||
*/
|
|
||||||
public class DeviceMgtAPIUtils {
|
|
||||||
|
|
||||||
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON_TYPE;
|
|
||||||
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
|
||||||
private static Log log = LogFactory.getLog(DeviceMgtAPIUtils.class);
|
|
||||||
|
|
||||||
public static int getNotifierFrequency(TenantConfiguration tenantConfiguration) {
|
|
||||||
List<ConfigurationEntry> configEntryList = tenantConfiguration.getConfiguration();
|
|
||||||
if (configEntryList != null && !configEntryList.isEmpty()) {
|
|
||||||
for(ConfigurationEntry entry : configEntryList) {
|
|
||||||
if (NOTIFIER_FREQUENCY.equals(entry.getName())) {
|
|
||||||
return Integer.parseInt((String) entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void scheduleTaskService(int notifierFrequency) {
|
|
||||||
TaskScheduleService taskScheduleService;
|
|
||||||
try {
|
|
||||||
taskScheduleService = getPolicyManagementService().getTaskScheduleService();
|
|
||||||
if (taskScheduleService.isTaskScheduled()) {
|
|
||||||
taskScheduleService.updateTask(notifierFrequency);
|
|
||||||
} else {
|
|
||||||
taskScheduleService.startTask(notifierFrequency);
|
|
||||||
}
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
|
||||||
log.error("Exception occurred while starting the Task service.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService =
|
|
||||||
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
|
||||||
if (deviceManagementProviderService == null) {
|
|
||||||
String msg = "Device Management provider service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return deviceManagementProviderService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GroupManagementProviderService getGroupManagementProviderService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
GroupManagementProviderService groupManagementProviderService =
|
|
||||||
(GroupManagementProviderService) ctx.getOSGiService(GroupManagementProviderService.class, null);
|
|
||||||
if (groupManagementProviderService == null) {
|
|
||||||
String msg = "Group Management service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return groupManagementProviderService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTenantId(String tenantDomain) throws MDMAPIException {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
try {
|
|
||||||
return realmService.getTenantManager().getTenantId(tenantDomain);
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
throw new MDMAPIException(
|
|
||||||
"Error obtaining tenant id from tenant domain " + tenantDomain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UserStoreManager getUserStoreManager() throws MDMAPIException {
|
|
||||||
RealmService realmService;
|
|
||||||
UserStoreManager userStoreManager;
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
|
||||||
String msg = "Realm service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
int tenantId = ctx.getTenantId();
|
|
||||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
}
|
|
||||||
return userStoreManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getting the current tenant's user realm
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
|
||||||
public static UserRealm getUserRealm() throws MDMAPIException {
|
|
||||||
RealmService realmService;
|
|
||||||
UserRealm realm;
|
|
||||||
try {
|
|
||||||
//PrivilegedCarbonContext.startTenantFlow();
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
//ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
||||||
//ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
|
|
||||||
if (realmService == null) {
|
|
||||||
String msg = "Realm service not initialized";
|
|
||||||
log.error(msg);
|
|
||||||
throw new MDMAPIException(msg);
|
|
||||||
}
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
realm = realmService.getTenantUserRealm(tenantId);
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving current user realm";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
} finally {
|
|
||||||
//PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
return realm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AuthorizationManager getAuthorizationManager() throws MDMAPIException {
|
|
||||||
RealmService realmService;
|
|
||||||
AuthorizationManager authorizationManager;
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
|
||||||
String msg = "Realm service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
int tenantId = ctx.getTenantId();
|
|
||||||
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving current Authorization manager.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
}
|
|
||||||
return authorizationManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to get the current tenant id.
|
|
||||||
*
|
|
||||||
* @return returns the tenant id.
|
|
||||||
*/
|
|
||||||
public static int getTenantId() {
|
|
||||||
return CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DeviceIdentifier instantiateDeviceIdentifier(String deviceType, String deviceId) {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(deviceType);
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
return deviceIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApplicationManagementProviderService getAppManagementService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
ApplicationManagementProviderService applicationManagementProviderService =
|
|
||||||
(ApplicationManagementProviderService) ctx.getOSGiService(ApplicationManagementProviderService.class, null);
|
|
||||||
if (applicationManagementProviderService == null) {
|
|
||||||
String msg = "Application management service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return applicationManagementProviderService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PolicyManagerService getPolicyManagementService() {
|
|
||||||
PolicyManagerService policyManagementService;
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
policyManagementService =
|
|
||||||
(PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null);
|
|
||||||
if (policyManagementService == null) {
|
|
||||||
String msg = "Policy Management service not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return policyManagementService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TenantConfigurationManagementService getTenantConfigurationManagementService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
TenantConfigurationManagementService tenantConfigurationManagementService =
|
|
||||||
(TenantConfigurationManagementService) ctx.getOSGiService(TenantConfigurationManagementService.class, null);
|
|
||||||
if (tenantConfigurationManagementService == null) {
|
|
||||||
String msg = "Tenant configuration Management service not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return tenantConfigurationManagementService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NotificationManagementService getNotificationManagementService() {
|
|
||||||
NotificationManagementService notificationManagementService;
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
notificationManagementService = (NotificationManagementService) ctx.getOSGiService(
|
|
||||||
NotificationManagementService.class, null);
|
|
||||||
if (notificationManagementService == null) {
|
|
||||||
String msg = "Notification Management service not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return notificationManagementService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PaginationResult getPagingResponse(int recordsTotal, int recordsFiltered, int draw, List<?> data) {
|
|
||||||
PaginationResult pagingResponse = new PaginationResult();
|
|
||||||
pagingResponse.setRecordsTotal(recordsTotal);
|
|
||||||
pagingResponse.setRecordsFiltered(recordsFiltered);
|
|
||||||
pagingResponse.setDraw(draw);
|
|
||||||
pagingResponse.setData(data);
|
|
||||||
return pagingResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CertificateManagementService getCertificateManagementService() {
|
|
||||||
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
CertificateManagementService certificateManagementService = (CertificateManagementService)
|
|
||||||
ctx.getOSGiService(CertificateManagementService.class, null);
|
|
||||||
|
|
||||||
if (certificateManagementService == null) {
|
|
||||||
String msg = "Certificate Management service not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return certificateManagementService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static MediaType getResponseMediaType(String acceptHeader) {
|
|
||||||
MediaType responseMediaType;
|
|
||||||
if (acceptHeader == null || MediaType.WILDCARD.equals(acceptHeader)) {
|
|
||||||
responseMediaType = DEFAULT_CONTENT_TYPE;
|
|
||||||
} else {
|
|
||||||
responseMediaType = MediaType.valueOf(acceptHeader);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseMediaType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DeviceInformationManager getDeviceInformationManagerService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
DeviceInformationManager deviceInformationManager =
|
|
||||||
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
|
||||||
if (deviceInformationManager == null) {
|
|
||||||
String msg = "Device information Manager service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return deviceInformationManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static SearchManagerService getSearchManagerService() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
SearchManagerService searchManagerService =
|
|
||||||
(SearchManagerService) ctx.getOSGiService(SearchManagerService.class, null);
|
|
||||||
if (searchManagerService == null) {
|
|
||||||
String msg = "Device search manager service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return searchManagerService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.api.util;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.beans.MobileApp;
|
|
||||||
import org.wso2.carbon.mdm.beans.android.WebApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* This class contains the all the operations related to Android.
|
|
||||||
*/
|
|
||||||
public class MDMAndroidOperationUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to create Install Application operation.
|
|
||||||
*
|
|
||||||
* @param application MobileApp application
|
|
||||||
* @return operation
|
|
||||||
* @throws MDMAPIException
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static Operation createInstallAppOperation(MobileApp application) throws MDMAPIException {
|
|
||||||
|
|
||||||
ProfileOperation operation = new ProfileOperation();
|
|
||||||
operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION);
|
|
||||||
operation.setType(Operation.Type.PROFILE);
|
|
||||||
|
|
||||||
switch (application.getType()) {
|
|
||||||
case ENTERPRISE:
|
|
||||||
org.wso2.carbon.mdm.beans.android.EnterpriseApplication enterpriseApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.android.EnterpriseApplication();
|
|
||||||
enterpriseApplication.setType(application.getType().toString());
|
|
||||||
enterpriseApplication.setUrl(application.getLocation());
|
|
||||||
operation.setPayLoad(enterpriseApplication.toJSON());
|
|
||||||
break;
|
|
||||||
case PUBLIC:
|
|
||||||
org.wso2.carbon.mdm.beans.android.AppStoreApplication appStoreApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.android.AppStoreApplication();
|
|
||||||
appStoreApplication.setType(application.getType().toString());
|
|
||||||
appStoreApplication.setAppIdentifier(application.getIdentifier());
|
|
||||||
operation.setPayLoad(appStoreApplication.toJSON());
|
|
||||||
break;
|
|
||||||
case WEBAPP:
|
|
||||||
WebApplication webApplication = new WebApplication();
|
|
||||||
webApplication.setUrl(application.getLocation());
|
|
||||||
webApplication.setName(application.getName());
|
|
||||||
webApplication.setType(application.getType().toString());
|
|
||||||
operation.setPayLoad(webApplication.toJSON());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String errorMessage = "Invalid application type.";
|
|
||||||
throw new MDMAPIException(errorMessage);
|
|
||||||
}
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to create Uninstall Application operation.
|
|
||||||
* @param application MobileApp application
|
|
||||||
* @return operation
|
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
|
||||||
public static Operation createAppUninstallOperation(MobileApp application) throws MDMAPIException {
|
|
||||||
|
|
||||||
ProfileOperation operation = new ProfileOperation();
|
|
||||||
operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION);
|
|
||||||
operation.setType(Operation.Type.PROFILE);
|
|
||||||
|
|
||||||
switch (application.getType()) {
|
|
||||||
case ENTERPRISE:
|
|
||||||
org.wso2.carbon.mdm.beans.android.EnterpriseApplication enterpriseApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.android.EnterpriseApplication();
|
|
||||||
enterpriseApplication.setType(application.getType().toString());
|
|
||||||
enterpriseApplication.setAppIdentifier(application.getAppIdentifier());
|
|
||||||
operation.setPayLoad(enterpriseApplication.toJSON());
|
|
||||||
break;
|
|
||||||
case PUBLIC:
|
|
||||||
org.wso2.carbon.mdm.beans.android.AppStoreApplication appStoreApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.android.AppStoreApplication();
|
|
||||||
appStoreApplication.setType(application.getType().toString());
|
|
||||||
appStoreApplication.setAppIdentifier(application.getAppIdentifier());
|
|
||||||
operation.setPayLoad(appStoreApplication.toJSON());
|
|
||||||
break;
|
|
||||||
case WEBAPP:
|
|
||||||
WebApplication webApplication = new WebApplication();
|
|
||||||
webApplication.setUrl(application.getLocation());
|
|
||||||
webApplication.setName(application.getName());
|
|
||||||
webApplication.setType(application.getType().toString());
|
|
||||||
operation.setPayLoad(webApplication.toJSON());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String errorMessage = "Invalid application type.";
|
|
||||||
throw new MDMAPIException(errorMessage);
|
|
||||||
}
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Licensed 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.api.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class holds all the constants used for IOS and Android.
|
|
||||||
*/
|
|
||||||
public class MDMAppConstants {
|
|
||||||
|
|
||||||
public class IOSConstants {
|
|
||||||
|
|
||||||
private IOSConstants() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
public static final String IS_REMOVE_APP = "isRemoveApp";
|
|
||||||
public static final String IS_PREVENT_BACKUP = "isPreventBackup";
|
|
||||||
public static final String I_TUNES_ID = "iTunesId";
|
|
||||||
public static final String LABEL = "label";
|
|
||||||
public static final String OPCODE_INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
|
|
||||||
public static final String OPCODE_INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION";
|
|
||||||
public static final String OPCODE_INSTALL_WEB_APPLICATION = "WEB_CLIP";
|
|
||||||
public static final String OPCODE_REMOVE_APPLICATION = "REMOVE_APPLICATION";
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AndroidConstants {
|
|
||||||
|
|
||||||
private AndroidConstants() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION";
|
|
||||||
public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION";
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RegistryConstants {
|
|
||||||
|
|
||||||
private RegistryConstants() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
public static final String GENERAL_CONFIG_RESOURCE_PATH = "general";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Licensed 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.api.util;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import org.wso2.carbon.mdm.beans.MobileApp;
|
|
||||||
import org.wso2.carbon.mdm.beans.ios.WebClip;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains the all the operations related to IOS.
|
|
||||||
*/
|
|
||||||
public class MDMIOSOperationUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to create Install Application operation.
|
|
||||||
*
|
|
||||||
* @param application MobileApp application
|
|
||||||
* @return operation
|
|
||||||
* @throws MDMAPIException
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static Operation createInstallAppOperation(MobileApp application) throws MDMAPIException {
|
|
||||||
|
|
||||||
ProfileOperation operation = new ProfileOperation();
|
|
||||||
|
|
||||||
switch (application.getType()) {
|
|
||||||
case ENTERPRISE:
|
|
||||||
org.wso2.carbon.mdm.beans.ios.EnterpriseApplication enterpriseApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.ios.EnterpriseApplication();
|
|
||||||
enterpriseApplication.setBundleId(application.getId());
|
|
||||||
enterpriseApplication.setIdentifier(application.getIdentifier());
|
|
||||||
enterpriseApplication.setManifestURL(application.getLocation());
|
|
||||||
|
|
||||||
Properties properties = application.getProperties();
|
|
||||||
enterpriseApplication.setPreventBackupOfAppData((Boolean) properties.
|
|
||||||
get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP));
|
|
||||||
enterpriseApplication.setRemoveAppUponMDMProfileRemoval((Boolean) properties.
|
|
||||||
get(MDMAppConstants.IOSConstants.IS_REMOVE_APP));
|
|
||||||
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_ENTERPRISE_APPLICATION);
|
|
||||||
operation.setPayLoad(enterpriseApplication.toJSON());
|
|
||||||
operation.setType(Operation.Type.COMMAND);
|
|
||||||
break;
|
|
||||||
case PUBLIC:
|
|
||||||
org.wso2.carbon.mdm.beans.ios.AppStoreApplication appStoreApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.ios.AppStoreApplication();
|
|
||||||
appStoreApplication.setRemoveAppUponMDMProfileRemoval((Boolean) application.getProperties().
|
|
||||||
get(MDMAppConstants.IOSConstants.IS_REMOVE_APP));
|
|
||||||
appStoreApplication.setIdentifier(application.getIdentifier());
|
|
||||||
appStoreApplication.setPreventBackupOfAppData((Boolean) application.getProperties().
|
|
||||||
get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP));
|
|
||||||
appStoreApplication.setBundleId(application.getId());
|
|
||||||
appStoreApplication.setiTunesStoreID((Integer) application.getProperties().
|
|
||||||
get(MDMAppConstants.IOSConstants.I_TUNES_ID));
|
|
||||||
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_STORE_APPLICATION);
|
|
||||||
operation.setType(Operation.Type.COMMAND);
|
|
||||||
operation.setPayLoad(appStoreApplication.toJSON());
|
|
||||||
break;
|
|
||||||
case WEBAPP:
|
|
||||||
WebClip webClip = new WebClip();
|
|
||||||
webClip.setIcon(application.getIconImage());
|
|
||||||
webClip.setIsRemovable(application.getProperties().
|
|
||||||
getProperty(MDMAppConstants.IOSConstants.IS_REMOVE_APP));
|
|
||||||
webClip.setLabel(application.getProperties().
|
|
||||||
getProperty(MDMAppConstants.IOSConstants.LABEL));
|
|
||||||
webClip.setURL(application.getLocation());
|
|
||||||
|
|
||||||
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_WEB_APPLICATION);
|
|
||||||
operation.setType(Operation.Type.PROFILE);
|
|
||||||
operation.setPayLoad(webClip.toJSON());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Operation createAppUninstallOperation(MobileApp application) throws MDMAPIException{
|
|
||||||
|
|
||||||
ProfileOperation operation = new ProfileOperation();
|
|
||||||
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_REMOVE_APPLICATION);
|
|
||||||
operation.setType(Operation.Type.PROFILE);
|
|
||||||
|
|
||||||
org.wso2.carbon.mdm.beans.ios.RemoveApplication removeApplication =
|
|
||||||
new org.wso2.carbon.mdm.beans.ios.RemoveApplication();
|
|
||||||
removeApplication.setBundleId(application.getIdentifier());
|
|
||||||
operation.setPayLoad(removeApplication.toJSON());
|
|
||||||
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.api.util;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class ResponsePayload {
|
|
||||||
|
|
||||||
private int statusCode;
|
|
||||||
private String messageFromServer;
|
|
||||||
private Object responseContent;
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public int getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusCode(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public String getMessageFromServer() {
|
|
||||||
return messageFromServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageFromServer(String messageFromServer) {
|
|
||||||
this.messageFromServer = messageFromServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public Object getResponseContent() {
|
|
||||||
return responseContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseContent(Object responseContent) {
|
|
||||||
this.responseContent = responseContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResponsePayloadBuilder getBuilder() {
|
|
||||||
return new ResponsePayloadBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResponsePayloadBuilder statusCode(int statusCode) {
|
|
||||||
ResponsePayload message = new ResponsePayload();
|
|
||||||
return message.getBuilder().statusCode(statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
|
||||||
ResponsePayload message = new ResponsePayload();
|
|
||||||
return message.getBuilder().messageFromServer(messageFromServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResponsePayloadBuilder responseContent(String responseContent) {
|
|
||||||
ResponsePayload message = new ResponsePayload();
|
|
||||||
return message.getBuilder().responseContent(responseContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ResponsePayloadBuilder {
|
|
||||||
|
|
||||||
private int statusCode;
|
|
||||||
private String messageFromServer;
|
|
||||||
private Object responseContent;
|
|
||||||
|
|
||||||
public ResponsePayloadBuilder statusCode(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
|
||||||
this.messageFromServer = messageFromServer;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponsePayloadBuilder responseContent(String responseContent) {
|
|
||||||
this.responseContent = responseContent;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponsePayload build() {
|
|
||||||
ResponsePayload payload = new ResponsePayload();
|
|
||||||
payload.setStatusCode(statusCode);
|
|
||||||
payload.setMessageFromServer(messageFromServer);
|
|
||||||
payload.setResponseContent(responseContent);
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ApplicationWrapper {
|
|
||||||
|
|
||||||
private List<String> userNameList;
|
|
||||||
private List<String> roleNameList;
|
|
||||||
private List<DeviceIdentifier> deviceIdentifiers;
|
|
||||||
private MobileApp application;
|
|
||||||
|
|
||||||
public MobileApp getApplication() {
|
|
||||||
return application;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplication(MobileApp application) {
|
|
||||||
this.application = application;
|
|
||||||
}
|
|
||||||
public List<String> getUserNameList() {
|
|
||||||
return userNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserNameList(List<String> userNameList) {
|
|
||||||
this.userNameList = userNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getRoleNameList() {
|
|
||||||
return roleNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoleNameList(List<String> roleNameList) {
|
|
||||||
this.roleNameList = roleNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DeviceIdentifier> getDeviceIdentifiers() {
|
|
||||||
return deviceIdentifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
|
|
||||||
this.deviceIdentifiers = deviceIdentifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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.beans;
|
|
||||||
|
|
||||||
public class EnrollmentCertificate {
|
|
||||||
String serial;
|
|
||||||
String pem;
|
|
||||||
int tenantId;
|
|
||||||
|
|
||||||
public int getTenantId() {
|
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenantId(int tenantId) {
|
|
||||||
this.tenantId = tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSerial() {
|
|
||||||
return serial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSerial(String serial) {
|
|
||||||
this.serial = serial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPem() {
|
|
||||||
return pem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPem(String pem) {
|
|
||||||
this.pem = pem;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents the generic mobile Application information
|
|
||||||
* which is used by AppM.
|
|
||||||
*/
|
|
||||||
public class MobileApp {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
private MobileAppTypes type;
|
|
||||||
private String platform;
|
|
||||||
private String version;
|
|
||||||
private String identifier;
|
|
||||||
private String iconImage;
|
|
||||||
private String packageName;
|
|
||||||
private String appIdentifier;
|
|
||||||
private String location;
|
|
||||||
private Properties properties;
|
|
||||||
|
|
||||||
public MobileAppTypes getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(MobileAppTypes type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlatform() {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlatform(String platform) {
|
|
||||||
this.platform = platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdentifier() {
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdentifier(String identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIconImage() {
|
|
||||||
return iconImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIconImage(String iconImage) {
|
|
||||||
this.iconImage = iconImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPackageName() {
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPackageName(String packageName) {
|
|
||||||
this.packageName = packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppIdentifier() {
|
|
||||||
return appIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppIdentifier(String appIdentifier) {
|
|
||||||
this.appIdentifier = appIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocation(String location) {
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Properties getProperties() {
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProperties(Properties properties) {
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
public enum MobileAppTypes {
|
|
||||||
ENTERPRISE,WEBAPP,PUBLIC
|
|
||||||
}
|
|
||||||
@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PolicyWrapper {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private Profile profile;
|
|
||||||
private String policyName;
|
|
||||||
private String description;
|
|
||||||
private String compliance;
|
|
||||||
private List<String> roles;
|
|
||||||
private String ownershipType;
|
|
||||||
private List<Device> devices;
|
|
||||||
private List<String> users;
|
|
||||||
private int tenantId;
|
|
||||||
private int profileId;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Profile getProfile() {
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfile(Profile profile) {
|
|
||||||
this.profile = profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCompliance() {
|
|
||||||
return compliance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCompliance(String compliance) {
|
|
||||||
this.compliance = compliance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPolicyName() {
|
|
||||||
return policyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPolicyName(String policyName) {
|
|
||||||
this.policyName = policyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getRoles() {
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoles(List<String> roles) {
|
|
||||||
this.roles = roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwnershipType() {
|
|
||||||
return ownershipType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwnershipType(String ownershipType) {
|
|
||||||
this.ownershipType = ownershipType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Device> getDevices() {
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDevices(List<Device> devices) {
|
|
||||||
this.devices = devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getUsers() {
|
|
||||||
return users;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsers(List<String> users) {
|
|
||||||
this.users = users;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTenantId() {
|
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenantId(int tenantId) {
|
|
||||||
this.tenantId = tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getProfileId() {
|
|
||||||
return profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfileId(int profileId) {
|
|
||||||
this.profileId = profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
public class PriorityUpdatedPolicyWrapper {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private int priority;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPriority(int priority) {
|
|
||||||
this.priority = priority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class Profile {
|
|
||||||
|
|
||||||
private int profileId;
|
|
||||||
private String profileName;
|
|
||||||
private int tenantId;
|
|
||||||
private DeviceType deviceType;
|
|
||||||
private Timestamp createdDate;
|
|
||||||
private Timestamp updatedDate;
|
|
||||||
private List<ProfileFeature> profileFeaturesList; // Features included in the policies.
|
|
||||||
|
|
||||||
public DeviceType getDeviceType() {
|
|
||||||
return deviceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceType(DeviceType deviceType) {
|
|
||||||
this.deviceType = deviceType;
|
|
||||||
}
|
|
||||||
@XmlElement
|
|
||||||
public int getTenantId() {
|
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenantId(int tenantId) {
|
|
||||||
this.tenantId = tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* public List<Feature> getFeaturesList() {
|
|
||||||
return featuresList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFeaturesList(List<Feature> featuresList) {
|
|
||||||
this.featuresList = featuresList;
|
|
||||||
}*/
|
|
||||||
@XmlElement
|
|
||||||
public int getProfileId() {
|
|
||||||
return profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfileId(int profileId) {
|
|
||||||
this.profileId = profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public String getProfileName() {
|
|
||||||
return profileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfileName(String profileName) {
|
|
||||||
this.profileName = profileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public Timestamp getCreatedDate() {
|
|
||||||
return createdDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedDate(Timestamp createdDate) {
|
|
||||||
this.createdDate = createdDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public Timestamp getUpdatedDate() {
|
|
||||||
return updatedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdatedDate(Timestamp updatedDate) {
|
|
||||||
this.updatedDate = updatedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public List<ProfileFeature> getProfileFeaturesList() {
|
|
||||||
return profileFeaturesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfileFeaturesList(List<ProfileFeature> profileFeaturesList) {
|
|
||||||
this.profileFeaturesList = profileFeaturesList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
|
|
||||||
public class ProfileFeature implements Serializable {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String featureCode;
|
|
||||||
private int profileId;
|
|
||||||
private int deviceTypeId;
|
|
||||||
private Object content;
|
|
||||||
private String payLoad;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFeatureCode() {
|
|
||||||
return featureCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFeatureCode(String featureCode) {
|
|
||||||
this.featureCode = featureCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getProfileId() {
|
|
||||||
return profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfileId(int profileId) {
|
|
||||||
this.profileId = profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDeviceTypeId() {
|
|
||||||
return deviceTypeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceTypeId(int deviceTypeId) {
|
|
||||||
this.deviceTypeId = deviceTypeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getPayLoad() {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
this.payLoad = gson.toJson(content);
|
|
||||||
return payLoad;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayLoad(String payLoad) {
|
|
||||||
this.payLoad = payLoad;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Object getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(Object content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
package org.wso2.carbon.mdm.beans;
|
|
||||||
|
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
public class RoleWrapper {
|
|
||||||
private String roleName;
|
|
||||||
private String[] permissions;
|
|
||||||
private String[] users;
|
|
||||||
private UIPermissionNode permissionList;
|
|
||||||
|
|
||||||
public String getRoleName() {
|
|
||||||
return roleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoleName(String roleName) {
|
|
||||||
this.roleName = roleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getPermissions() {
|
|
||||||
return permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissions(String[] permissions) {
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getUsers() {
|
|
||||||
return users;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsers(String[] users) {
|
|
||||||
this.users = users;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UIPermissionNode getPermissionList() {
|
|
||||||
return permissionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissionList(UIPermissionNode permissionList) {
|
|
||||||
this.permissionList = permissionList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans;
|
|
||||||
|
|
||||||
public class UserCredentialWrapper {
|
|
||||||
|
|
||||||
private String username;
|
|
||||||
/*
|
|
||||||
Base64 encoded password
|
|
||||||
*/
|
|
||||||
private String oldPassword;
|
|
||||||
private String newPassword;
|
|
||||||
|
|
||||||
public String getNewPassword() {
|
|
||||||
return newPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNewPassword(String newPassword) {
|
|
||||||
this.newPassword = newPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOldPassword() {
|
|
||||||
return oldPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOldPassword(String oldPassword) {
|
|
||||||
this.oldPassword = oldPassword;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.beans;
|
|
||||||
|
|
||||||
public class UserWrapper {
|
|
||||||
|
|
||||||
private String username;
|
|
||||||
/*
|
|
||||||
Base64 encoded password
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
private String firstname;
|
|
||||||
private String lastname;
|
|
||||||
private String emailAddress;
|
|
||||||
private String[] roles;
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFirstname() {
|
|
||||||
return firstname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstname(String firstname) {
|
|
||||||
this.firstname = firstname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastname() {
|
|
||||||
return lastname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastname(String lastname) {
|
|
||||||
this.lastname = lastname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmailAddress() {
|
|
||||||
return emailAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmailAddress(String emailAddress) {
|
|
||||||
this.emailAddress = emailAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Giving a clone of the array since arrays are mutable
|
|
||||||
*/
|
|
||||||
public String[] getRoles() {
|
|
||||||
String[] copiedRoles = roles;
|
|
||||||
if (roles != null){
|
|
||||||
copiedRoles = roles.clone();
|
|
||||||
}
|
|
||||||
return copiedRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoles(String[] roles) {
|
|
||||||
this.roles = roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Licensed 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.beans.android;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents the Appstore Application information.
|
|
||||||
*/
|
|
||||||
public class AppStoreApplication implements Serializable {
|
|
||||||
|
|
||||||
private String type;
|
|
||||||
private String appIdentifier;
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppIdentifier() {
|
|
||||||
return appIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppIdentifier(String appIdentifier) {
|
|
||||||
this.appIdentifier = appIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Licensed 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.beans.android;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents the Enterprise Application information.
|
|
||||||
*/
|
|
||||||
public class EnterpriseApplication implements Serializable {
|
|
||||||
|
|
||||||
private String type;
|
|
||||||
private String url;
|
|
||||||
private String appIdentifier;
|
|
||||||
|
|
||||||
public String getAppIdentifier() {
|
|
||||||
return appIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppIdentifier(String appIdentifier) {
|
|
||||||
this.appIdentifier = appIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Licensed 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.beans.android;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents the Web Application information.
|
|
||||||
*/
|
|
||||||
public class WebApplication implements Serializable {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String url;
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans.ios;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class AppStoreApplication implements Serializable {
|
|
||||||
|
|
||||||
private String identifier;
|
|
||||||
private int iTunesStoreID;
|
|
||||||
private boolean removeAppUponMDMProfileRemoval;
|
|
||||||
private boolean preventBackupOfAppData;
|
|
||||||
private String bundleId;
|
|
||||||
private String UUID;
|
|
||||||
|
|
||||||
public String getUUID() {
|
|
||||||
return UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUUID(String UUID) {
|
|
||||||
this.UUID = UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdentifier() {
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdentifier(String identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getiTunesStoreID() {
|
|
||||||
return iTunesStoreID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setiTunesStoreID(int iTunesStoreID) {
|
|
||||||
this.iTunesStoreID = iTunesStoreID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRemoveAppUponMDMProfileRemoval() {
|
|
||||||
return removeAppUponMDMProfileRemoval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) {
|
|
||||||
this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPreventBackupOfAppData() {
|
|
||||||
return preventBackupOfAppData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPreventBackupOfAppData(boolean preventBackupOfAppData) {
|
|
||||||
this.preventBackupOfAppData = preventBackupOfAppData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBundleId() {
|
|
||||||
return bundleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBundleId(String bundleId) {
|
|
||||||
this.bundleId = bundleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.beans.ios;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class EnterpriseApplication implements Serializable {
|
|
||||||
|
|
||||||
private String identifier;
|
|
||||||
private String manifestURL;
|
|
||||||
private boolean removeAppUponMDMProfileRemoval;
|
|
||||||
private boolean preventBackupOfAppData;
|
|
||||||
private String bundleId;
|
|
||||||
private String UUID;
|
|
||||||
|
|
||||||
public void setUUID(String UUID) {
|
|
||||||
this.UUID = UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdentifier() {
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdentifier(String identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getManifestURL() {
|
|
||||||
return manifestURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setManifestURL(String manifestURL) {
|
|
||||||
this.manifestURL = manifestURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRemoveAppUponMDMProfileRemoval() {
|
|
||||||
return removeAppUponMDMProfileRemoval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) {
|
|
||||||
this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPreventBackupOfAppData() {
|
|
||||||
return preventBackupOfAppData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPreventBackupOfAppData(boolean preventBackupOfAppData) {
|
|
||||||
this.preventBackupOfAppData = preventBackupOfAppData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBundleId() {
|
|
||||||
return bundleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBundleId(String bundleId) {
|
|
||||||
this.bundleId = bundleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
package org.wso2.carbon.mdm.beans.ios;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class RemoveApplication implements Serializable {
|
|
||||||
|
|
||||||
private String bundleId;
|
|
||||||
|
|
||||||
public String getBundleId() {
|
|
||||||
return bundleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBundleId(String bundleId) {
|
|
||||||
this.bundleId = bundleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
package org.wso2.carbon.mdm.beans.ios;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class WebClip {
|
|
||||||
|
|
||||||
private String URL;
|
|
||||||
private String label;
|
|
||||||
private String icon;
|
|
||||||
private String isRemovable;
|
|
||||||
private String UUID;
|
|
||||||
|
|
||||||
public String getUUID() {
|
|
||||||
return UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUUID(String UUID) {
|
|
||||||
this.UUID = UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getURL() {
|
|
||||||
return URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setURL(String URL) {
|
|
||||||
this.URL = URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIcon() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIcon(String icon) {
|
|
||||||
this.icon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIsRemovable() {
|
|
||||||
return isRemovable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsRemovable(String isRemovable) {
|
|
||||||
this.isRemovable = isRemovable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() throws MDMAPIException {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.toJson(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,31 +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.exception;
|
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
public class BadRequestException extends WebApplicationException {
|
|
||||||
|
|
||||||
public BadRequestException(Message message, MediaType mediaType) {
|
|
||||||
super(Response.status(Response.Status.BAD_REQUEST).entity(message).type(mediaType).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,41 +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.exception;
|
|
||||||
|
|
||||||
public class Message {
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
private String discription;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDiscription() {
|
|
||||||
return discription;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDiscription(String discription) {
|
|
||||||
this.discription = discription;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds the constants used by MDM-Admin web application.
|
|
||||||
*/
|
|
||||||
public class Constants {
|
|
||||||
|
|
||||||
public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress";
|
|
||||||
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
|
|
||||||
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.mdm.util;
|
|
||||||
|
|
||||||
import org.wso2.carbon.mdm.beans.ProfileFeature;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MDMUtil {
|
|
||||||
|
|
||||||
public static Profile convertProfile(org.wso2.carbon.mdm.beans.Profile mdmProfile) {
|
|
||||||
Profile profile = new Profile();
|
|
||||||
profile.setTenantId(mdmProfile.getTenantId());
|
|
||||||
profile.setCreatedDate(mdmProfile.getCreatedDate());
|
|
||||||
profile.setDeviceType(mdmProfile.getDeviceType());
|
|
||||||
|
|
||||||
List<org.wso2.carbon.policy.mgt.common.ProfileFeature> profileFeatures =
|
|
||||||
new ArrayList<org.wso2.carbon.policy.
|
|
||||||
mgt.common.ProfileFeature>(mdmProfile.getProfileFeaturesList().size());
|
|
||||||
for (ProfileFeature mdmProfileFeature : mdmProfile.getProfileFeaturesList()) {
|
|
||||||
profileFeatures.add(convertProfileFeature(mdmProfileFeature));
|
|
||||||
}
|
|
||||||
profile.setProfileFeaturesList(profileFeatures);
|
|
||||||
profile.setProfileId(mdmProfile.getProfileId());
|
|
||||||
profile.setProfileName(mdmProfile.getProfileName());
|
|
||||||
profile.setUpdatedDate(mdmProfile.getUpdatedDate());
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static org.wso2.carbon.policy.mgt.common.ProfileFeature convertProfileFeature(ProfileFeature
|
|
||||||
mdmProfileFeature) {
|
|
||||||
|
|
||||||
org.wso2.carbon.policy.mgt.common.ProfileFeature profileFeature =
|
|
||||||
new org.wso2.carbon.policy.mgt.common.ProfileFeature();
|
|
||||||
profileFeature.setProfileId(mdmProfileFeature.getProfileId());
|
|
||||||
profileFeature.setContent(mdmProfileFeature.getPayLoad());
|
|
||||||
profileFeature.setDeviceTypeId(mdmProfileFeature.getDeviceTypeId());
|
|
||||||
profileFeature.setFeatureCode(mdmProfileFeature.getFeatureCode());
|
|
||||||
profileFeature.setId(mdmProfileFeature.getId());
|
|
||||||
return profileFeature;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
public class SetReferenceTransformer<T>{
|
|
||||||
private List<T> objectsToRemove;
|
|
||||||
private List<T> objectsToAdd;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use the Set theory to find the objects to delete and objects to add
|
|
||||||
|
|
||||||
The difference of objects in existingSet and newSet needed to be deleted
|
|
||||||
|
|
||||||
new roles to add = newSet - The intersection of roles in existingSet and newSet
|
|
||||||
* @param currentList
|
|
||||||
* @param nextList
|
|
||||||
*/
|
|
||||||
public void transform(List<T> currentList, List<T> nextList){
|
|
||||||
TreeSet<T> existingSet = new TreeSet<T>(currentList);
|
|
||||||
TreeSet<T> newSet = new TreeSet<T>(nextList);
|
|
||||||
|
|
||||||
existingSet.removeAll(newSet);
|
|
||||||
|
|
||||||
objectsToRemove = new ArrayList<T>(existingSet);
|
|
||||||
|
|
||||||
// Clearing and re-initializing the set
|
|
||||||
existingSet = new TreeSet<T>(currentList);
|
|
||||||
|
|
||||||
newSet.removeAll(existingSet);
|
|
||||||
objectsToAdd = new ArrayList<T>(newSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> getObjectsToRemove() {
|
|
||||||
return objectsToRemove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> getObjectsToAdd() {
|
|
||||||
return objectsToAdd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,119 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* 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.mdm.common;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Application {
|
|
||||||
|
|
||||||
private String applicationName;
|
|
||||||
private String appId;
|
|
||||||
private String locationUrl;
|
|
||||||
private String imageUrl;
|
|
||||||
private String platform;
|
|
||||||
private String version;
|
|
||||||
private List<String> userNameList;
|
|
||||||
private List<String> roleNameList;
|
|
||||||
|
|
||||||
public List<DeviceIdentifier> getDeviceIdentifiers() {
|
|
||||||
return deviceIdentifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
|
|
||||||
this.deviceIdentifiers = deviceIdentifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<DeviceIdentifier> deviceIdentifiers;
|
|
||||||
|
|
||||||
|
|
||||||
public String getApplicationName() {
|
|
||||||
return applicationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicationName(String applicationName) {
|
|
||||||
this.applicationName = applicationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getAppId() {
|
|
||||||
return appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppId(String appId) {
|
|
||||||
this.appId = appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getLocationUrl() {
|
|
||||||
return locationUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationUrl(String locationUrl) {
|
|
||||||
this.locationUrl = locationUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getImageUrl() {
|
|
||||||
return imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImageUrl(String imageUrl) {
|
|
||||||
this.imageUrl = imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getPlatform() {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlatform(String platform) {
|
|
||||||
this.platform = platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<String> getUserNameList() {
|
|
||||||
return userNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserNameList(List<String> userNameList) {
|
|
||||||
this.userNameList = userNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<String> getRoleNameList() {
|
|
||||||
return roleNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoleNameList(List<String> roleNameList) {
|
|
||||||
this.roleNameList = roleNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.mdm.common;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.MultivaluedMap;
|
|
||||||
import javax.ws.rs.ext.MessageBodyReader;
|
|
||||||
import javax.ws.rs.ext.MessageBodyWriter;
|
|
||||||
import javax.ws.rs.ext.Provider;
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
@Produces(APPLICATION_JSON)
|
|
||||||
@Consumes(APPLICATION_JSON)
|
|
||||||
public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> {
|
|
||||||
|
|
||||||
private Gson gson;
|
|
||||||
private static final String UTF_8 = "UTF-8";
|
|
||||||
|
|
||||||
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Gson getGson() {
|
|
||||||
if (gson == null) {
|
|
||||||
final GsonBuilder gsonBuilder = new GsonBuilder();
|
|
||||||
gson = gsonBuilder.create();
|
|
||||||
}
|
|
||||||
return gson;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
|
|
||||||
MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream entityStream)
|
|
||||||
throws IOException, WebApplicationException {
|
|
||||||
|
|
||||||
InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8");
|
|
||||||
|
|
||||||
try {
|
|
||||||
return getGson().fromJson(reader, type);
|
|
||||||
} finally {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSize(Object o, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(Object object, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
|
|
||||||
MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream entityStream)
|
|
||||||
throws IOException, WebApplicationException {
|
|
||||||
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
|
|
||||||
try {
|
|
||||||
Type jsonType = null;
|
|
||||||
if (type.equals(type)) {
|
|
||||||
jsonType = type;
|
|
||||||
}
|
|
||||||
getGson().toJson(object, jsonType, writer);
|
|
||||||
} finally {
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,35 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
|
||||||
-->
|
|
||||||
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
|
||||||
|
|
||||||
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
|
||||||
<ParentFirst>false</ParentFirst>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
|
||||||
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
|
||||||
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
|
||||||
-->
|
|
||||||
<Environments>CXF,Carbon</Environments>
|
|
||||||
</Classloading>
|
|
||||||
@ -1,188 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
|
||||||
xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xsi:schemaLocation="
|
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
|
||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
|
||||||
|
|
||||||
<jaxrs:server id="operationService" address="/operations">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="operationServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="featureService" address="/features">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="featureServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="deviceService" address="/devices">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="deviceServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="deviceGroupService" address="/groups">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="groupServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="userService" address="/users">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="userServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="roleService" address="/roles">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="roleServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="policyService" address="/policies">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="policyServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="profileService" address="/profiles">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="profileServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="configurationService" address="/configuration">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="configurationServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="licenseService" address="/license">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="licenseServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="certificateService" address="/certificates">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="certificateServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<jaxrs:server id="notificationService" address="/notifications">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="notificationServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
|
|
||||||
<jaxrs:server id="informationService" address="/information">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="informationServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
|
|
||||||
<jaxrs:server id="searchService" address="/search">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="searchingServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
<!--
|
|
||||||
<jaxrs:server id="authenticationService" address="/authentication">
|
|
||||||
<jaxrs:serviceBeans>
|
|
||||||
<ref bean="authenticationServiceBean"/>
|
|
||||||
</jaxrs:serviceBeans>
|
|
||||||
<jaxrs:providers>
|
|
||||||
<ref bean="jsonProvider"/>
|
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
|
||||||
</jaxrs:server>
|
|
||||||
-->
|
|
||||||
<bean id="operationServiceBean" class="org.wso2.carbon.mdm.api.Operation"/>
|
|
||||||
<bean id="deviceServiceBean" class="org.wso2.carbon.mdm.api.Device"/>
|
|
||||||
<bean id="groupServiceBean" class="org.wso2.carbon.mdm.api.Group"/>
|
|
||||||
<bean id="userServiceBean" class="org.wso2.carbon.mdm.api.User"/>
|
|
||||||
<bean id="roleServiceBean" class="org.wso2.carbon.mdm.api.Role"/>
|
|
||||||
<bean id="featureServiceBean" class="org.wso2.carbon.mdm.api.Feature"/>
|
|
||||||
<bean id="configurationServiceBean" class="org.wso2.carbon.mdm.api.Configuration"/>
|
|
||||||
<bean id="notificationServiceBean" class="org.wso2.carbon.mdm.api.DeviceNotification"/>
|
|
||||||
<bean id="licenseServiceBean" class="org.wso2.carbon.mdm.api.License"/>
|
|
||||||
<bean id="certificateServiceBean" class="org.wso2.carbon.mdm.api.Certificate"/>
|
|
||||||
|
|
||||||
|
|
||||||
<bean id="informationServiceBean" class="org.wso2.carbon.mdm.api.DeviceInformation"/>
|
|
||||||
<bean id="searchingServiceBean" class="org.wso2.carbon.mdm.api.DeviceSearch"/>
|
|
||||||
<!--
|
|
||||||
<bean id="authenticationServiceBean" class="org.wso2.carbon.mdm.api.Authentication"/>
|
|
||||||
-->
|
|
||||||
<bean id="policyServiceBean" class="org.wso2.carbon.mdm.api.Policy"/>
|
|
||||||
<bean id="profileServiceBean" class="org.wso2.carbon.mdm.api.Profile"/>
|
|
||||||
<bean id="jsonProvider" class="org.wso2.mdm.common.GsonMessageBodyHandler"/>
|
|
||||||
<bean id="errorHandler" class="org.wso2.carbon.mdm.api.common.ErrorHandler"/>
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
|
||||||
<display-name>Admin-Webapp</display-name>
|
|
||||||
<servlet>
|
|
||||||
<description>JAX-WS/JAX-RS MDM Endpoint</description>
|
|
||||||
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<servlet-class>
|
|
||||||
org.apache.cxf.transport.servlet.CXFServlet
|
|
||||||
</servlet-class>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
<session-config>
|
|
||||||
<session-timeout>60</session-timeout>
|
|
||||||
</session-config>
|
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>isAdminService</param-name>
|
|
||||||
<param-value>false</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>doAuthentication</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<!--context-param>
|
|
||||||
<param-name>managed-api-enabled</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-owner</param-name>
|
|
||||||
<param-value>admin</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-version</param-name>
|
|
||||||
<param-value>1.0.0</param-value>
|
|
||||||
</context-param>
|
|
||||||
<context-param>
|
|
||||||
<param-name>managed-api-isSecured</param-name>
|
|
||||||
<param-value>true</param-value>
|
|
||||||
</context-param-->
|
|
||||||
|
|
||||||
<!-- Below configuration is used to redirect http requests to https -->
|
|
||||||
<security-constraint>
|
|
||||||
<web-resource-collection>
|
|
||||||
<web-resource-name>MDM-Admin</web-resource-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</web-resource-collection>
|
|
||||||
<user-data-constraint>
|
|
||||||
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
|
|
||||||
</user-data-constraint>
|
|
||||||
</security-constraint>
|
|
||||||
|
|
||||||
</web-app>
|
|
||||||
@ -272,12 +272,18 @@ public class AndroidFeatureManager implements FeatureManager {
|
|||||||
feature.setDescription("Reboot the device");
|
feature.setDescription("Reboot the device");
|
||||||
supportedFeatures.add(feature);
|
supportedFeatures.add(feature);
|
||||||
|
|
||||||
feature = new Feature();
|
feature = new Feature();
|
||||||
feature.setCode("UPGRADE_FIRMWARE");
|
feature.setCode("UPGRADE_FIRMWARE");
|
||||||
feature.setName("Upgrade Firmware");
|
feature.setName("Upgrade Firmware");
|
||||||
feature.setDescription("Upgrade Firmware");
|
feature.setDescription("Upgrade Firmware");
|
||||||
supportedFeatures.add(feature);
|
supportedFeatures.add(feature);
|
||||||
|
|
||||||
|
feature = new Feature();
|
||||||
|
feature.setCode("VPN");
|
||||||
|
feature.setName("Configure VPN");
|
||||||
|
feature.setDescription("Configure VPN settings");
|
||||||
|
supportedFeatures.add(feature);
|
||||||
|
|
||||||
return supportedFeatures;
|
return supportedFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user