diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java index 93469177a1..319acca3c8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java @@ -65,7 +65,7 @@ public interface DeviceManagerService { * @return Status of enrollment * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device */ - boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException; + boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; /** * Method to retrieve the status of a particular device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index 1d541a7da1..a7c6ef8154 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -84,10 +84,10 @@ public class DeviceManager implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isRegistered(deviceId); + return dms.isEnrolled(deviceId); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 5a30f8cd75..d7508fb784 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -46,8 +46,8 @@ public class DeviceManagementService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isRegistered(deviceId); + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java index 59f44f9283..648fd2c92b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java @@ -50,7 +50,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java index 4baee059dd..a458b59529 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java @@ -50,7 +50,7 @@ public class IOSDeviceManagerService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java index b144670b5f..1cc845faaa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java @@ -50,7 +50,7 @@ public class WindowsDeviceManagerService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; } diff --git a/product/modules/agents/android/jax-rs/pom.xml b/product/modules/agents/android/jax-rs/pom.xml index 190d08ff6b..744ae057a2 100644 --- a/product/modules/agents/android/jax-rs/pom.xml +++ b/product/modules/agents/android/jax-rs/pom.xml @@ -19,10 +19,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - org.wso2.carbon - wso2cdm-parent + org.wso2.cdmserver + wso2cdmserver-product 2.0.0-SNAPSHOT - ../../../../../pom.xml + ../../../../pom.xml 4.0.0 @@ -47,7 +47,7 @@ maven-war-plugin 2.2 - + WEB-INF/lib/*cxf*.jar ${project.artifactId} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index a78f8051c4..866bae0cf2 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -21,10 +21,12 @@ import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.ws.rs.*; import javax.ws.rs.core.Response; @@ -36,66 +38,133 @@ import javax.ws.rs.core.Response; public class Enrollment { private static Log log = LogFactory.getLog(Enrollment.class); + @POST public Response enrollDevice() { - JsonObject result = new JsonObject(); - result.addProperty("senderId","jwwfowrjwqporqwrpqworpq"); - CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); - Device device = AndroidAPIUtil.convertToDeviceObject(result); + boolean result = false; + int status = 0; + String msg = ""; + DeviceManagementService dmService; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + Device device = AndroidAPIUtil.convertToDeviceObject(null); try { - dmService.enrollDevice(device); + result = dmService.enrollDevice(device); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while enrolling the device"; + msg = "Error occurred while enrolling the device"; log.error(msg, e); + status = -1; } - return Response.status(201).entity("Registration Successful").build(); + switch (status) { + case 1: + if (result) { + return Response.status(201).entity("Registration Successful").build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); + } + return Response.status(400).entity("Registration Failed").build(); } @GET @Path("{id}") public Response isEnrolled(@PathParam("id") String id) { - boolean status = false; + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); try { DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); - status = dmService.isRegistered(deviceIdentifier); + result = dmService.isEnrolled(deviceIdentifier); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while checking enrollment of the device"; + msg = "Error occurred while checking enrollment of the device"; log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(200).entity(result).build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); } - return Response.status(200).entity(status).build(); + return Response.status(404).entity(result).build(); } @PUT @Consumes("application/json") @Path("{id}") public Response modifyEnrollment(@PathParam("id") String id) { - boolean status = false; + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); + Device device = AndroidAPIUtil.convertToDeviceObject(null); try { - status = dmService.isRegistered(null); + result = dmService.modifyEnrollment(device); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while modifying enrollment of the device"; + msg = "Error occurred while modifying enrollment of the device"; log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(200).entity("Device information modified").build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); } - return Response.status(201).entity(status).build(); + return Response.status(400).entity("Update enrollment failed").build(); } @DELETE @Path("{id}") public Response disenrollDevice(@PathParam("id") String id) { - boolean status = false; + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); try { - status = dmService.isRegistered(null); + DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); + result = dmService.disenrollDevice(deviceIdentifier); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while disenrolling the device"; + msg = "Error occurred while disenrolling the device"; log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(200).entity(result).build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); } - return Response.status(201).entity(status).build(); + return Response.status(404).entity("Device not found").build(); } } diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 2b569559c3..eee52239eb 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -323,12 +323,12 @@ wso2cdm-${project.version}/repository/conf/multitenancy/ true - + src/repository/conf/application-authenticators.xml wso2cdm-${project.version}/repository/conf/security/ diff --git a/product/pom.xml b/product/pom.xml index ecd5db07f4..c9fbafc3d0 100644 --- a/product/pom.xml +++ b/product/pom.xml @@ -34,6 +34,7 @@ WSO2 Connected Device Manager (CDM) - Parent + modules/p2-profile-gen modules/distribution modules/integration