Merge branch 'master' of https://github.com/wso2/carbon-device-mgt-plugins into carbon-kernel-4.4.7

revert-dabc3590
mharindu 8 years ago
commit 0d3cd0c9e1

@ -12,15 +12,15 @@ public class Event {
private String deviceId;
private String type;
private int battery;
private double gps[]; //lat,long
private float accelerometer[]; //x,y,z
private float magnetic[]; //x,y,z
private float gyroscope[]; //x,y,z
private double gps[] = new double[]{0, 0}; //lat,long
private float accelerometer[] = new float[]{0, 0, 0}; //x,y,z
private float magnetic[] = new float[]{0, 0, 0};; //x,y,z
private float gyroscope[] = new float[]{0, 0, 0};; //x,y,z
private float light;
private float pressure;
private float proximity;
private float gravity[];
private float rotation[];
private float gravity[] = new float[]{0, 0, 0};;
private float rotation[] = new float[]{0, 0, 0};;
private String wordSessionId;
private String word;
private String wordStatus;
@ -45,7 +45,7 @@ public class Event {
}
private double[] getGps() {
return gps != null ? gps : new double[]{0, 0};
return gps;
}
public void setGps(double[] gps) {
@ -54,7 +54,7 @@ public class Event {
}
private float[] getAccelerometer() {
return accelerometer != null ? accelerometer : new float[]{0, 0, 0};
return accelerometer;
}
public void setAccelerometer(float[] accelerometer) {
@ -63,7 +63,7 @@ public class Event {
}
private float[] getMagnetic() {
return magnetic != null ? magnetic : new float[]{0, 0, 0};
return magnetic;
}
public void setMagnetic(float[] magnetic) {
@ -72,7 +72,7 @@ public class Event {
}
private float[] getGyroscope() {
return gyroscope != null ? gyroscope : new float[]{0, 0, 0};
return gyroscope;
}
public void setGyroscope(float[] gyroscope) {
@ -108,7 +108,7 @@ public class Event {
}
private float[] getGravity() {
return gravity != null ? gravity : new float[]{0, 0, 0};
return gravity;
}
public void setGravity(float gravity[]) {
@ -117,7 +117,7 @@ public class Event {
}
private float[] getRotation() {
return rotation != null ? rotation : new float[]{0, 0, 0};
return rotation;
}
public void setRotation(float rotation[]) {

@ -231,7 +231,7 @@ public class LocationDataReader extends DataReader implements LocationListener {
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
Log.e(TAG, " Location Data Retrieval Failed");
Log.e(TAG, " Location Data Retrieval Failed", e);
}
}

@ -21,7 +21,7 @@
<parent>
<artifactId>androidsense-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -3,7 +3,7 @@
<parent>
<artifactId>androidsense-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -19,17 +19,11 @@
package org.wso2.carbon.device.mgt.iot.androidsense.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.*;
import javax.ws.rs.core.Response;
@DeviceType(value = "android_sense")
@ -45,7 +39,7 @@ public interface AndroidSenseService {
@Path("device/{deviceId}/words")
@POST
@Feature(code = "keywords", name = "Add Keywords", description = "Send keywords to the device")
@Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:android-sense:enroll", name = "", description = "")
Response sendKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("keywords") String keywords);
/**
@ -57,13 +51,13 @@ public interface AndroidSenseService {
@Path("device/{deviceId}/words/threshold")
@POST
@Feature(code = "threshold", name = "Add a Threshold", description = "Set a threshold for word in the device")
@Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:android-sense:enroll", name = "", description = "")
Response sendThreshold(@PathParam("deviceId") String deviceId, @QueryParam("threshold") String threshold);
@Path("device/{deviceId}/words")
@DELETE
@Feature(code = "remove", name = "Remove Keywords", description = "Remove the keywords")
@Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:android-sense:enroll", name = "", description = "")
Response removeKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("words") String words);
/**
@ -72,7 +66,7 @@ public interface AndroidSenseService {
@Path("stats/{deviceId}/sensors/{sensorName}")
@GET
@Consumes("application/json")
@Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/stats"})
@Scope(key = "device:android-sense:enroll", name = "", description = "")
@Produces("application/json")
Response getAndroidSenseDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor,
@QueryParam("from") long from, @QueryParam("to") long to);
@ -82,7 +76,7 @@ public interface AndroidSenseService {
*/
@Path("device/{device_id}/register")
@POST
@Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/devices"})
@Scope(key = "device:android-sense:enroll", name = "", description = "")
Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName);
}

@ -23,37 +23,25 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.analytics.dataservice.commons.SORT;
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.device.mgt.common.Device;
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.*;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.AndroidConfiguration;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.Constants;
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.util.Utils;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.*;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
@ -69,7 +57,7 @@ public class AndroidSenseServiceImpl implements AndroidSenseService {
public Response sendKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("keywords") String keywords) {
try {
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
AndroidSenseConstants.DEVICE_TYPE))) {
AndroidSenseConstants.DEVICE_TYPE))) {
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
String publishTopic = APIUtil.getAuthenticatedUserTenantDomain()
@ -88,8 +76,12 @@ public class AndroidSenseServiceImpl implements AndroidSenseService {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(new DeviceIdentifier(deviceId, AndroidSenseConstants.DEVICE_TYPE));
APIUtil.getDeviceManagementService().addOperation(AndroidSenseConstants.DEVICE_TYPE, commandOp,
deviceIdentifiers);
deviceIdentifiers);
return Response.ok().build();
} catch (InvalidDeviceException e) {
String msg = "Invalid Device Identifiers found.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
@ -126,6 +118,10 @@ public class AndroidSenseServiceImpl implements AndroidSenseService {
APIUtil.getDeviceManagementService().addOperation(AndroidSenseConstants.DEVICE_TYPE, commandOp,
deviceIdentifiers);
return Response.ok().build();
} catch (InvalidDeviceException e) {
String msg = "Invalid Device Identifiers found.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (DeviceAccessAuthorizationException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
} catch (OperationManagementException e) {
@ -161,6 +157,10 @@ public class AndroidSenseServiceImpl implements AndroidSenseService {
APIUtil.getDeviceManagementService().addOperation(AndroidSenseConstants.DEVICE_TYPE, commandOp,
deviceIdentifiers);
return Response.ok().build();
} catch (InvalidDeviceException e) {
String msg = "Invalid Device Identifiers found.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();

@ -14,7 +14,7 @@
<parent>
<artifactId>androidsense-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>androidsense-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -200,7 +200,6 @@ function drawGraph_android_sense(from, to) {
populateGraph();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
populateGraph();
});
}
@ -219,7 +218,6 @@ function drawGraph_android_sense(from, to) {
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});
@ -265,7 +263,6 @@ function drawGraph_android_sense(from, to) {
populateGraph();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
populateGraph();
});
}
@ -285,7 +282,6 @@ function drawGraph_android_sense(from, to) {
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>arduino-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>arduino-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -19,16 +19,11 @@
package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
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.*;
import javax.ws.rs.core.Response;
@API(name = "arduino", version = "1.0.0", context = "/arduino", tags = {"arduino"})
@ -38,12 +33,12 @@ public interface ArduinoService {
@Path("device/{deviceId}/bulb")
@POST
@Feature(code = "bulb", name = "Control Bulb", description = "Control Bulb on Arduino Uno")
@Permission(scope = "arduino_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:arduino:enroll", name = "", description = "")
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state);
@Path("device/{deviceId}/controls")
@GET
@Permission(scope = "arduino_device", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:arduino:enroll", name = "", description = "")
Response readControls(@PathParam("deviceId") String deviceId);
/**
@ -53,7 +48,7 @@ public interface ArduinoService {
@GET
@Consumes("application/json")
@Produces("application/json")
@Permission(scope = "arduino_user", permissions = {"/permission/admin/device-mgt/user/stats"})
@Scope(key = "device:arduino:enroll", name = "", description = "")
Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@QueryParam("to") long to);
@ -63,7 +58,7 @@ public interface ArduinoService {
@Path("device/download")
@GET
@Produces("application/octet-stream")
@Permission(scope = "arduino_user", permissions = {"/permission/admin/device-mgt/user/devices"})
@Scope(key = "device:arduino:enroll", name = "", description = "")
Response downloadSketch(@QueryParam("deviceName") String customDeviceName);
}

@ -28,18 +28,15 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
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.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
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.plugin.constants.ArduinoConstants;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ZipUtil;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
@ -47,26 +44,12 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException;
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.*;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.UUID;
import java.util.*;
public class ArduinoServiceImpl implements ArduinoService {
@ -81,7 +64,7 @@ public class ArduinoServiceImpl implements ArduinoService {
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
try {
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
String operation = "BULB:" + state.toUpperCase();
@ -94,8 +77,12 @@ public class ArduinoServiceImpl implements ArduinoService {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(new DeviceIdentifier(deviceId, ArduinoConstants.DEVICE_TYPE));
APIUtil.getDeviceManagementService().addOperation(ArduinoConstants.DEVICE_TYPE, commandOp,
deviceIdentifiers);
deviceIdentifiers);
return Response.status(Response.Status.OK.getStatusCode()).build();
} catch (InvalidDeviceException e) {
String msg = "Invalid Device Identifiers found.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();

@ -22,7 +22,7 @@
<parent>
<artifactId>arduino-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>arduino-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -137,7 +137,6 @@ function drawGraph_arduino(from, to) {
}
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
});
}
@ -155,7 +154,6 @@ function drawGraph_arduino(from, to) {
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-analytics</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -20,7 +20,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -20,7 +20,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -20,7 +20,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -20,7 +20,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -22,7 +22,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -23,7 +23,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,6 +23,7 @@ function onRequest(context) {
var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label";
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var deviceModule = require("/app/modules/business-controllers/device.js").deviceModule;
var utility = require('/app/modules/utility.js').utility;
var response = userModule.getRoles();
var wizardPage = {};
@ -30,7 +31,7 @@ function onRequest(context) {
wizardPage["roles"] = response["content"];
}
var deviceType = context.uriParams.deviceType;
var typesListResponse = userModule.getPlatforms();
var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") {
for (var type in typesListResponse["content"]) {
if (deviceType == typesListResponse["content"][type]["name"]) {

@ -23,7 +23,7 @@
<parent>
<artifactId>iot-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -0,0 +1,108 @@
/*
* 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.devicetype.config;
import org.wso2.carbon.device.mgt.iot.devicetype.util.DeviceTypeConfigUtil;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding CertificateKeystore data.
*/
@XmlRootElement(name = "CertificateKeystore")
public class CertificateKeystoreConfig {
private String certificateKeystoreLocation;
private String certificateKeystoreType;
private String certificateKeystorePassword;
private String caCertAlias;
private String caPrivateKeyPassword;
private String raCertAlias;
private String raPrivateKeyPassword;
@XmlElement(name = "CertificateKeystoreLocation", required = true)
public String getCertificateKeystoreLocation() {
return certificateKeystoreLocation;
}
public void setCertificateKeystoreLocation(String certificateKeystoreLocation) {
if (certificateKeystoreLocation != null && certificateKeystoreLocation.toLowerCase().
contains(DeviceTypeConfigUtil.CARBON_HOME_ENTRY)) {
certificateKeystoreLocation = certificateKeystoreLocation.replace(DeviceTypeConfigUtil.CARBON_HOME_ENTRY,
System.getProperty(DeviceTypeConfigUtil.CARBON_HOME));
}
this.certificateKeystoreLocation = certificateKeystoreLocation;
}
@XmlElement(name = "CertificateKeystoreType", required = true)
public String getCertificateKeystoreType() {
return certificateKeystoreType;
}
public void setCertificateKeystoreType(String certificateKeystoreType) {
this.certificateKeystoreType = certificateKeystoreType;
}
@XmlElement(name = "CertificateKeystorePassword", required = true)
public String getCertificateKeystorePassword() {
return certificateKeystorePassword;
}
public void setCertificateKeystorePassword(String certificateKeystorePassword) {
this.certificateKeystorePassword = certificateKeystorePassword;
}
@XmlElement(name = "CACertAlias", required = true)
public String getCACertAlias() {
return caCertAlias;
}
public void setCACertAlias(String caCertAlias) {
this.caCertAlias = caCertAlias;
}
@XmlElement(name = "CAPrivateKeyPassword", required = true)
public String getCAPrivateKeyPassword() {
return caPrivateKeyPassword;
}
public void setCAPrivateKeyPassword(String caPrivateKeyPassword) {
this.caPrivateKeyPassword = caPrivateKeyPassword;
}
@XmlElement(name = "RACertAlias", required = true)
public String getRACertAlias() {
return raCertAlias;
}
public void setRACertAlias(String raCertAlias) {
this.raCertAlias = raCertAlias;
}
@XmlElement(name = "RAPrivateKeyPassword", required = true)
public String getRAPrivateKeyPassword() {
return raPrivateKeyPassword;
}
public void setRAPrivateKeyPassword(String raPrivateKeyPassword) {
this.raPrivateKeyPassword = raPrivateKeyPassword;
}
}

@ -30,6 +30,7 @@ public class DeviceManagementConfiguration {
private DeviceManagementConfigRepository deviceManagementConfigRepository;
private PushNotificationConfig pushNotificationConfig;
private String deviceType;
private CertificateKeystoreConfig certificateKeystoreConfig;
private static final Log log = LogFactory.getLog(DeviceManagementConfiguration.class);
@ -63,4 +64,13 @@ public class DeviceManagementConfiguration {
this.pushNotificationConfig = pushNotificationConfig;
}
@XmlElement(name = "CertificateKeystore", required = false)
public CertificateKeystoreConfig getCertificateKeystoreConfig() {
return certificateKeystoreConfig;
}
public void setCertificateKeystoreConfig(
CertificateKeystoreConfig certificateKeystoreConfig) {
this.certificateKeystoreConfig = certificateKeystoreConfig;
}
}

@ -31,6 +31,9 @@ import java.io.File;
public class DeviceTypeConfigUtil {
public static final String CARBON_HOME = "carbon.home";
public static final String CARBON_HOME_ENTRY = "${carbon.home}";
public static Document convertToDocument(File file) throws DeviceTypeConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);

@ -63,6 +63,7 @@ public class Utils {
}
} catch (SocketException e) {
hostName = "localhost";
log.warn("Failed retrieving the hostname, therefore set to localhost", e);
}
return hostName;
}
@ -90,25 +91,14 @@ public class Utils {
templateFiles.add("sketch.properties"); // ommit copying the props file
copyFolder(new File(sketchPath), new File(archivesPath), templateFiles);
createZipArchive(archivesPath);
FileUtils.deleteDirectory(new File(archivesPath));
File zip = new File(archivesPath + ".zip");
return new ZipArchive(zipFileName, zip);
} catch (IOException ex) {
throw new DeviceManagementException(
"Error occurred when trying to read property " + "file sketch.properties", ex);
}
try {
createZipArchive(archivesPath);
} catch (IOException e) {
String message = "Zip file for the specific device agent not found at path: " + archivesPath;
log.error(message);
log.error(e);
throw new DeviceManagementException(message, e);
}
FileUtils.deleteDirectory(new File(archivesPath));//clear folder
/* now get the zip file */
File zip = new File(archivesPath + ".zip");
return new ZipArchive(zipFileName, zip);
}
private static Map<String, List<String>> getProperties(String propertyFilePath) throws IOException {
@ -139,7 +129,7 @@ public class Utils {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
log.error("Failed closing connection", e);
}
}
}
@ -147,21 +137,25 @@ public class Utils {
private static void parseTemplate(String srcFile, String dstFile, Map contextParams) throws IOException {
//read from file
FileInputStream inputStream = new FileInputStream(srcFile);
String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8.toString());
Iterator iterator = contextParams.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iterator.next();
content = content.replaceAll("\\$\\{" + mapEntry.getKey() + "\\}", mapEntry.getValue().toString());
}
if (inputStream != null) {
inputStream.close();
}
//write to file
FileOutputStream outputStream = new FileOutputStream(dstFile);
IOUtils.write(content, outputStream, StandardCharsets.UTF_8.toString());
if (outputStream != null) {
outputStream.close();
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
try {
inputStream = new FileInputStream(srcFile);
outputStream = new FileOutputStream(dstFile);
String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8.toString());
Iterator iterator = contextParams.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iterator.next();
content = content.replaceAll("\\$\\{" + mapEntry.getKey() + "\\}", mapEntry.getValue().toString());
}
IOUtils.write(content, outputStream, StandardCharsets.UTF_8.toString());
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
@ -213,35 +207,16 @@ public class Utils {
out.write(buffer, 0, length);
}
} finally {
silentClose(in);
silentClose(out);
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
private static void silentClose(InputStream is) {
if (is == null) {
return;
}
try {
is.close();
} catch (IOException e) {
// do nothing
}
}
private static void silentClose(OutputStream os) {
if (os == null) {
return;
}
try {
os.close();
} catch (IOException e) {
// do nothing
}
}
private static boolean createZipArchive(String srcFolder) throws IOException {
BufferedInputStream origin = null;
ZipOutputStream out = null;
@ -295,8 +270,12 @@ public class Utils {
}
out.flush();
} finally {
silentClose(origin);
silentClose(out);
if (origin != null) {
origin.close();
}
if (out != null) {
out.close();
}
}
return true;
}

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>raspberrypi-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>raspberrypi-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -19,16 +19,11 @@
package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
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.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -39,7 +34,7 @@ public interface RaspberryPiService {
@Path("device/{deviceId}/bulb")
@POST
@Feature(code = "bulb", name = "Bulb On / Off", description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
@Permission(scope = "raspberrypi_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:raspberrypi:enroll", name = "", description = "")
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state);
/**
@ -49,7 +44,7 @@ public interface RaspberryPiService {
@GET
@Consumes("application/json")
@Produces("application/json")
@Permission(scope = "raspberrypi_user", permissions = {"/permission/admin/device-mgt/user/stats"})
@Scope(key = "device:raspberrypi:enroll", name = "", description = "")
Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
@QueryParam("from") long from, @QueryParam("to") long to);
@ -59,7 +54,7 @@ public interface RaspberryPiService {
@Path("device/download")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Permission(scope = "raspberrypi_user", permissions = {"/permission/admin/device-mgt/user/devices"})
@Scope(key = "device:raspberrypi:enroll", name = "", description = "")
Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketch_type") String sketchType);
}

@ -28,18 +28,15 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
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.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.ZipUtil;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
@ -47,24 +44,12 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException;
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.*;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.*;
public class RaspberryPiServiceImpl implements RaspberryPiService {
@ -77,7 +62,7 @@ public class RaspberryPiServiceImpl implements RaspberryPiService {
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
try {
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
RaspberrypiConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
RaspberrypiConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
String switchToState = state.toUpperCase();
@ -103,8 +88,12 @@ public class RaspberryPiServiceImpl implements RaspberryPiService {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(new DeviceIdentifier(deviceId, RaspberrypiConstants.DEVICE_TYPE));
APIUtil.getDeviceManagementService().addOperation(RaspberrypiConstants.DEVICE_TYPE, commandOp,
deviceIdentifiers);
deviceIdentifiers);
return Response.ok().build();
} catch (InvalidDeviceException e) {
String msg = "Invalid Device Identifiers found.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();

@ -23,7 +23,7 @@
<parent>
<artifactId>raspberrypi-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>raspberrypi-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -137,7 +137,6 @@ function drawGraph_raspberrypi(from, to) {
}
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
});
}
@ -155,7 +154,6 @@ function drawGraph_raspberrypi(from, to) {
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>virtual-fire-alarm-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>virtual-fire-alarm-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>virtual-fire-alarm-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -19,7 +19,7 @@
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
@ -48,7 +48,7 @@ public interface VirtualFireAlarmService {
*/
@POST
@Path("device/{deviceId}/buzz")
@Permission(scope = "virtual_firealarm_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Scope(key = "device:firealarm:enroll", name = "", description = "")
@Feature(code = "buzz", name = "Buzzer On / Off", description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
Response switchBuzzer(@PathParam("deviceId") String deviceId,
@FormParam("state") String state);
@ -58,7 +58,7 @@ public interface VirtualFireAlarmService {
*/
@Path("device/stats/{deviceId}")
@GET
@Permission(scope = "virtual_firealarm_user", permissions = {"/permission/admin/device-mgt/user/stats"})
@Scope(key = "device:firealarm:enroll", name = "", description = "")
@Consumes("application/json")
@Produces("application/json")
Response getVirtualFirealarmStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@ -67,7 +67,7 @@ public interface VirtualFireAlarmService {
@Path("device/download")
@GET
@Produces("application/zip")
@Permission(scope = "virtual_firealarm_user", permissions = {"/permission/admin/device-mgt/user/devices"})
@Scope(key = "device:firealarm:enroll", name = "", description = "")
Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType);
}

@ -29,10 +29,7 @@ import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
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.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -109,7 +106,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
PrivateKey serverPrivateKey = VirtualFirealarmSecurityManager.getServerPrivateKey();
String actualMessage = resource + ":" + switchToState;
String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage,
serverPrivateKey);
serverPrivateKey);
String publishTopic = APIUtil.getTenantDomainOftheUser() + "/"
+ VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId;
@ -125,14 +122,18 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
.getInstance().getServerName());
props.setProperty(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "CONTROL-REQUEST");
props.setProperty(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY,
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);
commandOp.setProperties(props);
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(new DeviceIdentifier(deviceId, VirtualFireAlarmConstants.DEVICE_TYPE));
APIUtil.getDeviceManagementService().addOperation(VirtualFireAlarmConstants.DEVICE_TYPE, commandOp,
deviceIdentifiers);
deviceIdentifiers);
return Response.ok().build();
} catch (InvalidDeviceException e) {
String msg = "Error occurred while executing command operation to send keywords";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();

@ -23,7 +23,7 @@
<parent>
<artifactId>virtual-fire-alarm-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,8 +22,11 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
import org.wso2.carbon.device.mgt.iot.devicetype.config.CertificateKeystoreConfig;
import org.wso2.carbon.device.mgt.iot.devicetype.config.DeviceManagementConfiguration;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.VirtualFirealarmManagementDataHolder;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@ -46,11 +49,11 @@ import java.security.SignatureException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
public class VirtualFirealarmSecurityManager {
private static final Log log = LogFactory.getLog(VirtualFirealarmSecurityManager.class);
private static PrivateKey serverPrivateKey;
private static CertificateKeystoreConfig certificateKeystoreConfig;
private static final String SIGNATURE_ALG = "SHA1withRSA";
private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding";
@ -58,26 +61,34 @@ public class VirtualFirealarmSecurityManager {
}
private static CertificateKeystoreConfig getCertKeyStoreConfig() {
if (certificateKeystoreConfig == null) {
DeviceManagementConfiguration deviceManagementConfiguration = VirtualFirealarmManagementDataHolder.getInstance().
getDeviceTypeConfigService().getConfiguration(
VirtualFireAlarmConstants.DEVICE_TYPE,
VirtualFireAlarmConstants.DEVICE_TYPE_PROVIDER_DOMAIN);
certificateKeystoreConfig = deviceManagementConfiguration.getCertificateKeystoreConfig();
}
return certificateKeystoreConfig;
}
public static void initVerificationManager() {
serverPrivateKey = retrievePrivateKey(ConfigurationUtil.CA_CERT_ALIAS,
ConfigurationUtil.KEYSTORE_CA_CERT_PRIV_PASSWORD);
serverPrivateKey = retrievePrivateKey();
}
public static PrivateKey retrievePrivateKey(String alias, String password){
public static PrivateKey retrievePrivateKey() {
PrivateKey privateKey = null;
InputStream inputStream = null;
KeyStore keyStore;
CertificateKeystoreConfig certificateKeystoreConfig = getCertKeyStoreConfig();
try {
keyStore = KeyStore.getInstance(ConfigurationUtil.getConfigEntry(ConfigurationUtil.CERTIFICATE_KEYSTORE));
inputStream = new FileInputStream(ConfigurationUtil.getConfigEntry(
ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE));
keyStore = KeyStore.getInstance(certificateKeystoreConfig.getCertificateKeystoreType());
inputStream = new FileInputStream(certificateKeystoreConfig.getCertificateKeystoreLocation());
keyStore.load(inputStream, ConfigurationUtil.getConfigEntry(ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD)
.toCharArray());
keyStore.load(inputStream, certificateKeystoreConfig.getCertificateKeystorePassword().toCharArray());
privateKey = (PrivateKey) (keyStore.getKey(ConfigurationUtil.getConfigEntry(alias),
ConfigurationUtil.getConfigEntry(password).toCharArray()));
privateKey = (PrivateKey) (keyStore.getKey(certificateKeystoreConfig.getCACertAlias(),
certificateKeystoreConfig.getCAPrivateKeyPassword().toCharArray()));
} catch (KeyStoreException e) {
String errorMsg = "Could not load KeyStore of given type in [certificate-config.xml] file." ;
@ -94,9 +105,6 @@ public class VirtualFirealarmSecurityManager {
} catch (IOException e) {
String errorMsg = "Input output issue occurred when loading KeyStore";
log.error(errorMsg, e);
} catch (KeystoreException e) {
String errorMsg = "An error occurred whilst trying load Configs for KeyStoreReader";
log.error(errorMsg, e);
} catch (UnrecoverableKeyException e) {
String errorMsg = "Key is unrecoverable when retrieving CA private key";
log.error(errorMsg, e);

@ -21,7 +21,7 @@
<parent>
<artifactId>virtual-fire-alarm-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>virtual-fire-alarm-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -137,7 +137,6 @@ function drawGraph_virtual_firealarm(from, to) {
}
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
});
}
@ -155,7 +154,6 @@ function drawGraph_virtual_firealarm(from, to) {
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});

@ -39,16 +39,6 @@ $(document).ready(function () {
});
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};
// Start of HTML embedded invoke methods
var addConfiguration = function () {
var errorMsgWrapper = "#virtual_firelarm-config-error-msg";

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>android-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,8 +21,7 @@ package org.wso2.carbon.mdm.services.android.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -49,7 +48,6 @@ public class AndroidPlatformConfiguration implements Serializable {
value = "type of device",
required = true
)
@NotNull
@Size(min = 2, max = 10)
private String type;
@ApiModelProperty(

@ -21,7 +21,6 @@ package org.wso2.carbon.mdm.services.android.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;
@ -36,7 +35,6 @@ public class BlacklistApplications extends AndroidOperation implements Serializa
@ApiModelProperty(name = "appIdentifiers", value = "A list of application package names to be blacklisted.",
required = true)
@Size(min = 2, max = 45)
@Pattern(regexp = "^[A-Za-z0-9]*$")
private List<String> appIdentifiers;
public List<String> getAppIdentifier() {

@ -32,16 +32,15 @@ import java.util.List;
public class BlacklistApplicationsBeanWrapper {
@ApiModelProperty(name = "operation", value = "Blacklist applications information", required = true)
@Valid
private BlacklistApplications operation;
private @Valid BlacklistApplications operation;
@ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true)
private List<String> deviceIDs;
public BlacklistApplications getOperation() {
public @Valid BlacklistApplications getOperation() {
return operation;
}
public void setOperation(BlacklistApplications operation) {
public void setOperation(@Valid BlacklistApplications operation) {
this.operation = operation;
}

@ -21,8 +21,6 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.Vpn;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.List;
/**
@ -36,8 +34,6 @@ public class VpnBeanWrapper {
private Vpn operation;
@ApiModelProperty(name = "deviceIDs",
value = "List of device Ids to be need to execute VPN operation.", required = true)
@Size(min = 2, max = 45)
@Pattern(regexp = "^[A-Za-z0-9]*$")
private List<String> deviceIDs;
public Vpn getOperation() {

@ -105,9 +105,7 @@ public class GlobalThrowableMapper implements ExceptionMapper {
return ((ForbiddenException) e).getResponse();
}
//unknown exception log and return
if (log.isDebugEnabled()) {
log.error("An Unknown exception has been captured by global exception mapper.", e);
}
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", "application/json")
.entity(e500).build();
}

@ -19,9 +19,12 @@
package org.wso2.carbon.mdm.services.android.services;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.mdm.services.android.bean.wrapper.*;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@ -30,6 +33,10 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@API(name = "Android Device Management Administrative Service", version = "1.0.0",
context = "api/device-mgt/android/v1.0/admin/devices",
tags = {"devicemgt_android"})
@Path("/admin/devices")
@Api(value = "Android Device Management Administrative Service", description = "Device management related admin APIs.")
@Produces(MediaType.APPLICATION_JSON)
@ -85,6 +92,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new lock operation.")
})
@Scope(key = "device:android:operation:lock", name = "Lock device", description = "")
Response configureDeviceLock(
@ApiParam(name = "deviceLockBeanWrapper",
value = "Device lock configurations with device IDs") DeviceLockBeanWrapper deviceLockBeanWrapper);
@ -138,6 +146,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new un-lock operation.")
})
@Scope(key = "device:android:operation:unlock", name = "Unlock device", description = "")
Response configureDeviceUnlock(
@ApiParam(name = "deviceIDs", value = "DeviceIds to be enable device unlock operation")
List<String> deviceIDs);
@ -190,6 +199,7 @@ public interface DeviceManagementAdminService {
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while adding a new get-location operation.")})
@Scope(key = "device:android:operation:location", name = "Get device location", description = "")
Response getDeviceLocation(
@ApiParam(name = "deviceIDs", value = "DeviceIDs to be requested to get device location")
List<String> deviceIDs);
@ -242,6 +252,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new clear password operation.")
})
@Scope(key = "device:android:operation:clear-password", name = "Clear password of device", description = "")
Response removePassword(
@ApiParam(name = "deviceIDs",
value = "DeviceIds to be requested to remove password") List<String> deviceIDs);
@ -294,6 +305,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new control camera operation.")
})
@Scope(key = "device:android:operation:camera", name = "Enable/Disable camera", description = "")
Response configureCamera(
@ApiParam(name = "cameraBeanWrapper", value = "Camera enable/disable configurations with device IDs")
CameraBeanWrapper cameraBeanWrapper);
@ -349,6 +361,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new device info operation.")
})
@Scope(key = "device:android:operation:info", name = "Get device information", description = "")
Response getDeviceInformation(
@ApiParam(name = "deviceIds", value = "Device IDs to be requested to get device information")
List<String> deviceIDs);
@ -457,6 +470,7 @@ public interface DeviceManagementAdminService {
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while adding a enterprise wipe operation.")})
@Scope(key = "device:android:operation:enterprise-wipe", name = "Enterprise wipe", description = "")
Response wipeDevice(@ApiParam(name = "deviceIDs", value = "Device IDs to be requested to do enterprise-wipe")
List<String> deviceIDs);
@ -508,6 +522,7 @@ public interface DeviceManagementAdminService {
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while adding a device wipe operation.")})
@Scope(key = "device:android:operation:wipe", name = "Factory reset device", description = "")
Response wipeData(
@ApiParam(name = "wipeDataBeanWrapper", value = "Configurations and DeviceIds needed to do wipe-data")
WipeDataBeanWrapper wipeDataBeanWrapper);
@ -564,6 +579,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new get-applications operation.")
})
@Scope(key = "device:android:operation:applications", name = "Get installed applications", description = "")
Response getApplications(
@ApiParam(name = "deviceIDs", value = "Device Ids needed to get applications that are already installed")
List<String> deviceIDs);
@ -616,6 +632,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new device ring operation.")
})
@Scope(key = "device:android:operation:ring", name = "Ring device", description = "")
Response ringDevice(
@ApiParam(name = "deviceIDs", value = "Device Ids needed for ring")
List<String> deviceIDs);
@ -668,6 +685,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new device reboot operation.")
})
@Scope(key = "device:android:operation:reboot", name = "Reboot device", description = "")
Response rebootDevice(
@ApiParam(name = "deviceIDs", value = "Device Ids needed for reboot.")
List<String> deviceIDs);
@ -720,6 +738,7 @@ public interface DeviceManagementAdminService {
"Server error occurred while adding a new device mute operation.")
})
@Path("/mute")
@Scope(key = "device:android:operation:mute", name = "Mute device", description = "")
Response muteDevice(
@ApiParam(name = "deviceIDs", value = "DeviceIDs need to be muted")
List<String> deviceIDs);
@ -775,6 +794,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new install-application operation.")
})
@Scope(key = "device:android:operation:install-app", name = "Install applications", description = "")
Response installApplication(
@ApiParam(name = "applicationInstallationBeanWrapper", value = "Properties of installed apps and device IDs")
ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper);
@ -830,6 +850,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new update-application operation.")
})
@Scope(key = "device:android:operation:update-app", name = "Update installed applications", description = "")
Response updateApplication(
@ApiParam(name = "applicationUpdateBeanWrapper", value = "Properties of updated apps and device IDs")
ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper);
@ -882,6 +903,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new uninstall-application operation.")
})
@Scope(key = "device:android:operation:uninstall-app", name = "Uninstall applications", description = "")
Response uninstallApplication(
@ApiParam(name = "applicationUninstallationBeanWrapper",
value = "applicationUninstallationConfigs and Device Ids")
@ -936,10 +958,11 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new blacklist-applications operation.")
})
@Scope(key = "device:android:operation:blacklist-app", name = "Blacklist applications", description = "")
Response blacklistApplications(
@ApiParam(name = "blacklistApplicationsBeanWrapper", value = "BlacklistApplications " +
"Configuration and DeviceIds")
BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper);
@Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper);
@POST
@Path("/upgrade-firmware")
@ -990,6 +1013,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new upgrade firmware operation.")
})
@Scope(key = "device:android:operation:upgrade", name = "Upgrade firmware", description = "")
Response upgradeFirmware(
@ApiParam(name = "upgradeFirmwareBeanWrapper",
value = "Firmware upgrade configuration and DeviceIds")
@ -1044,6 +1068,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new configure VPN operation.")
})
@Scope(key = "device:android:operation:vpn", name = "Add VPN profiles", description = "")
Response configureVPN(
@ApiParam(name = "vpnBeanWrapper",
value = "VPN configuration and DeviceIds")
@ -1097,6 +1122,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new send notification operation.")
})
@Scope(key = "device:android:operation:notification", name = "Send notifications", description = "")
Response sendNotification(
@ApiParam(name = "notificationBeanWrapper",
value = "Notification Configurations and device Ids")
@ -1150,6 +1176,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new configure wifi operation.")
})
@Scope(key = "device:android:operation:wifi", name = "Add WiFi configurations", description = "")
Response configureWifi(
@ApiParam(name = "wifiBeanWrapper",
value = "WifiConfigurations and Device Ids") WifiBeanWrapper wifiBeanWrapper);
@ -1202,6 +1229,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new encrypt storage operation.")
})
@Scope(key = "device:android:operation:encrypt", name = "Encrypt device", description = "")
Response encryptStorage(
@ApiParam(name = "encryptionBeanWrapper",
value = "Configurations and deviceIds need to be done data encryption")
@ -1255,6 +1283,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new change lock code operation.")
})
@Scope(key = "device:android:operation:change-lock", name = "Change password of device", description = "")
Response changeLockCode(
@ApiParam(name = "lockCodeBeanWrapper",
value = "Configurations and device Ids need to be done change lock code")
@ -1308,6 +1337,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new set password policy operation.")
})
@Scope(key = "device:android:operation:password-policy", name = "Set password policy", description = "")
Response setPasswordPolicy(
@ApiParam(name = "passwordPolicyBeanWrapper",
value = "Password Policy Configurations and Device Ids")
@ -1361,6 +1391,7 @@ public interface DeviceManagementAdminService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new set webclip operation.")
})
@Scope(key = "device:android:operation:webclip", name = "Add webclips", description = "")
Response setWebClip(
@ApiParam(name = "webClipBeanWrapper",
value = "Configurations to need set web clip on device and device Ids")

@ -19,6 +19,8 @@
package org.wso2.carbon.mdm.services.android.services;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice;
@ -32,6 +34,10 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@API(name = "Android Device Management", version = "1.0.0",
context = "api/device-mgt/android/v1.0/devices",
tags = {"devicemgt_android"})
@Api(value = "Android Device Management",
description = "This carries all the resources related to Android device management functionalities")
@Path("/devices")
@ -81,6 +87,7 @@ public interface DeviceManagementService {
message = "Internal Server Error. \n " +
"Server error occurred while updating the application list.")
})
@Scope(key = "device:android:enroll", name = "Enroll Android device", description = "")
Response updateApplicationList(
@ApiParam(
name = "id",
@ -134,6 +141,7 @@ public interface DeviceManagementService {
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching policies.")
})
@Scope(key = "device:android:enroll", name = "Enroll Android device", description = "")
Response getPendingOperations(
@ApiParam(
name = "id",
@ -198,6 +206,7 @@ public interface DeviceManagementService {
message = "Internal Server Error. \n " +
"Server error occurred while adding a new policy.")
})
Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll")
@Valid AndroidDevice device);
@ -236,6 +245,7 @@ public interface DeviceManagementService {
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the enrollment status of the Android device.")
})
@Scope(key = "device:android:enroll", name = "Enroll Android device", description = "")
Response isEnrolled(
@ApiParam(
name = "id",
@ -289,6 +299,7 @@ public interface DeviceManagementService {
message = "Internal Server Error. \n " +
"Server error occurred while updating the device enrollment.")
})
@Scope(key = "device:android:enroll", name = "Enroll Android device", description = "")
Response modifyEnrollment(
@ApiParam(
name = "id",
@ -318,6 +329,7 @@ public interface DeviceManagementService {
message = "Internal Server Error. \n " +
"Server error occurred while dis-enrolling the device.")
})
@Scope(key = "device:android:disenroll", name = "Enroll Android device", description = "")
Response disEnrollDevice(
@ApiParam(
name = "id",

@ -19,6 +19,8 @@
package org.wso2.carbon.mdm.services.android.services;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.mdm.services.android.bean.AndroidPlatformConfiguration;
import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException;
@ -28,6 +30,10 @@ import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Android Configuration Management", version = "1.0.0",
context = "api/device-mgt/android/v1.0/configuration",
tags = {"devicemgt_android"})
@Api(value = "Android Configuration Management", description = "This API carries all resource associated with " +
"manipulating the general configurations of Android platform")
@Path("/configuration")
@ -75,6 +81,7 @@ public interface DeviceTypeConfigurationService {
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching Android platform configuration.")
})
@Scope(key = "configuration:view", name = "View configurations", description = "")
Response getConfiguration(
@ApiParam(
name = "If-Modified-Since",
@ -124,6 +131,7 @@ public interface DeviceTypeConfigurationService {
message = "Internal Server Error. \n " +
"Server error occurred while modifying Android platform configuration.")
})
@Scope(key = "configuration:manage", name = "Add configurations", description = "")
Response updateConfiguration(
@ApiParam(name = "configuration",
value = "AndroidPlatformConfiguration")
@ -171,6 +179,7 @@ public interface DeviceTypeConfigurationService {
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching Android license configuration.")
})
@Scope(key = "device:android:enroll", name = "Enroll Android device", description = "")
Response getLicense(
@ApiParam(
name = "If-Modified-Since",

@ -19,6 +19,8 @@
package org.wso2.carbon.mdm.services.android.services;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper;
@ -28,6 +30,10 @@ import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Android Event Receiver", version = "1.0.0",
context = "api/device-mgt/android/v1.0/events",
tags = {"devicemgt_android"})
@Api(value = "Event Receiver", description = "Event publishing/retrieving related APIs.To enable Eventing need to" +
" configure as ref-https://docs.wso2.com/display/EMM210/Managing+Event+Publishing+with+WSO2+Data+Analytics+Server, " +
"https://docs.wso2.com/display/EMM210/Creating+a+New+Event+Stream+and+Receiver")
@ -84,6 +90,7 @@ public interface EventReceiverService {
message = "Internal Server Error. \n " +
"Server error occurred while publishing events.")
})
@Scope(key = "device:android:event:manage", name = "Publish events to DAS", description = "")
Response publishEvents(
@ApiParam(
name = "eventBeanWrapper",
@ -133,7 +140,7 @@ public interface EventReceiverService {
code = 500,
message = "Error occurred while getting published events for specific device.")
})
@Scope(key = "device:android:event:read", name = "View events", description = "")
Response retrieveAlerts(
@ApiParam(
name = "id",

@ -21,47 +21,20 @@ package org.wso2.carbon.mdm.services.android.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation;
import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation;
import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate;
import org.wso2.carbon.mdm.services.android.bean.BlacklistApplications;
import org.wso2.carbon.mdm.services.android.bean.Camera;
import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption;
import org.wso2.carbon.mdm.services.android.bean.DeviceLock;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.bean.LockCode;
import org.wso2.carbon.mdm.services.android.bean.Notification;
import org.wso2.carbon.mdm.services.android.bean.PasscodePolicy;
import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware;
import org.wso2.carbon.mdm.services.android.bean.Vpn;
import org.wso2.carbon.mdm.services.android.bean.WebClip;
import org.wso2.carbon.mdm.services.android.bean.Wifi;
import org.wso2.carbon.mdm.services.android.bean.WipeData;
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.BlacklistApplicationsBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.CameraBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.DeviceLockBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EncryptionBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.LockCodeBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.UpgradeFirmwareBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper;
import org.wso2.carbon.mdm.services.android.bean.*;
import org.wso2.carbon.mdm.services.android.bean.wrapper.*;
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService;
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@ -103,6 +76,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setEnabled(true);
operation.setPayLoad(lock.toJSON());
return AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -130,6 +108,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(true);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -156,6 +139,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -182,6 +170,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance.";
log.error(errorMessage, e);
@ -216,6 +209,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(camera.isEnabled());
return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -242,6 +240,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -267,6 +270,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.LOGCAT);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -292,6 +300,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -326,6 +339,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(wipeData.toJSON());
return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -352,6 +370,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -378,6 +401,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -404,6 +432,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -431,6 +464,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(true);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -467,6 +505,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setPayLoad(applicationInstallation.toJSON());
return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -503,6 +546,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -540,6 +588,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
return AndroidAPIUtils.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -556,7 +609,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
@POST
@Path("/blacklist-applications")
@Override
public Response blacklistApplications(BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) {
public Response blacklistApplications(@Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) {
if (log.isDebugEnabled()) {
log.debug("Invoking 'Blacklist-Applications' operation");
}
@ -575,7 +628,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setPayLoad(blacklistApplications.toJSON());
return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -618,6 +675,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(upgradeFirmware.toJSON());
return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -658,6 +720,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setPayLoad(vpn.toJSON());
return AndroidAPIUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -693,7 +760,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setPayLoad(notification.toJSON());
return AndroidAPIUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -730,7 +801,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
return AndroidAPIUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -766,7 +841,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setEnabled(deviceEncryption.isEncrypted());
return AndroidAPIUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -802,7 +881,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setPayLoad(lockCode.toJSON());
return AndroidAPIUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -839,7 +922,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
return AndroidAPIUtils.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
@ -875,7 +962,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(webClip.toJSON());
return AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);

@ -32,7 +32,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication;
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice;
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
import org.wso2.carbon.mdm.services.android.exception.*;
import org.wso2.carbon.mdm.services.android.services.DeviceManagementService;
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
@ -192,6 +192,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@POST
@Override
public Response enrollDevice(@Valid AndroidDevice androidDevice) {
if (androidDevice == null) {
String errorMessage = "The payload of the android device enrollment is incorrect.";
log.error(errorMessage);
throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
try {
Device device = new Device();
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
@ -209,12 +215,18 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService();
policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType()));
if (status) {
return Response.status(Response.Status.OK).entity("Android device, which carries the id '" +
androidDevice.getDeviceIdentifier() + "' has successfully been enrolled").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseMessage("Android device, which carries the id '" +
androidDevice.getDeviceIdentifier() + "' has successfully been enrolled");
return Response.status(Response.Status.OK).entity(responseMessage).build();
} else {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to enroll '" +
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
responseMessage.setResponseMessage("Failed to enroll '" +
device.getType() + "' device, which carries the id '" +
androidDevice.getDeviceIdentifier() + "'").build();
androidDevice.getDeviceIdentifier() + "'");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while enrolling the android, which carries the id '" +
@ -241,11 +253,16 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
try {
result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
if (result) {
return Response.status(Response.Status.OK).entity("Android device that carries the id '" +
id + "' is enrolled").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseMessage("Android device that carries the id '" +
id + "' is enrolled");
return Response.status(Response.Status.OK).entity(responseMessage).build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("No Android device is found upon the id '" +
id + "'").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString());
responseMessage.setResponseMessage("No Android device is found upon the id '" + id + "'");
return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while checking enrollment status of the device.";
@ -260,7 +277,16 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@Override
public Response modifyEnrollment(@PathParam("id") String id, @Valid AndroidDevice androidDevice) {
Device device = new Device();
String msg = "";
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
if(androidDevice.getEnrolmentInfo().getDateOfEnrolment() <= 0){
msg = "Invalid Enrollment date.";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
if(androidDevice.getEnrolmentInfo().getDateOfLastUpdate() <= 0){
msg = "Invalid Last Updated date.";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
device.setEnrolmentInfo(androidDevice.getEnrolmentInfo());
device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser());
device.setDeviceInfo(androidDevice.getDeviceInfo());
@ -274,14 +300,20 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device);
if (result) {
return Response.status(Response.Status.ACCEPTED).entity("Enrollment of Android device that " +
"carries the id '" + id + "' has successfully updated").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.ACCEPTED.toString());
responseMessage.setResponseMessage("Enrollment of Android device that " +
"carries the id '" + id + "' has successfully updated");
return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build();
} else {
return Response.status(Response.Status.NOT_MODIFIED).entity("Enrollment of Android device that " +
"carries the id '" + id + "' has not been updated").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.NOT_MODIFIED.toString());
responseMessage.setResponseMessage("Enrollment of Android device that " +
"carries the id '" + id + "' has not been updated");
return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
id + "'";
log.error(msg, e);
throw new UnexpectedServerErrorException(
@ -298,11 +330,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
try {
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
if (result) {
return Response.status(Response.Status.OK).entity("Android device that carries id '" + id +
"' has successfully dis-enrolled").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseMessage("Android device that carries id '" + id +
"' has successfully dis-enrolled");
return Response.status(Response.Status.OK).entity(responseMessage).build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Android device that carries id '" + id +
"' has not been dis-enrolled").build();
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString());
responseMessage.setResponseMessage("Android device that carries id '" + id +
"' has not been dis-enrolled");
return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while dis-enrolling the Android device that carries the id '" + id + "'";

@ -91,6 +91,12 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati
Message responseMsg = new Message();
ConfigurationEntry licenseEntry = null;
PlatformConfiguration configuration = new PlatformConfiguration();
if (androidPlatformConfiguration == null) {
String errorMessage = "The payload of the android platform configuration is incorrect.";
log.error(errorMessage);
throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
configuration.setConfiguration(androidPlatformConfiguration.getConfiguration());
try {
configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);

@ -30,10 +30,7 @@ import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.*;
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.device.details.DeviceInfo;
@ -118,24 +115,23 @@ public class AndroidAPIUtils {
}
public static Response getOperationResponse(List<String> deviceIDs, Operation operation)
throws DeviceManagementException, OperationManagementException {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
if (deviceIDs == null || deviceIDs.size() == 0) {
String errorMessage = "Device identifier list is empty";
log.error(errorMessage);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils();
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs);
List<DeviceIdentifier> validDeviceIds = deviceIDHolder.getValidDeviceIDList();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
List<DeviceIdentifier> deviceids = new ArrayList<>();
for (String deviceId : deviceIDs) {
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID);
deviceids.add(deviceIdentifier);
}
Activity activity = null;
if(validDeviceIds.size() > 0) {
activity = getDeviceManagementService().addOperation(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, validDeviceIds);
} else {
throw new IllegalArgumentException("Invalid device Identifiers found");
}
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceids);
// if (activity != null) {
// GCMService gcmService = getGCMService();

@ -50,7 +50,7 @@
<name>Add Tenant configuration</name>
<path>/device-mgt/admin/platform-configs/add</path>
<url>/configuration</url>
<method>POST</method>
<method>PUT</method>
</Permission>
<Permission>

@ -44,14 +44,14 @@
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="GlobalExceptionMapper" class="org.wso2.carbon.mdm.services.android.exception.GlobalThrowableMapper"/>
<bean id="ValidationInterceptor" class="org.wso2.carbon.mdm.services.android.exception.ValidationInterceptor"/>
<bean id="ValidationInterceptor" class="org.wso2.carbon.mdm.services.android.common.ValidationInterceptor"/>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="org.wso2.carbon.mdm.services.android.services"/>
<property name="version" value="1.0"/>
<property name="host" value="localhost:9443"/>
<property name="schemes" value="https" />
<property name="basePath" value="/api/device-mgt/android/v1.0"/>
<property name="basePath" value="/api-device-mgt-android-v1.0"/>
<property name="title" value="Android Device Management API Definitions"/>
<property name="contact" value="dev@wso2.org"/>
<property name="license" value="Apache 2.0"/>

@ -49,7 +49,7 @@
</context-param>
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>false</param-value>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>

@ -23,13 +23,13 @@
<parent>
<artifactId>android-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.ui</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<name>WSO2 Carbon - Mobile Android UI</name>
<packaging>pom</packaging>

@ -0,0 +1,92 @@
{{!
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.
}}
<!-- android -->
<div class="panel panel-default">
<div id="android-config-body" class="panel-collapse panel-body" role="tabpanel">
<div id="android-config-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<h4>
Communication Protocol Configuration
<hr>
</h4>
<div class="wr-input-control">
<label class="wr-input-label" for="android-config-notifier">
Type of Communication
<span class="helper" title="Communication method of android agent to contact EMM server">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<select id="android-config-notifier" class="form-control" data-default="0">
<option value="1">Local Polling</option>
<option value="2">Google Cloud Messaging ( GCM )</option>
</select>
</div>
<div id="local-inputs">
<div class="wr-input-control">
<label class="wr-input-label" for="android-config-notifier-frequency">
Polling Interval*
<span class="helper" title="Time interval after which Android agent will contact EMM server each time to fetch data">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
<br>
( Should be in seconds )
</label>
<input id="android-config-notifier-frequency" type="text" class="form-control" >
</div>
</div>
<div id="gcm-inputs">
<div class="wr-input-control">
<label class="wr-input-label" for="android-config-gcm-api-key">
API Key*
<span class="helper" title="GCM API Key">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="android-config-gcm-api-key" type="text" class="form-control" >
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="android-config-gcm-sender-id">
Sender ID*
<span class="helper" title="GCM Sender ID">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="android-config-gcm-sender-id" type="text" class="form-control">
</div>
</div>
<h4>
End User License Agreement ( EULA )
<hr>
</h4>
<div class="wr-input-control">
<textarea id="android-eula" type="text" class="form-control"></textarea>
</div>
<div class="wr-input-control wr-btn-grp">
<button id="save-android-btn" class="wr-btn">Save</button>
</div>
</div>
</div>
<!-- /android -->
{{#zone "bottomJs"}}
{{js "js/platform-configuration.js"}}
{{/zone}}

@ -0,0 +1,249 @@
/*
* 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.
*/
/**
* Checks if provided input is valid against RegEx input.
*
* @param regExp Regular expression
* @param inputString Input string to check
* @returns {boolean} Returns true if input matches RegEx
*/
function isPositiveInteger(str) {
return /^\+?(0|[1-9]\d*)$/.test(str);
}
var notifierTypeConstants = {
"LOCAL": "1",
"GCM": "2"
};
// Constants to define platform types available
var platformTypeConstants = {
"ANDROID": "android",
"IOS": "ios",
"WINDOWS": "windows"
};
var responseCodes = {
"CREATED": "Created",
"SUCCESS": "201",
"INTERNAL_SERVER_ERROR": "Internal Server Error"
};
var configParams = {
"NOTIFIER_TYPE": "notifierType",
"NOTIFIER_FREQUENCY": "notifierFrequency",
"GCM_API_KEY": "gcmAPIKey",
"GCM_SENDER_ID": "gcmSenderId",
"ANDROID_EULA": "androidEula",
"IOS_EULA": "iosEula",
"CONFIG_COUNTRY": "configCountry",
"CONFIG_STATE": "configState",
"CONFIG_LOCALITY": "configLocality",
"CONFIG_ORGANIZATION": "configOrganization",
"CONFIG_ORGANIZATION_UNIT": "configOrganizationUnit",
"MDM_CERT_PASSWORD": "MDMCertPassword",
"MDM_CERT_TOPIC_ID": "MDMCertTopicID",
"APNS_CERT_PASSWORD": "APNSCertPassword",
"MDM_CERT": "MDMCert",
"MDM_CERT_NAME": "MDMCertName",
"APNS_CERT": "APNSCert",
"APNS_CERT_NAME": "APNSCertName",
"ORG_DISPLAY_NAME": "organizationDisplayName",
"GENERAL_EMAIL_HOST": "emailHost",
"GENERAL_EMAIL_PORT": "emailPort",
"GENERAL_EMAIL_USERNAME": "emailUsername",
"GENERAL_EMAIL_PASSWORD": "emailPassword",
"GENERAL_EMAIL_SENDER_ADDRESS": "emailSender",
"GENERAL_EMAIL_TEMPLATE": "emailTemplate",
"COMMON_NAME": "commonName",
"KEYSTORE_PASSWORD": "keystorePassword",
"PRIVATE_KEY_PASSWORD": "privateKeyPassword",
"BEFORE_EXPIRE": "beforeExpire",
"AFTER_EXPIRE": "afterExpire",
"WINDOWS_EULA": "windowsLicense",
"IOS_CONFIG_MDM_MODE": "iOSConfigMDMMode",
"IOS_CONFIG_APNS_MODE": "iOSConfigAPNSMode"
};
$(document).ready(function () {
$("#gcm-inputs").hide();
tinymce.init({
selector: "textarea",
height:500,
theme: "modern",
plugins: [
"autoresize",
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime image table contextmenu paste"
],
toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
var androidConfigAPI = "/api/device-mgt/android/v1.0/configuration";
/**
* Following requests would execute
* on page load event of platform configuration page in WSO2 EMM Console.
* Upon receiving the response, the parameters will be set to the fields,
* in case those configurations are already set.
*/
invokerUtil.get(
androidConfigAPI,
function (data) {
data = JSON.parse(data);
if (data != null && data.configuration != null) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == configParams["NOTIFIER_TYPE"]) {
$("#android-config-notifier").val(config.value);
if (config.value != notifierTypeConstants["GCM"]) {
$("#gcm-inputs").hide();
$("#local-inputs").show();
} else {
$("#gcm-inputs").show();
$("#local-inputs").hide();
}
} else if (config.name == configParams["NOTIFIER_FREQUENCY"]) {
$("input#android-config-notifier-frequency").val(config.value / 1000);
} else if (config.name == configParams["GCM_API_KEY"]) {
$("input#android-config-gcm-api-key").val(config.value);
} else if (config.name == configParams["GCM_SENDER_ID"]) {
$("input#android-config-gcm-sender-id").val(config.value);
} else if (config.name == configParams["ANDROID_EULA"]) {
$("#android-eula").val(config.value);
}
}
}
}, function (data) {
console.log(data);
});
$("select.select2[multiple=multiple]").select2({
tags: true
});
$("#android-config-notifier").change(function () {
var notifierType = $("#android-config-notifier").find("option:selected").attr("value");
if (notifierType != notifierTypeConstants["GCM"]) {
$("#gcm-inputs").hide();
$("#local-inputs").show();
} else {
$("#local-inputs").hide();
$("#gcm-inputs").show();
}
});
/**
* Following click function would execute
* when a user clicks on "Save" button
* on Android platform configuration page in WSO2 EMM Console.
*/
$("button#save-android-btn").click(function () {
var notifierType = $("#android-config-notifier").find("option:selected").attr("value");
var notifierFrequency = $("input#android-config-notifier-frequency").val();
var gcmAPIKey = $("input#android-config-gcm-api-key").val();
var gcmSenderId = $("input#android-config-gcm-sender-id").val();
var androidLicense = tinyMCE.activeEditor.getContent();
var errorMsgWrapper = "#android-config-error-msg";
var errorMsg = "#android-config-error-msg span";
if (notifierType == notifierTypeConstants["LOCAL"] && !notifierFrequency) {
$(errorMsg).text("Notifier frequency is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else if (notifierType == notifierTypeConstants["LOCAL"] && !isPositiveInteger(notifierFrequency)) {
$(errorMsg).text("Provided notifier frequency is invalid. ");
$(errorMsgWrapper).removeClass("hidden");
} else if (notifierType == notifierTypeConstants["GCM"] && !gcmAPIKey) {
$(errorMsg).text("GCM API Key is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else if (notifierType == notifierTypeConstants["GCM"] && !gcmSenderId) {
$(errorMsg).text("GCM Sender ID is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else {
var addConfigFormData = {};
var configList = new Array();
var type = {
"name": configParams["NOTIFIER_TYPE"],
"value": notifierType,
"contentType": "text"
};
var frequency = {
"name": configParams["NOTIFIER_FREQUENCY"],
"value": String(notifierFrequency * 1000),
"contentType": "text"
};
var gcmKey = {
"name": configParams["GCM_API_KEY"],
"value": gcmAPIKey,
"contentType": "text"
};
var gcmId = {
"name": configParams["GCM_SENDER_ID"],
"value": gcmSenderId,
"contentType": "text"
};
var androidEula = {
"name": configParams["ANDROID_EULA"],
"value": androidLicense,
"contentType": "text"
};
configList.push(type);
configList.push(frequency);
configList.push(androidEula);
if (notifierType == notifierTypeConstants["GCM"]) {
configList.push(gcmKey);
configList.push(gcmId);
}
addConfigFormData.type = platformTypeConstants["ANDROID"];
addConfigFormData.configuration = configList;
var addConfigAPI = androidConfigAPI;
invokerUtil.put(
addConfigAPI,
addConfigFormData,
function (data, textStatus, jqXHR) {
data = JSON.parse(data);
if (jqXHR.status == 201) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
}
}, function (data) {
if (data.status == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data.status == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
}
});
});

@ -22,7 +22,7 @@
<parent>
<artifactId>android-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -463,6 +463,12 @@ public class AndroidFeatureManager implements FeatureManager {
feature.setDescription("Fetch device logcat");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("DEVICE_UNLOCK");
feature.setName("Device Unlock");
feature.setDescription("Unlock the device");
supportedFeatures.add(feature);
return supportedFeatures;
}
}

@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>mobile-plugins</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>mobile-base-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -61,7 +61,7 @@
"roleNameHelpMsg" : "should be in minimum 3 characters long and do not include any whitespaces."
},
"generalConfig" : {
"host" : "https://localhost:9443",
"host" : "%https.ip%",
"companyName" : "WSO2 Carbon Device Manager",
"browserTitle" : "WSO2 Device Manager",
"copyrightPrefix" : "\u00A9 %date-year%, ",
@ -70,17 +70,53 @@
"copyrightSuffix" : " All Rights Reserved."
},
"scopes" : [
"license-add", "license-view", "device-view",
"device-info", "device-list", "device-view-own", "device-modify", "device-search",
"operation-install", "operation-view", "operation-modify", "operation-uninstall",
"group-add", "group-share", "group-modify", "group-view", "group-remove",
"certificate-modify", "certificate-view",
"configuration-view", "configuration-modify",
"policy-view", "policy-modify",
"device-notification-view", "device-notification-modify",
"feature-view",
"roles-view", "roles-modify", "roles-remove", "roles-add",
"user-password-reset", "user-password-modify", "user-modify", "user-view", "user-invite", "user-remove", "user-add"
"user:manage",
"user:view",
"device-type:admin:view",
"device:view",
"notification:view",
"device:admin:view",
"application:manage",
"activity:view",
"user:admin:reset-password",
"policy:manage",
"policy:view",
"role:manage",
"role:view",
"configuration:view",
"configuration:modify",
"device:android:operation:reboot",
"device:android:operation:camera",
"device:android:operation:vpn",
"device:android:operation:lock",
"device:android:operation:ring",
"device:android:operation:update-app",
"device:android:operation:wipe",
"device:android:operation:encrypt",
"device:android:operation:blacklist-app",
"device:android:operation:applications",
"device:android:operation:enterprise-wipe",
"device:android:operation:info",
"device:android:operation:wifi",
"device:android:operation:uninstall-app",
"device:android:operation:change-lock",
"device:android:operation:notification",
"device:android:operation:upgrade",
"device:android:operation:unlock",
"device:android:operation:mute",
"device:android:operation:location",
"device:android:operation:webclip",
"device:android:operation:clear-password",
"device:android:operation:password-policy",
"device:android:operation:install-app",
"device:android:event:write",
"device:android:event:read",
"device:android:enroll",
"configuration:manage",
"configuration:view",
"device:android:enroll",
"certificate:view",
"certificate:manage"
],
"isOAuthEnabled" : true,
"backendRestEndpoints" : {

@ -1,4 +1,5 @@
{{unit "cdmf.unit.lib.qrcode"}}
{{unit "mdm.unit.device.qr-modal"}}
{{#zone "content"}}
{{#if permissions.VIEW_DASHBOARD}}
{{#if permissions.LIST_DEVICES}}
@ -11,7 +12,7 @@
<div class="tile-stats">
<span id="device-count" data-device-count="true">Loading...</span>
<span class="tile-stats-free">
<a id="device-count-view-btn" href="/emm/devices">
<a id="device-count-view-btn" href="{{@app.context}}/devices">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
@ -40,7 +41,7 @@
<div class="tile-stats">
<span id="policy-count" data-policy-count="true">Loading...</span>
<span class="tile-stats-free">
<a id="policy-count-view-btn" href="/emm/policies/">
<a id="policy-count-view-btn" href="{{@app.context}}/policies/">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
@ -48,7 +49,7 @@
View
</a>
{{#if permissions.ADD_POLICY}}
<a href="/emm/policy/add">
<a href="{{@app.context}}/policy/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
@ -71,7 +72,7 @@
<div class="tile-stats">
<span id="user-count" data-user-count="true">Loading...</span>
<span class="tile-stats-free">
<a id="user-count-view-btn" href="/emm/users/">
<a id="user-count-view-btn" href="{{@app.context}}/users/">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
@ -79,7 +80,7 @@
View
</a>
{{#if permissions.ADD_USER}}
<a href="/emm/user/add">
<a href="{{@app.context}}/user/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
@ -102,7 +103,7 @@
<div class="tile-stats">
<span id="role-count" data-role-count="true">Loading...</span>
<span class="tile-stats-free">
<a id="device-count-view-btn" href="/emm/roles">
<a id="device-count-view-btn" href="{{@app.context}}/roles">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
@ -110,7 +111,7 @@
View
</a>
{{#if permissions.ADD_ROLE}}
<a href="/emm/role/add">
<a href="{{@app.context}}/role/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
@ -128,23 +129,6 @@
{{else}}
Permission denied
{{/if}}
<div id="qr-code-modal" data-enrollment-url="{{enrollmentURL}}" class="hidden">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Scan QR code to start enrollment</h3>
<h4>
Please scan the QR code using your mobile device to retrieve enrollment URL.
</h4>
<div class="panel panel-default">
<div class="panel-body col-centered text-center">
<div class="qr-code"></div>
</div>
</div>
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
{{js "js/dashboard.js"}}

@ -25,6 +25,6 @@ function onRequest(context) {
viewModel.permissions = userModule.getUIPermissions();
new Log().debug("## Permissions : " + stringify(userModule.getUIPermissions()));
//TODO: Move enrollment URL into app-conf.json
viewModel.enrollmentURL = mdmProps.enrollmentUrl;
viewModel.enrollmentURL = mdmProps.generalConfig.host + mdmProps.enrollmentDir;
return viewModel;
}

@ -17,11 +17,13 @@
*/
var updateStats = function (serviceURL, id) {
//noinspection JSUnresolvedVariable invokerUtil
invokerUtil.get(
serviceURL,
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
var responsePayload = JSON.parse(data);
//noinspection JSUnresolvedVariable count
var itemCount = responsePayload.count;
if (itemCount == 0) {
$(id).html(0);
@ -42,6 +44,7 @@ var updateStats = function (serviceURL, id) {
);
};
//noinspection JSUnresolvedFunction ready
$(document).ready(function () {
if ($("#device-count").data("device-count")) {
updateStats("/api/device-mgt/v1.0/devices?offset=0&limit=1", "#device-count");

@ -0,0 +1,44 @@
{{!
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.
}}
{{unit "cdmf.unit.ui.title" pageTitle="Device Details"}}
{{unit "cdmf.unit.lib.service-invoker-utility"}}
{{unit "cdmf.unit.lib.handlebars"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/devices">
Devices
</a>
</li>
<li>
<a href="#">
Device Details
</a>
</li>
{{/zone}}
{{#zone "content"}}
{{unit "cdmf.unit.lib.data-table"}}
{{unit "cdmf.unit.device.operation-mod"}}
{{unit "cdmf.unit.device.view"}}
{{/zone}}

@ -0,0 +1,33 @@
/*
* 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.
*/
function onRequest(context){
var utility = require("/app/modules/utility.js").utility;
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
if (arguments.length < 3)
throw new Error("Handlebars Helper equal needs 2 parameters");
if( lvalue!=rvalue ) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
var deviceType = context.uriParams.deviceType;
return {"deviceViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "device-view")};
}

@ -0,0 +1,166 @@
{{!
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.
}}
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
{{unit "cdmf.unit.data-tables-extended"}}
{{unit "cdmf.unit.lib.qrcode"}}
{{unit "mdm.unit.device.qr-modal"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/devices">
Devices
</a>
</li>
{{/zone}}
{{#zone "navbarActions"}}
{{!-- #if permissions.enroll --}}
<li>
<a href="javascript:toggleEnrollment()">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-mobile fw-stack-1x"></i>
<span class="fw-stack fw-move-right fw-move-bottom">
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
</span>
Enroll Device
</a>
</li>
{{!-- /if --}}
<li>
<a href="{{appContext}}devices/search">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-mobile fw-stack-1x"></i>
<span class="fw-stack fw-move-right fw-move-bottom">
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-search fw-stack-1x"></i>
</span>
</span>
Advanced Search
</a>
</li>
{{/zone}}
{{#zone "content"}}
<span id="permission" data-permission="{{permissions}}"></span>
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading devices . . .
<br>
</div>
<div id="device-listing-status" class="raw hidden">
<ul style="list-style-type: none;">
<li class="message message-info">
<h4>
<i class="icon fw fw-info"></i>
<a id="device-listing-status-msg"></a>
</h4>
</li>
</ul>
</div>
<div id="device-table">
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view"
id="device-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th>By Device Name</th>
<th>By Owner</th>
<th>By Status</th>
<th>By Platform</th>
<th>By Ownership</th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th class="no-sort"></th>
<th data-for="By Device Name"></th>
<th data-for="By Owner" class="text-filter"></th>
<th data-for="By Status" class="select-filter"></th>
<th data-for="By Platform" class="select-filter data-platform"></th>
<th data-for="By Ownership" class="select-filter"></th>
<th class="no-sort"></th>
</tr>
<tr class="bulk-action-row hidden">
<th colspan="7">
<div id="operation-bar">
{{unit "mdm.unit.device.operation-bar"}}
</div>
<div id="operation-guide" class="bs-callout bs-callout-info">
<h4>Enabling Device Operations</h4>
<p>To enable device operations, select the desired platform from above filter.</p>
</div>
</th>
</tr>
</thead>
<tbody id="ast-container">
<br class="c-both"/>
</tbody>
</table>
</div>
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Device Name<span class="ico-sort-asc"></span></a>
<a href="#">By Owner</a>
<a href="#">By Status</a>
<a href="#">By Platform</a>
<a href="#">By Ownership</a>
</div>
</div>
<div id="no-device-view" class="ast-container list-view hidden">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h2>You don't have any device registered at the moment.</h2>
<br/>
<p class="text-center">
<a href="javascript:toggleEnrollment()" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-mobile fw-stack-1x"></i>
<span class="fw-stack fw-move-right fw-move-bottom">
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
</span>
Enroll New Device
</a>
</p>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script id="device-listing" data-current-user="{{currentUser.username}}"
data-image-resource="{{self.publicURL}}/images/"
src="{{self.publicURL}}/templates/device-listing.hbs" type="text/x-handlebars-template"></script>
{{js "js/device-listing.js"}}
{{/zone}}

@ -0,0 +1,40 @@
/*
* 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.
*/
function onRequest(context){
var userModule = require("/app/modules/business-controllers/user.js").userModule;
var constants = require("/app/modules/constants.js");
var viewModel = {};
var permissions = [];
if(userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/list")){
permissions.push("LIST_DEVICES");
if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/view")) {
permissions.push("VIEW_DEVICES");
}
}else if(userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")){
permissions.push("LIST_OWN_DEVICES");
if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/view")) {
permissions.push("VIEW_OWN_DEVICES");
}
}else if(userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")){
permissions.push("LIST_POLICIES");
}
var currentUser = session.get(constants.USER_SESSION_KEY);
viewModel.permissions = stringify(permissions);
viewModel.currentUser = currentUser;
return viewModel;
}

@ -0,0 +1,520 @@
/*
* 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.
*/
/**
* Following function would execute
* when a user clicks on the list item
* initial mode and with out select mode.
*/
function InitiateViewOption(url) {
if ($(".select-enable-btn").text() == "Select") {
$(location).attr('href', url);
}
}
(function () {
var cache = {};
var permissionSet = {};
var validateAndReturn = function (value) {
return (value == undefined || value == null) ? "Unspecified" : value;
};
Handlebars.registerHelper("deviceMap", function (device) {
device.owner = validateAndReturn(device.owner);
device.ownership = validateAndReturn(device.ownership);
var arr = device.properties;
if (arr){
device.properties = arr.reduce(function (total, current) {
total[current.name] = validateAndReturn(current.value);
return total;
}, {});
}
});
//This method is used to setup permission for device listing
$.setPermission = function (permission) {
permissionSet[permission] = true;
};
$.hasPermission = function (permission) {
return permissionSet[permission];
};
})();
/*
* Setting-up global variables.
*/
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container";
/*
* DOM ready functions.
*/
$(document).ready(function () {
/* Adding selected class for selected devices */
$(deviceCheckbox).each(function () {
addDeviceSelectedClass(this);
});
var i;
var permissionList = $("#permission").data("permission");
for (i = 0; i < permissionList.length; i++) {
$.setPermission(permissionList[i]);
}
/* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({
html : true,
content : function () {
return $("#content-filter-types").html();
}
});
$(".ast-container").on("click", ".claim-btn", function(e){
e.stopPropagation();
var deviceId = $(this).data("deviceid");
var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("current-user");
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
invokerUtil.put(serviceURL, deviceIdentifier, function(message){
console.log(message);
}, function(message){
console.log(message.content);
});
});
});
/*
* On Select All Device button click function.
*
* @param button: Select All Device button
*/
function selectAllDevices(button) {
if(!$(button).data('select')){
$(deviceCheckbox).each(function(index){
$(this).prop('checked', true);
addDeviceSelectedClass(this);
});
$(button).data('select', true);
$(button).html('Deselect All Devices');
}else{
$(deviceCheckbox).each(function(index){
$(this).prop('checked', false);
addDeviceSelectedClass(this);
});
$(button).data('select', false);
$(button).html('Select All Devices');
}
}
/*
* On listing layout toggle buttons click function.
*
* @param view: Selected view type
* @param selection: Selection button
*/
function changeDeviceView(view, selection) {
$(".view-toggle").each(function() {
$(this).removeClass("selected");
});
$(selection).addClass("selected");
if (view == "list") {
$(assetContainer).addClass("list-view");
} else {
$(assetContainer).removeClass("list-view");
}
}
/*
* Add selected style class to the parent element function.
*
* @param checkbox: Selected checkbox
*/
function addDeviceSelectedClass(checkbox) {
if ($(checkbox).is(":checked")) {
$(checkbox).closest(".ctrl-wr-asset").addClass("selected device-select");
} else {
$(checkbox).closest(".ctrl-wr-asset").removeClass("selected device-select");
}
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
function loadDevices(searchType, searchParam){
var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("currentUser");
var serviceURL;
if ($.hasPermission("LIST_DEVICES")) {
//serviceURL = "/mdm-admin/devices";
serviceURL = "/api/device-mgt/v1.0/devices";
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/devices?user="+currentUser;
//serviceURL = "/mdm-admin/users/devices?username="+currentUser;
} else {
$("#loading-content").remove();
$('#device-table').addClass('hidden');
$('#device-listing-status-msg').text('Permission denied.');
$("#device-listing-status").removeClass(' hidden');
return;
}
function getPropertyValue(deviceProperties, propertyName) {
var property;
for (var i =0; i < deviceProperties.length; i++) {
property = deviceProperties[i];
if (property.name == propertyName) {
return property.value;
}
}
return {};
}
var fnCreatedRow = function( nRow, aData, iDataIndex ) {
$(nRow).attr('data-type', 'selectable');
$(nRow).attr('data-deviceid', aData.deviceIdentifier);
$(nRow).attr('data-devicetype', aData.deviceType);
}
var columns = [
{
class : 'remove-padding icon-only content-fill viewEnabledIcon',
data : 'icon',
render: function (data, type, row, meta) {
var deviceType = row.deviceType;
var deviceIdentifier = row.deviceIdentifier;
var url = "#";
if (status != 'REMOVED') {
url = "device/" + deviceType + "?id=" + deviceIdentifier;
}
return '<div onclick="javascript:InitiateViewOption(\'' + url + '\')" class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>'
}
},{
class: 'fade-edge',
data: 'name',
render: function ( name, type, row, meta ) {
var model = row.model;
var vendor = row.vendor;
var html = '<h4>Device ' + name + '</h4>';
if (model) {
html += '<div>(' + vendor + '-' + model + ')</div>';
}
return html;
}
},{
class: 'fade-edge remove-padding-top',
data: 'owner',
render: function ( owner, type, row, meta ) {
return '<div><label class="label-bold">Owner&nbsp;:&nbsp;</label>' + owner + '</div>';
}
},{
class: 'fade-edge remove-padding-top',
data: 'status',
render: function ( status, type, row, meta ) {
var html;
switch (status) {
case 'ACTIVE' :
html = '<span><i class="fw fw-ok icon-success"></i> Active</span>';
break;
case 'INACTIVE' :
html = '<span><i class="fw fw-warning icon-warning"></i> Inactive</span>';
break;
case 'BLOCKED' :
html = '<span><i class="fw fw-remove icon-danger"></i> Blocked</span>';
break;
case 'REMOVED' :
html = '<span><i class="fw fw-delete icon-danger"></i> Removed</span>';
break;
}
return '<div><label class="label-bold">Status&nbsp;:&nbsp;</label>'+html+'</div>';
}
},{
className: 'fade-edge remove-padding-top',
data: 'deviceType',
render: function ( deviceType, type, row, meta ) {
return '<div><label class="label-bold">Type&nbsp;:&nbsp;</label>' + deviceType + '</div>';
}
},{
className: 'fade-edge remove-padding-top',
data: 'ownership',
render: function ( ownership, type, row, meta ) {
return '<div><label class="label-bold">Ownership&nbsp;:&nbsp;</label>' + ownership + '</div>';
}
}
];
var dataFilter = function(data){
data = JSON.parse(data);
var objects = [];
$(data.devices).each(function( index ) {
objects.push(
{
model: getPropertyValue(data.devices[index].properties, 'DEVICE_MODEL'),
vendor: getPropertyValue(data.devices[index].properties, 'VENDOR'),
owner: data.devices[index].enrolmentInfo.owner,
status: data.devices[index].enrolmentInfo.status,
ownership: data.devices[index].enrolmentInfo.ownership,
deviceType: data.devices[index].type,
deviceIdentifier: data.devices[index].deviceIdentifier,
name : data.devices[index].name
}
);
});
json = {
"recordsTotal": data.count,
"recordsFiltered": data.count,
"data": objects
};
return JSON.stringify( json );
};
$('#device-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/devices', dataFilter, columns, fnCreatedRow,
function( oSettings ) {
$(".icon .text").res_text(0.2);
$('#device-grid').removeClass('hidden');
$("#loading-content").remove();
}, {
"placeholder": "Search By Device Name",
"searchKey" : "name"
});
// $('#device-grid').datatables_extended({
// serverSide: true,
// processing: false,
// searching: true,
// ordering: false,
// filter: false,
// pageLength : 16,
// ajax: { url : '/emm/api/devices', data : {url : serviceURL},
// dataSrc: function (json) {
// $('#device-grid').removeClass('hidden');
// $("#loading-content").remove();
// var $list = $("#device-table :input[type='search']");
// $list.each(function(){
// $(this).addClass("hidden");
// });
// return json.devices;
// }
// },
// columnDefs: [
// { targets: 0, data: 'name', className: 'remove-padding icon-only content-fill viewEnabledIcon' , render: function ( data, type, row, meta ) {
// var deviceType = row.type;
// var deviceIdentifier = row.deviceIdentifier;
// var url = "#";
// if (status != 'REMOVED') {
// url = "devices/view?type=" + deviceType + "&id=" + deviceIdentifier;
// }
// return '<div onclick="javascript:InitiateViewOption(\'' + url + '\')" class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>';
// }},
// { targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) {
// var model = getPropertyValue(row.properties, 'DEVICE_MODEL');
// var vendor = getPropertyValue(row.properties, 'VENDOR');
// var html = '<h4>Device ' + name + '</h4>';
// if (model) {
// html += '<div>(' + vendor + '-' + model + ')</div>';
// }
// return html;
// }},
// { targets: 2, data: 'enrolmentInfo.owner', className: 'fade-edge remove-padding-top'},
// { targets: 3, data: 'enrolmentInfo.status', className: 'fade-edge remove-padding-top' ,
// render: function ( status, type, row, meta ) {
// var html;
// switch (status) {
// case 'ACTIVE' :
// html = '<span><i class="fw fw-ok icon-success"></i> Active</span>';
// break;
// case 'INACTIVE' :
// html = '<span><i class="fw fw-warning icon-warning"></i> Inactive</span>';
// break;
// case 'BLOCKED' :
// html = '<span><i class="fw fw-remove icon-danger"></i> Blocked</span>';
// break;
// case 'REMOVED' :
// html = '<span><i class="fw fw-delete icon-danger"></i> Removed</span>';
// break;
// }
// return html;
// }},
// { targets: 4, data: 'type' , className: 'fade-edge remove-padding-top' },
// { targets: 5, data: 'enrolmentInfo.ownership' , className: 'fade-edge remove-padding-top' },
// { targets: 6, data: 'enrolmentInfo.status' , className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
// render: function ( status, type, row, meta ) {
// var deviceType = row.type;
// var deviceIdentifier = row.deviceIdentifier;
// var html = '<span></span>';
// return html;
// }}
// ],
// "createdRow": function( row, data, dataIndex ) {
// $(row).attr('data-type', 'selectable');
// $(row).attr('data-deviceid', data.deviceIdentifier);
// $(row).attr('data-devicetype', data.type);
// var model = getPropertyValue(data.properties, 'DEVICE_MODEL');
// var vendor = getPropertyValue(data.properties, 'VENDOR');
// var owner = data.enrolmentInfo.owner;
// var status = data.enrolmentInfo.status;
// var ownership = data.enrolmentInfo.ownership;
// var deviceType = data.type;
// $.each($('td', row), function (colIndex) {
// switch(colIndex) {
// case 1:
// $(this).attr('data-search', model + ',' + vendor);
// $(this).attr('data-display', model);
// break;
// case 2:
// $(this).attr('data-grid-label', "Owner");
// $(this).attr('data-search', owner);
// $(this).attr('data-display', owner);
// break;
// case 3:
// $(this).attr('data-grid-label', "Status");
// $(this).attr('data-search', status);
// $(this).attr('data-display', status);
// break;
// case 4:
// $(this).attr('data-grid-label', "Type");
// $(this).attr('data-search', deviceType);
// $(this).attr('data-display', deviceType);
// break;
// case 5:
// $(this).attr('data-grid-label', "Ownership");
// $(this).attr('data-search', ownership);
// $(this).attr('data-display', ownership);
// break;
// }
// });
// },
// "fnDrawCallback": function( oSettings ) {
// $(".icon .text").res_text(0.2);
// }
// });
$(deviceCheckbox).click(function () {
addDeviceSelectedClass(this);
});
}
/*
* Setting-up global variables.
*/
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container";
function openCollapsedNav(){
$('.wr-hidden-nav-toggle-btn').addClass('active');
$('#hiddenNav').slideToggle('slideDown', function(){
if($(this).css('display') == 'none'){
$('.wr-hidden-nav-toggle-btn').removeClass('active');
}
});
}
function initPage() {
var currentUser = $("#device-listing").data("currentUser");
var serviceURL;
if ($.hasPermission("LIST_DEVICES")) {
serviceURL ="/api/device-mgt/v1.0/devices"
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/devices?user=" + currentUser;
}
invokerUtil.get(
serviceURL,
function (data) {
if (data) {
data = JSON.parse(data);
if (data.devices.length > 0) {
loadDevices();
} else {
$("#loading-content").remove();
$("#device-table").remove();
$("#no-device-view").removeClass(' hidden');
}
}
}, function (message) {
initPage();
}
);
}
/*
* DOM ready functions.
*/
$(document).ready(function () {
initPage();
/* Adding selected class for selected devices */
$(deviceCheckbox).each(function () {
addDeviceSelectedClass(this);
});
var i;
var permissionList = $("#permission").data("permission");
for (i = 0; i < permissionList.length; i++) {
$.setPermission(permissionList[i]);
}
/* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({
html : true,
content : function () {
return $("#content-filter-types").html();
}
});
$(".ast-container").on("click", ".claim-btn", function(e){
e.stopPropagation();
var deviceId = $(this).data("deviceid");
var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("current-user");
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
invokerUtil.put(serviceURL, deviceIdentifier, function(message){
console.log(message);
}, function(message){
console.log(message.content);
});
});
/* for data tables*/
$('[data-toggle="tooltip"]').tooltip();
$("[data-toggle=popover]").popover();
$(".ctrl-filter-type-switcher").popover({
html : true,
content: function() {
return $('#content-filter-types').html();
}
});
$('#nav').affix({
offset: {
top: $('header').height()
}
});
});

@ -0,0 +1,42 @@
{{#each devices}}
{{deviceMap this}}
<tr data-type="selectable" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon"
{{#unequal enrolmentInfo.status "REMOVED"}}
data-url="device?type={{type}}&id={{deviceIdentifier}}"
{{/unequal}}
>
<div class="thumbnail icon">
<i class="square-element text fw fw-mobile"></i>
</div>
</td>
<td class="fade-edge" data-search="{{properties.DEVICE_MODEL}},{{properties.VENDOR}}" data-display="{{properties.DEVICE_MODEL}}">
<h4>Device {{name}}</h4>
{{#if properties.DEVICE_MODEL}}
<div>({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})</div>
{{/if}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.owner}}" data-display="{{enrolmentInfo.owner}}" data-grid-label="Owner">{{enrolmentInfo.owner}}</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.status}}" data-display="{{enrolmentInfo.status}}" data-grid-label="Status">
{{#equal enrolmentInfo.status "ACTIVE"}}<span><i class="fw fw-ok icon-success"></i> Active</span>{{/equal}}
{{#equal enrolmentInfo.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
{{#equal enrolmentInfo.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
{{#equal enrolmentInfo.status "REMOVED"}}<span><i class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{type}}" data-display="{{type}}" data-grid-label="Type">{{type}}</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}" data-display="{{enrolmentInfo.ownership}}" data-grid-label="Ownership">{{enrolmentInfo.ownership}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<!--{{#equal type "TemperatureController"}}
{{#equal status "INACTIVE"}}
<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view claim-btn" data-deviceid="{{deviceIdentifier}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Claim</span>
</a>
{{/equal}}
{{/equal}}-->
</td>
</tr>
{{/each}}

@ -0,0 +1,643 @@
{{!
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.
}}
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
{{unit "cdmf.unit.data-tables-extended"}}
{{#zone "topCss"}}
<style>
.thumbnail.icon:before {
padding-top: 0;
}
</style>
{{/zone}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/policies">
Policies
</a>
</li>
{{/zone}}
{{#zone "navbarActions"}}
{{#if permissions.ADD_ADMIN_POLICY}}
<li>
<a href="{{@app.context}}/policy/add" class="cu-btn">
<span class="icon fw-stack">
<i class="fw fw-add fw-stack-1x"></i>
<i class="fw fw-ring fw-stack-2x"></i>
</span>
Add Policy
</a>
</li>
{{/if}}
{{#if permissions.CHANGE_POLICY_PRIORITY}}
{{#equal noPolicy false}}
<li>
<a href="{{@app.context}}/policy/priority" class="cu-btn">
<span class="icon fw-stack">
<i class="fw fw-throttling-policy fw-stack-1x"></i>
<i class="fw fw-ring fw-stack-2x"></i>
</span>
Policy Priority
</a>
</li>
{{/equal}}
{{/if}}
<li>
<a href="#" class="cu-btn" id="appbar-btn-apply-changes">
<span class="icon fw-stack">
<i class="fw fw-check fw-stack-1x"></i>
<i class="fw fw-ring fw-stack-2x"></i>
</span>
Apply Changes To Devices
</a>
</li>
{{/zone}}
{{#zone "content"}}
{{#equal isUpdated true}}
<input type="hidden" id="is-updated" value="UPDATED">
{{/equal}}
{{#equal noPolicy true}}
<div id="ast-container" class="ast-container list-view">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h2>You don't have any policy at the moment.</h2>
<br/>
{{#if permissions.ADD_ADMIN_POLICY}}
<p class="text-center">
<a href="{{@app.context}}/policy/add" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add New Policy
</a>
</p>
{{/if}}
</div>
</div>
{{/equal}}
{{#equal noPolicy false}}
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
Loading policies . . .
<br>
</div>
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
id="policy-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th class="no-sort"></th>
<th>By Platform</th>
<th>By Ownership Type</th>
<th>By Role</th>
<th>By User</th>
<th>By Compliance Type</th>
<th>By Status</th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th class="no-sort"></th>
<th class="no-sort"></th>
<th data-for="By Platform" class="select-filter"></th>
<th data-for="By Ownership Type" class="select-filter"></th>
<th data-for="By Role" class="text-filter"></th>
<th data-for="By User" class="text-filter"></th>
<th data-for="By Compliance Type" class="select-filter"></th>
<th data-for="By Status" class="select-filter"></th>
<th class="no-sort"></th>
</tr>
<tr class="bulk-action-row">
<th colspan="9">
<ul class="tiles">
{{#if removePermitted}}
<li class="square">
<a href="#" data-click-event="remove-form" class="btn square-element policy-remove-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-delete fw-stack-1x"></i>
</span>
Remove
</a>
</li>
{{/if}}
<li class="square">
<a href="#" data-click-event="remove-form" class="btn square-element policy-publish-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="glyphicon glyphicon-floppy-saved"></i>
</span>
Publish
</a>
</li>
<li class="square">
<a href="#" data-click-event="remove-form" class="btn square-element policy-unpublish-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="glyphicon glyphicon-floppy-remove"></i>
</span>
Unpublish
</a>
</li>
</ul>
</th>
</tr>
</thead>
<tbody>
{{#each policyListToView}}
<tr data-type="selectable" data-id="{{id}}" data-status="{{status}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon"
data-url="{{@app.context}}/policy/view?id={{id}}" data-id="{{id}}">
<div class="thumbnail icon">
<img src="{{icon}}"/>
</div>
</td>
<td class="fade-edge"
data-search="{{name}}"
data-display="{{name}}">
<h4>{{name}}</h4>
<div>({{platform}})</div>
{{#equal status "Active/Updated"}}
<span><i class="fw fw-warning icon-success"></i> Active/Updated</span>
{{/equal}}
{{#equal status "Active"}}
<span><i class="fw fw-ok icon-success"></i> Active</span>
{{/equal}}
{{#equal status "Inactive/Updated"}}
<span><i class="fw fw-warning icon-warning"></i> Inactive/Updated</span>
{{/equal}}
{{#equal status "Inactive"}}
<span><i class="fw fw-error icon-danger"></i> Inactive</span>
{{/equal}}
</td>
<td class="fade-edge remove-padding-top"
data-search="{{platform}}"
data-display="{{platform}}">
</td>
<td class="fade-edge remove-padding-top"
data-search="{{ownershipType}}"
data-display="{{ownershipType}}"
data-grid-label="Ownership">
{{ownershipType}}
</td>
<td id="policy-roles" class="fade-edge remove-padding-top"
data-search="{{roles}}"
data-display="{{roles}}"
data-grid-label="Role(s)">
{{roles}}
</td>
<td id="policy-users" class="fade-edge remove-padding-top"
data-search="{{users}}"
data-display="{{users}}"
data-grid-label="User(s)">
{{users}}
</td>
<td class="fade-edge remove-padding-top"
data-search="{{compliance}}"
data-display="{{compliance}}"
data-grid-label="Compliance">
{{compliance}}
</td>
<td id="policy-status" class="fade-edge remove-padding-top"
data-search="{{status}}"
data-display="{{status}}">
</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<a href="{{@app.context}}/policy/edit?id={{id}}"
data-id="{{id}}"
data-click-event="remove-form"
class="btn padding-reduce-on-grid-view policy-update-link">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Re-Configure</span>
</a>
</td>
</tr>
{{/each}}
<br class="c-both"/>
</tbody>
</table>
{{/equal}}
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Platform<span class="ico-sort-asc"></span></a>
<a href="#">By Ownership Type</a>
<a href="#">By Role</a>
<a href="#">By User</a>
<a href="#">By Compliance Type</a>
<a href="#">By Status</a>
</div>
</div>
<div id="remove-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="remove-policy-yes-link" class="btn-operations">
Remove
</a>
<a href="#" id="remove-policy-cancel-link" class="btn-operations">
Cancel
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully removed.</h3>
<div class="buttons">
<a href="#" id="remove-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="remove-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-active-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
You cannot remove policies that have been already applied to devices.
Please deselect active policies from your selection and try again.
</h3>
<div class="buttons">
<a href="#" id="remove-active-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to publish the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="publish-policy-yes-link" class="btn-operations">Yes</a>
<a href="#" id="publish-policy-cancel-link" class="btn-operations">No</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully published.</h3>
<div class="buttons">
<a href="#" id="publish-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="publish-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to unpublish the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-yes-link" class="btn-operations">
Yes
</a>
<a href="#" id="unpublish-policy-cancel-link" class="btn-operations">
No
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully unpublished.</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="save-policy-priorities-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. New Policy priorities were successfully updated.</h3>
<div class="buttons">
<a href="#" id="save-policy-priorities-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="save-policy-priorities-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<h4 class="message-from-server"></h4>
<div class="buttons">
<a href="#" id="save-policy-priorities-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to apply changes to all policies?</h3>
<div class="buttons">
<a href="#" id="change-policy-yes-link" class="btn-operations">
Yes
</a>
<a href="#" id="change-policy-cancel-link" class="btn-operations">
No
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Changes applied successfully.</h3>
<div class="buttons">
<a href="#" id="change-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="change-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyUnPublish" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Action cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to un-publish.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyUnPublishSelection" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Action cannot be performed !
</h3>
<h4>
You cannot select already inactive policies to be unpublished.
Please deselect inactive policies and try again.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="active-policy-selection-error" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Action cannot be performed !
</h3>
<h4>
You cannot select already active policies. Please deselect active policies and try again.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="policy-publish-error" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Action cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to publish.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="policy-remove-error" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Action cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to remove.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
{{js "js/policy-list.js"}}
{{/zone}}

@ -0,0 +1,59 @@
/*
* 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.
*/
function onRequest(context) {
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters");
}
if (lvalue != rvalue) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
var page = {};
var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"];
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var response = policyModule.getAllPolicies();
if (response["status"] == "success") {
var policyListToView = response["content"];
page["policyListToView"] = policyListToView;
var policyCount = policyListToView.length;
if (policyCount == 0) {
page["policyListingStatusMsg"] = "No policy is available to be displayed.";
page["noPolicy"] = true;
} else {
page["noPolicy"] = false;
page["isUpdated"] = response["updated"];
}
} else {
// here, response["status"] == "error"
page["policyListingStatusMsg"] = "An unexpected error occurred. Please try again later.";
page["noPolicy"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/remove")) {
page["removePermitted"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/update")) {
page["editPermitted"] = true;
}
page.permissions = userModule.getUIPermissions();
return page;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save