From eb8dad1af7509a8927b04474b25992ba37acbd4e Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 11:33:54 +0530 Subject: [PATCH 1/7] resolved wso2/product-iots#1428 --- .../windows/api/common/PluginConstants.java | 2 + .../windows/api/operations/ChallengeTag.java | 3 +- .../windows/api/operations/StatusTag.java | 12 ++++ .../api/operations/util/Constants.java | 1 + .../api/operations/util/OperationHandler.java | 51 ++++++++++++++-- .../api/operations/util/OperationReply.java | 16 ++++- .../impl/EnrollmentServiceImpl.java | 21 ++++++- .../impl/DeviceManagementServiceImpl.java | 58 +++++++++++++------ .../services/syncml/beans/WindowsDevice.java | 9 +++ .../main/resources/win10-wap-provisioning.xml | 6 +- .../mobile/windows/impl/dto/MobileDevice.java | 1 + 11 files changed, 149 insertions(+), 31 deletions(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java index 7ef3f6498..e82d55057 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java @@ -207,6 +207,7 @@ public final class PluginConstants { public static final String MANUFACTURER = "MANUFACTURER"; public static final String LANGUAGE = "LANGUAGE"; public static final String RESOLUTION = "RESOLUTION"; + public static final String WINDOWS_TYPE = "WINDOWS_TYPE"; // windows 10 codes public static final String TOTAL_RAM = "TOTAL_RAM";// available ram in MB @@ -357,6 +358,7 @@ public final class PluginConstants { public static final String DEVICE_VERSION = "OSVersion"; public static final String DEVICE_ID = "DeviceID"; public static final String IMEI = "MobileEquipmentId"; + public static final String TYPE = "DeviceType"; } } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java index e2c1fe6b4..341f819ae 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java @@ -38,9 +38,10 @@ public class ChallengeTag { public void buildChallengeElement(Document doc, Element rootElement) { Element challenge = doc.createElement(Constants.CHALLENGE); - rootElement.appendChild(challenge); + if (getMeta() != null) { getMeta().buildMetaElement(doc, challenge); } + rootElement.appendChild(challenge); } } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java index b83fe5c04..157ff3411 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java @@ -43,6 +43,16 @@ public class StatusTag { this.targetReference = targetReference; this.data = data; } + public StatusTag(int commandId, int messageReference, int commandReference, String command, + ChallengeTag challengeTag, String targetReference, String data) { + this.commandId = commandId; + this.messageReference = messageReference; + this.commandReference = commandReference; + this.command = command; + this.challenge = challengeTag; + this.targetReference = targetReference; + this.data = data; + } public StatusTag() { } @@ -132,8 +142,10 @@ public class StatusTag { status.appendChild(targetReference); } if (getChallenge() != null) { + getChallenge().buildChallengeElement(doc, status); } + if (getData() != null) { Element data = doc.createElement(Constants.DATA); data.appendChild(doc.createTextNode(getData())); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/Constants.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/Constants.java index b20f31baa..b0d3fb85d 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/Constants.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/Constants.java @@ -87,6 +87,7 @@ public class Constants { public final class SyncMLResponseCodes { public static final String AUTHENTICATION_ACCEPTED = "212"; public static final String ACCEPTED = "200"; + public static final String UNAUTHORIZED = "401"; public static final String ACCEPTED_FOR_PROCESSING = "202"; public static final String PIN_NOTFOUND = "405"; public static final String LOCK_RESET_NOTIFICATION = "Error occurred in Device Lock Operation. " + diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java index 25f963ab3..6c7c48f7f 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java @@ -22,7 +22,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; @@ -32,15 +31,21 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; 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.common.policy.mgt.ProfileFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.StatusTag; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlDocument; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlHeader; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.ItemTag; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.WindowsOperationException; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.ResultsTag; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.SyncmlBody; import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.Profile; -import org.wso2.carbon.device.mgt.mobile.windows.api.operations.*; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; -import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; -import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import java.util.ArrayList; import java.util.List; @@ -226,6 +231,22 @@ public class OperationHandler { } } + public void updateDisenrollOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { + List pendingDeviceInfoOperations; + try { + pendingDeviceInfoOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier); + } catch (DeviceManagementException e) { + throw new OperationManagementException("Error occurred while getting pending operations."); + } + for (Operation operation : pendingDeviceInfoOperations) { + if (PluginConstants.OperationCodes.DISENROLL.equals(operation.getCode())) { + operation.setStatus(Operation.Status.COMPLETED); + updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations); + } + } + + } + public void updateDeviceInfoStatus(DeviceIdentifier deviceIdentifier) throws OperationManagementException { List pendingDeviceInfoOperations; @@ -294,6 +315,9 @@ public class OperationHandler { if (OperationCode.Command.TOTAL_RAM.getCode().equals(itemTag.getSource().getLocURI())) { updateDeviceInfo(syncmlDocument); } + if (OperationCode.Command.BATTERY_CHARGE_REMAINING.equals(itemTag.getSource().getLocURI())) { + updateDeviceInfo(syncmlDocument); + } } } UpdateUriOperations(syncmlDocument); @@ -562,6 +586,7 @@ public class OperationHandler { String totalRAM; String deviceID = null; String totalStorage; + Double battery; List deviceInformations = syncmlDocument.getBody().getResults().getItem(); DeviceInfo deviceInfo = new DeviceInfo(); @@ -598,6 +623,10 @@ public class OperationHandler { if (OperationCode.Info.DEV_ID.getCode().equals(source)) { deviceID = item.getData(); } + if (OperationCode.Info.BATTERY_CHARGE_REMAINING.getCode().equals(source)) { + battery = Double.valueOf(item.getData()); + deviceInfo.setBatteryLevel(battery); + } } DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(deviceID); try { @@ -636,6 +665,18 @@ public class OperationHandler { } catch (OperationManagementException e) { throw new WindowsOperationException("Error occurred while updating Device Location operation status."); } + } + + public void checkForDeviceWipe(List pendingDeviceInfoOperations + , DeviceIdentifier deviceIdentifier) throws OperationManagementException { + + for (Operation operation : pendingDeviceInfoOperations) { + if (PluginConstants.OperationCodes.WIPE_DATA.equals(operation.getCode())) { + operation.setStatus(Operation.Status.COMPLETED); + updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations); + } + } } } + diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java index 9fbb4f27d..ae2a768b7 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java @@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.operations.util; import com.google.gson.Gson; import org.json.JSONException; import org.json.JSONObject; +import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; @@ -159,17 +161,25 @@ public class OperationReply { } private SyncmlBody generateStatuses() { + SyncmlBody sourceSyncmlBody = syncmlDocument.getBody(); SyncmlHeader sourceHeader = syncmlDocument.getHeader(); StatusTag headerStatus; + ChallengeTag challengeTag; + challengeTag = new ChallengeTag(); + MetaTag metaTag = new MetaTag(); + metaTag.setFormat("b64"); + metaTag.setType("syncml:auth-md5"); + metaTag.setNextNonce("ZHVtbXk="); + challengeTag.setMeta(metaTag); SyncmlBody syncmlBodyReply = new SyncmlBody(); List statuses = new ArrayList<>(); List sourceStatuses = sourceSyncmlBody.getStatus(); if (sourceStatuses.isEmpty()) { headerStatus = new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID, - HEADER_COMMAND_TEXT, sourceHeader.getSource().getLocURI(), - String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED)); + HEADER_COMMAND_TEXT, challengeTag,sourceHeader.getSource().getLocURI(), + String.valueOf(Constants.SyncMLResponseCodes.UNAUTHORIZED)); statuses.add(headerStatus); } else { for (StatusTag sourceStatus : sourceStatuses) { @@ -177,7 +187,7 @@ public class OperationReply { headerStatus = new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID, - HEADER_COMMAND_TEXT, sourceHeader.getSource().getLocURI(), + HEADER_COMMAND_TEXT, challengeTag, sourceHeader.getSource().getLocURI(), String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED)); statuses.add(headerStatus); } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java index ee3d62c9c..814a7d0ef 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.impl; +import com.google.gson.Gson; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.logging.Log; @@ -40,6 +41,7 @@ import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WAPProvis import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.DeviceUtil; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils; +import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.DeviceInfo; import org.wso2.carbon.device.mgt.mobile.windows.api.operations.util.SyncmlCredentialUtil; import org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.EnrollmentService; import org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.beans.*; @@ -368,7 +370,7 @@ public class EnrollmentServiceImpl implements EnrollmentService { * @return Value added Device. */ private Device generateDevice(WindowsDevice windowsDevice) { - + Gson gson = new Gson(); Device generatedDevice = new Device(); Device.Property OSVersionProperty = new Device.Property(); @@ -383,15 +385,28 @@ public class EnrollmentServiceImpl implements EnrollmentService { IMEIProperty.setName(PluginConstants.SyncML.IMEI); IMEIProperty.setValue(windowsDevice.getImei()); + Device.Property deviceInfoProperties = new Device.Property(); + deviceInfoProperties.setName(PluginConstants.WindowsEnrollmentProperties.TYPE); + deviceInfoProperties.setValue(windowsDevice.getWindowsType()); + String deviceInfo = gson.toJson(deviceInfoProperties); + + + Device.Property winDeviceType = new Device.Property(); + winDeviceType.setName(PluginConstants.SyncML.DEVICE_INFO); + winDeviceType.setValue(deviceInfo); + + List propertyList = new ArrayList<>(); propertyList.add(OSVersionProperty); propertyList.add(IMSEIProperty); propertyList.add(IMEIProperty); + propertyList.add(winDeviceType); EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); enrolmentInfo.setOwner(windowsDevice.getUser()); enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + generatedDevice.setEnrolmentInfo(enrolmentInfo); generatedDevice.setDeviceIdentifier(windowsDevice.getDeviceId()); @@ -430,9 +445,13 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (PluginConstants.WindowsEnrollmentProperties.DEVICE_VERSION.equals(contextItem.getName())) { windowsDevice.setOsVersion(contextItem.getValue()); } + if (PluginConstants.WindowsEnrollmentProperties.TYPE.equals(contextItem.getName())) { + windowsDevice.setWindowsType(contextItem.getValue()); + } } Device device = generateDevice(windowsDevice); WindowsAPIUtils.getDeviceManagementService().enrollDevice(device); + PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService(); policyManagerService.getEffectivePolicy(new DeviceIdentifier(windowsDevice.getDeviceId(), device.getType())); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java index 8dd5f93cb..cfccd5e13 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java @@ -87,39 +87,60 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if ((PluginConstants.SyncML.SYNCML_FIRST_MESSAGE_ID == msgId) && (PluginConstants.SyncML.SYNCML_FIRST_SESSION_ID == sessionId)) { - token = syncmlHeader.getCredential().getData(); - MobileCacheEntry cacheToken = DeviceUtil.getTokenEntry(token); - DeviceUtil.persistChallengeToken(token, deviceIdentifier.getId(), user); - PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - carbonCtx.setTenantId(cacheToken.getTenanatID(), true); + if (syncmlHeader.getCredential() != null) { + token = syncmlHeader.getCredential().getData(); - if ((cacheToken.getUsername() != null) && (cacheToken.getUsername().equals(user))) { + MobileCacheEntry cacheToken = DeviceUtil.getTokenEntry(token); + DeviceUtil.persistChallengeToken(token, deviceIdentifier.getId(), user); + PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonCtx.setTenantId(cacheToken.getTenanatID(), true); - if (modifyEnrollWithMoreDetail(request, cacheToken.getTenantDomain(), cacheToken.getTenanatID())) { - pendingOperations = operationHandler.getPendingOperations(syncmlDocument); - response = operationReply.generateReply(syncmlDocument, pendingOperations); - return Response.status(Response.Status.OK).entity(response).build(); + if ((cacheToken.getUsername() != null) && (cacheToken.getUsername().equals(user))) { + + if (modifyEnrollWithMoreDetail(request, cacheToken.getTenantDomain(), cacheToken.getTenanatID())) { + pendingOperations = operationHandler.getPendingOperations(syncmlDocument); + operationHandler.checkForDeviceWipe(pendingOperations, deviceIdentifier); + response = operationReply.generateReply(syncmlDocument, pendingOperations); + return Response.status(Response.Status.OK).entity(response).build(); + + } else { + String msg = "Error occurred in while modify the enrollment."; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } } else { - String msg = "Error occurred in while modify the enrollment."; + String msg = "Authentication failure due to incorrect credentials."; log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build(); } + } else { - String msg = "Authentication failure due to incorrect credentials."; - log.error(msg); - return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build(); + return Response.ok().entity(operationReply.generateReply(syncmlDocument, null)).build(); } } else { - MobileCacheEntry cacheToken = DeviceUtil.getTokenEntryFromDeviceId(deviceIdentifier.getId()); - PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - carbonCtx.setTenantId(cacheToken.getTenanatID()); + if (DeviceUtil.getTokenEntryFromDeviceId(deviceIdentifier.getId()) == null) { + if (syncmlHeader.getCredential() != null) { + token = syncmlHeader.getCredential().getData(); + + MobileCacheEntry cacheToken = DeviceUtil.getTokenEntry(token); + DeviceUtil.persistChallengeToken(token, deviceIdentifier.getId(), user); + PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonCtx.setTenantId(cacheToken.getTenanatID(), true); + } + } else { + MobileCacheEntry cacheToken = DeviceUtil.getTokenEntryFromDeviceId(deviceIdentifier.getId()); + PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonCtx.setTenantId(cacheToken.getTenanatID()); + } if ((syncmlDocument.getBody().getAlert() != null)) { if (!syncmlDocument.getBody().getAlert().getData().equals(Constants.DISENROLL_ALERT_DATA)) { pendingOperations = operationHandler.getPendingOperations(syncmlDocument); + operationHandler.checkForDeviceWipe(pendingOperations, deviceIdentifier); return Response.ok().entity(operationReply.generateReply( syncmlDocument, pendingOperations)).build(); } else { if (WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false) != null) { + operationHandler.updateDisenrollOperation(deviceIdentifier); WindowsAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); return Response.ok().entity(operationReply.generateReply(syncmlDocument, null)).build(); } else { @@ -130,6 +151,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } else { pendingOperations = operationHandler.getPendingOperations(syncmlDocument); + operationHandler.checkForDeviceWipe(pendingOperations, deviceIdentifier); return Response.ok().entity(operationReply.generateReply( syncmlDocument, pendingOperations)).build(); } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/syncml/beans/WindowsDevice.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/syncml/beans/WindowsDevice.java index 272b7875a..4bafbf22c 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/syncml/beans/WindowsDevice.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/syncml/beans/WindowsDevice.java @@ -32,6 +32,15 @@ public class WindowsDevice { private String model; private String user; private String deviceName; + private String windowsType; + + public String getWindowsType() { + return windowsType; + } + + public void setWindowsType(String windowsType) { + this.windowsType = windowsType; + } public String getImei() { return imei; diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/resources/win10-wap-provisioning.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/resources/win10-wap-provisioning.xml index 5d305a243..fdbd89938 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/resources/win10-wap-provisioning.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/resources/win10-wap-provisioning.xml @@ -29,7 +29,7 @@ - + @@ -42,8 +42,8 @@ - - + + diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java index 77b70de3b..7618ab85f 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java @@ -39,6 +39,7 @@ public class MobileDevice implements Serializable { private String serial; private String osBuildDate; + private Map deviceProperties; public MobileDevice() { From 475513bcc260bd56f661d01cbfd1bb6bb0d5ce70 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 11:52:30 +0530 Subject: [PATCH 2/7] fixing formatting issues --- .../windows/api/operations/util/OperationReply.java | 9 ++++----- .../device/mgt/mobile/windows/impl/dto/MobileDevice.java | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java index ae2a768b7..0d8252dee 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java @@ -165,12 +165,11 @@ public class OperationReply { SyncmlBody sourceSyncmlBody = syncmlDocument.getBody(); SyncmlHeader sourceHeader = syncmlDocument.getHeader(); StatusTag headerStatus; - ChallengeTag challengeTag; - challengeTag = new ChallengeTag(); + ChallengeTag challengeTag = new ChallengeTag(); MetaTag metaTag = new MetaTag(); - metaTag.setFormat("b64"); - metaTag.setType("syncml:auth-md5"); - metaTag.setNextNonce("ZHVtbXk="); + metaTag.setFormat(Constants.CRED_FORMAT); + metaTag.setType(Constants.CRED_TYPE); + metaTag.setNextNonce(Constants.INITIAL_NONCE); challengeTag.setMeta(metaTag); SyncmlBody syncmlBodyReply = new SyncmlBody(); List statuses = new ArrayList<>(); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java index 7618ab85f..77b70de3b 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dto/MobileDevice.java @@ -39,7 +39,6 @@ public class MobileDevice implements Serializable { private String serial; private String osBuildDate; - private Map deviceProperties; public MobileDevice() { From 60cf41150d414d2accb121b82a529752c91afb02 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 12:22:04 +0530 Subject: [PATCH 3/7] fixing speace issues --- .../device/mgt/mobile/windows/api/operations/ChallengeTag.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java index 341f819ae..c47649ce2 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/ChallengeTag.java @@ -38,7 +38,6 @@ public class ChallengeTag { public void buildChallengeElement(Document doc, Element rootElement) { Element challenge = doc.createElement(Constants.CHALLENGE); - if (getMeta() != null) { getMeta().buildMetaElement(doc, challenge); } From 792cfeea79c8a92a428ab4190bb08ac0fd9bc124 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 12:24:46 +0530 Subject: [PATCH 4/7] removing unused variables --- .../device/mgt/mobile/windows/api/common/PluginConstants.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java index e82d55057..302fd5b92 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java @@ -207,7 +207,6 @@ public final class PluginConstants { public static final String MANUFACTURER = "MANUFACTURER"; public static final String LANGUAGE = "LANGUAGE"; public static final String RESOLUTION = "RESOLUTION"; - public static final String WINDOWS_TYPE = "WINDOWS_TYPE"; // windows 10 codes public static final String TOTAL_RAM = "TOTAL_RAM";// available ram in MB From eed8293ea5425809332e279a23197a82565ec368 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 12:33:23 +0530 Subject: [PATCH 5/7] fixing formatting issues --- .../mobile/windows/api/operations/util/OperationHandler.java | 2 +- .../api/services/enrollment/impl/EnrollmentServiceImpl.java | 3 --- .../windows/api/services/impl/DeviceManagementServiceImpl.java | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java index 6c7c48f7f..0cc07df23 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java @@ -231,7 +231,7 @@ public class OperationHandler { } } - public void updateDisenrollOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { + public void updateDisenrollOperationStatus(DeviceIdentifier deviceIdentifier) throws OperationManagementException { List pendingDeviceInfoOperations; try { pendingDeviceInfoOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java index 814a7d0ef..c8205c7e1 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java @@ -390,12 +390,10 @@ public class EnrollmentServiceImpl implements EnrollmentService { deviceInfoProperties.setValue(windowsDevice.getWindowsType()); String deviceInfo = gson.toJson(deviceInfoProperties); - Device.Property winDeviceType = new Device.Property(); winDeviceType.setName(PluginConstants.SyncML.DEVICE_INFO); winDeviceType.setValue(deviceInfo); - List propertyList = new ArrayList<>(); propertyList.add(OSVersionProperty); propertyList.add(IMSEIProperty); @@ -407,7 +405,6 @@ public class EnrollmentServiceImpl implements EnrollmentService { enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); - generatedDevice.setEnrolmentInfo(enrolmentInfo); generatedDevice.setDeviceIdentifier(windowsDevice.getDeviceId()); generatedDevice.setProperties(propertyList); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java index cfccd5e13..1525566b4 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java @@ -140,7 +140,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { syncmlDocument, pendingOperations)).build(); } else { if (WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false) != null) { - operationHandler.updateDisenrollOperation(deviceIdentifier); + operationHandler.updateDisenrollOperationStatus(deviceIdentifier); WindowsAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); return Response.ok().entity(operationReply.generateReply(syncmlDocument, null)).build(); } else { From 70f971cc26b0075ef35a77a228dd16529e4cb927 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 12:37:16 +0530 Subject: [PATCH 6/7] resolved code issues --- .../api/services/enrollment/impl/EnrollmentServiceImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java index c8205c7e1..e7cd34494 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java @@ -201,7 +201,6 @@ public class EnrollmentServiceImpl implements EnrollmentService { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(DOMSource, streamResult); - return stringWriter.toString(); } @@ -448,7 +447,6 @@ public class EnrollmentServiceImpl implements EnrollmentService { } Device device = generateDevice(windowsDevice); WindowsAPIUtils.getDeviceManagementService().enrollDevice(device); - PolicyManagerService policyManagerService = WindowsAPIUtils.getPolicyManagerService(); policyManagerService.getEffectivePolicy(new DeviceIdentifier(windowsDevice.getDeviceId(), device.getType())); From 54e5fad42a89f4d18f9e42639d278ce57b4ac647 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 29 Sep 2017 13:42:58 +0530 Subject: [PATCH 7/7] fixing formatting issues --- .../mgt/mobile/windows/api/common/PluginConstants.java | 2 -- .../mgt/mobile/windows/api/operations/StatusTag.java | 4 +--- .../windows/api/operations/util/OperationHandler.java | 4 ---- .../windows/api/operations/util/OperationReply.java | 3 --- .../services/enrollment/impl/EnrollmentServiceImpl.java | 4 ---- .../api/services/impl/DeviceManagementServiceImpl.java | 9 +-------- 6 files changed, 2 insertions(+), 24 deletions(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java index 302fd5b92..897a7d2bb 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java @@ -352,12 +352,10 @@ public final class PluginConstants { private WindowsEnrollmentProperties() { throw new AssertionError(); } - public static final String DEVICE_NAME = "DeviceName"; public static final String DEVICE_VERSION = "OSVersion"; public static final String DEVICE_ID = "DeviceID"; public static final String IMEI = "MobileEquipmentId"; public static final String TYPE = "DeviceType"; - } } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java index 157ff3411..4c82b8a56 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/StatusTag.java @@ -43,6 +43,7 @@ public class StatusTag { this.targetReference = targetReference; this.data = data; } + public StatusTag(int commandId, int messageReference, int commandReference, String command, ChallengeTag challengeTag, String targetReference, String data) { this.commandId = commandId; @@ -142,15 +143,12 @@ public class StatusTag { status.appendChild(targetReference); } if (getChallenge() != null) { - getChallenge().buildChallengeElement(doc, status); } - if (getData() != null) { Element data = doc.createElement(Constants.DATA); data.appendChild(doc.createTextNode(getData())); status.appendChild(data); } } - } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java index 0cc07df23..fd5cf76eb 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationHandler.java @@ -244,10 +244,8 @@ public class OperationHandler { updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations); } } - } - public void updateDeviceInfoStatus(DeviceIdentifier deviceIdentifier) throws OperationManagementException { List pendingDeviceInfoOperations; try { @@ -669,14 +667,12 @@ public class OperationHandler { public void checkForDeviceWipe(List pendingDeviceInfoOperations , DeviceIdentifier deviceIdentifier) throws OperationManagementException { - for (Operation operation : pendingDeviceInfoOperations) { if (PluginConstants.OperationCodes.WIPE_DATA.equals(operation.getCode())) { operation.setStatus(Operation.Status.COMPLETED); updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations); } } - } } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java index 0d8252dee..389dd0cdc 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/operations/util/OperationReply.java @@ -161,7 +161,6 @@ public class OperationReply { } private SyncmlBody generateStatuses() { - SyncmlBody sourceSyncmlBody = syncmlDocument.getBody(); SyncmlHeader sourceHeader = syncmlDocument.getHeader(); StatusTag headerStatus; @@ -183,7 +182,6 @@ public class OperationReply { } else { for (StatusTag sourceStatus : sourceStatuses) { if (sourceStatus.getChallenge() != null && HEADER_COMMAND_TEXT.equals(sourceStatus.getCommand())) { - headerStatus = new StatusTag(headerCommandId, sourceHeader.getMsgID(), HEADER_STATUS_ID, HEADER_COMMAND_TEXT, challengeTag, sourceHeader.getSource().getLocURI(), @@ -239,7 +237,6 @@ public class OperationReply { private void appendOperations(SyncmlBody syncmlBody) throws PolicyManagementException, FeatureManagementException, JSONException, SyncmlOperationException { - GetTag getElement = new GetTag(); List getElements = new ArrayList<>(); List executeElements = new ArrayList<>(); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java index e7cd34494..558cd601b 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/enrollment/impl/EnrollmentServiceImpl.java @@ -100,7 +100,6 @@ public class EnrollmentServiceImpl implements EnrollmentService { AdditionalContext additionalContext, Holder response) throws WindowsDeviceEnrolmentException, UnsupportedEncodingException, WAPProvisioningException { - String headerBinarySecurityToken = null; String headerTo = null; String encodedWap; @@ -221,14 +220,12 @@ public class EnrollmentServiceImpl implements EnrollmentService { String signedCertEncodedString; X509Certificate signedCertificate; String provisioningXmlString; - CertificateManagementServiceImpl certMgtServiceImpl = CertificateManagementServiceImpl.getInstance(); Base64 base64Encoder = new Base64(); try { X509Certificate rootCACertificate = (X509Certificate) certMgtServiceImpl.getCACertificate(); rootCertEncodedString = base64Encoder.encodeAsString(rootCACertificate.getEncoded()); - signedCertificate = certMgtServiceImpl.getSignedCertificateFromCSR(binarySecurityToken); signedCertEncodedString = base64Encoder.encodeAsString(signedCertificate.getEncoded()); @@ -313,7 +310,6 @@ public class EnrollmentServiceImpl implements EnrollmentService { Node pollValue = pollingAttributes.getNamedItem(PluginConstants.CertificateEnrolment.VALUE); pollValue.setTextContent(pollingFrequency); provisioningXmlString = convertDocumentToString(document); - } catch (ParserConfigurationException e) { throw new WAPProvisioningException("Problem occurred while creating configuration request", e); } catch (CertificateEncodingException e) { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java index 1525566b4..5b8d52a44 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementServiceImpl.java @@ -89,20 +89,16 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { (PluginConstants.SyncML.SYNCML_FIRST_SESSION_ID == sessionId)) { if (syncmlHeader.getCredential() != null) { token = syncmlHeader.getCredential().getData(); - MobileCacheEntry cacheToken = DeviceUtil.getTokenEntry(token); DeviceUtil.persistChallengeToken(token, deviceIdentifier.getId(), user); PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); carbonCtx.setTenantId(cacheToken.getTenanatID(), true); - if ((cacheToken.getUsername() != null) && (cacheToken.getUsername().equals(user))) { - if (modifyEnrollWithMoreDetail(request, cacheToken.getTenantDomain(), cacheToken.getTenanatID())) { pendingOperations = operationHandler.getPendingOperations(syncmlDocument); operationHandler.checkForDeviceWipe(pendingOperations, deviceIdentifier); response = operationReply.generateReply(syncmlDocument, pendingOperations); return Response.status(Response.Status.OK).entity(response).build(); - } else { String msg = "Error occurred in while modify the enrollment."; log.error(msg); @@ -113,7 +109,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { log.error(msg); return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build(); } - } else { return Response.ok().entity(operationReply.generateReply(syncmlDocument, null)).build(); } @@ -121,7 +116,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (DeviceUtil.getTokenEntryFromDeviceId(deviceIdentifier.getId()) == null) { if (syncmlHeader.getCredential() != null) { token = syncmlHeader.getCredential().getData(); - MobileCacheEntry cacheToken = DeviceUtil.getTokenEntry(token); DeviceUtil.persistChallengeToken(token, deviceIdentifier.getId(), user); PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); @@ -193,7 +187,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { boolean status = false; String user; SyncmlDocument syncmlDocument; - try { syncmlDocument = SyncmlParser.parseSyncmlPayload(request); ReplaceTag replace = syncmlDocument.getBody().getReplace(); @@ -218,7 +211,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { Device existingDevice = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); if (!existingDevice.getProperties().isEmpty()) { List existingProperties = new ArrayList<>(); - + Device.Property vendorProperty = new Device.Property(); vendorProperty.setName(PluginConstants.SyncML.VENDOR); vendorProperty.setValue(devMan);