From 1362e2d7fe3b03021b039dda3379e19b03301426 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Wed, 18 Jan 2017 18:03:28 +0530 Subject: [PATCH] Fixing windows policy issues --- .../windows/api/common/PluginConstants.java | 11 +++--- .../api/operations/util/OperationHandler.java | 38 ++++++++++--------- .../api/services/DeviceManagementService.java | 2 +- .../enrollment/beans/ContextItem.java | 8 ++-- .../impl/EnrollmentServiceImpl.java | 28 +++++++------- .../api/services/syncml/SyncmlService.java | 12 ++++++ ...n--Windows_10_Device_management_v1.0.0.xml | 5 ++- ...-Windows_8.1_Device_Management_Service.xml | 7 +++- ...s_8.1_Device_Management_Service_v1.0.0.xml | 7 ++-- .../admin--Windows_8.1_Enrollment_Service.xml | 3 ++ ...-Windows_8.1_Enrollment_Service_v1.0.0.xml | 4 +- ...min--Windows_Enrollment_policy_Service.xml | 2 +- 12 files changed, 76 insertions(+), 51 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 bebdafe00..7ef3f6498 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 @@ -342,11 +342,10 @@ public final class PluginConstants { } public static final String REQUESTED_WIN10_VERSION = "3.0"; public static final String REQUESTED_WIN81_VERSION = "2.0"; - public static final String OS_VERSION = "10"; } /** - * Windows enrollment property constants. + * Windows10 enrollment property constants. */ public final class WindowsEnrollmentProperties { @@ -354,10 +353,10 @@ public final class PluginConstants { throw new AssertionError(); } - public static final int WIN_DEVICE_ID = 12; - public static final int WIN_DEVICE_NAME = 2; - public static final int WIN_DEVICE_VERSION = 15; - public static final int WIN_DEVICE_IMEI = 3; + 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"; } } 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 877093c63..ed90bd456 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 @@ -243,7 +243,6 @@ public class OperationHandler { public void updateDeviceLocationStatus(SyncmlDocument syncmlDocument) throws OperationManagementException { List pendingDataOperations; - List statuses = syncmlDocument.getBody().getStatus(); DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject( syncmlDocument.getHeader().getSource().getLocURI()); try { @@ -253,13 +252,16 @@ public class OperationHandler { } for (Operation operation : pendingDataOperations) { if (PluginConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { - for (StatusTag statusTag : statuses) { - if (Constants.GET.equals(statusTag.getCommand()) && statusTag.getTargetReference() != null - && OperationCode.Command.LATITUDE.getCode().equals(statusTag.getTargetReference())) { - if (Constants.SyncMLResponseCodes.ACCEPTED.equals(statusTag.getData())) { - operation.setStatus(Operation.Status.COMPLETED); - } else { - operation.setStatus(Operation.Status.ERROR); + if (syncmlDocument.getBody().getResults() != null) { + List items = syncmlDocument.getBody().getResults().getItem(); + for (ItemTag itemTag : items) { + if (OperationCode.Command.LATITUDE.getCode().equals(itemTag.getSource().getLocURI())) { + // at this moment we can't get accepted value 200 from the device. + if (itemTag.getData() != null) { + operation.setStatus(Operation.Status.COMPLETED); + } else { + operation.setStatus(Operation.Status.ERROR); + } } } } @@ -282,16 +284,13 @@ public class OperationHandler { SyncmlBody syncmlBody = syncmlDocument.getBody(); List pendingOperations; DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource().getLocURI()); - List statuses = syncmlBody.getStatus(); - for (StatusTag status : statuses ) { - if (OperationCode.Command.LATITUDE.getCode().equals(status.getTargetReference()) && - Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData())) { - updateLocation(syncmlDocument); - } - - if (OperationCode.Command.TOTAL_RAM.getCode().equals(status.getTargetReference()) && - Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData())) { - if ((syncmlBody.getResults() != null)) { + if (syncmlBody.getResults() != null) { + List items = syncmlBody.getResults().getItem(); + for (ItemTag itemTag : items) { + if (OperationCode.Command.LATITUDE.getCode().equals(itemTag.getSource().getLocURI())) { + updateLocation(syncmlDocument); + } + if (OperationCode.Command.TOTAL_RAM.getCode().equals(itemTag.getSource().getLocURI())) { updateDeviceInfo(syncmlDocument); } } @@ -377,6 +376,9 @@ public class OperationHandler { operation.getId() == status.getCommandReference()) { operation.setStatus(Operation.Status.ERROR); } + if (PluginConstants.OperationCodes.POLICY_REVOKE.equals(operation.getCode())) { + operation.setStatus(Operation.Status.COMPLETED); + } } updateStatus(syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations); 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/DeviceManagementService.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/DeviceManagementService.java index 602403cd6..bbfda4355 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/DeviceManagementService.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/DeviceManagementService.java @@ -46,7 +46,7 @@ import javax.ws.rs.core.Response; scopes = { @Scope( name = "Pending operations", - description = "Register an Android device", + description = "Register an Windows device", key = "perm:windows:enroll", permissions = {"/device-mgt/devices/enroll/windows"} ) 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/beans/ContextItem.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/beans/ContextItem.java index 68fac756c..8c5cfd482 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/beans/ContextItem.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/beans/ContextItem.java @@ -22,14 +22,16 @@ import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; import javax.xml.bind.annotation.*; +@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "ContextItem", namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE, - propOrder = {"Name", "Value"}) + propOrder = {"Value"}) public class ContextItem { - @XmlAttribute(name = "Name", required = true, namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE) + @XmlAttribute(name = "Name") protected String Name; - @XmlElement(name = "Value", required = true, namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE) + @XmlElement(name = "Value", required = true, + namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE) protected String Value; public String getValue() { 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 d59243549..d45455f0c 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 @@ -85,7 +85,6 @@ import java.util.List; @BindingType(value = SOAPBinding.SOAP12HTTP_BINDING) public class EnrollmentServiceImpl implements EnrollmentService { private static Log log = LogFactory.getLog(EnrollmentServiceImpl.class); - private X509Certificate rootCACertificate; private String pollingFrequency; private String provisioningURL; private String domain; @@ -224,7 +223,7 @@ public class EnrollmentServiceImpl implements EnrollmentService { CertificateManagementServiceImpl certMgtServiceImpl = CertificateManagementServiceImpl.getInstance(); Base64 base64Encoder = new Base64(); try { - rootCACertificate = (X509Certificate) certMgtServiceImpl.getCACertificate(); + X509Certificate rootCACertificate = (X509Certificate) certMgtServiceImpl.getCACertificate(); rootCertEncodedString = base64Encoder.encodeAsString(rootCACertificate.getEncoded()); @@ -353,8 +352,7 @@ public class EnrollmentServiceImpl implements EnrollmentService { */ private String getRequestedUser(String bst) { CacheEntry cacheEntry = (CacheEntry) DeviceUtil.getCacheEntry(bst); - String userName = cacheEntry.getUsername(); - return userName; + return cacheEntry.getUsername(); } /** @@ -413,16 +411,18 @@ public class EnrollmentServiceImpl implements EnrollmentService { MOBILE_DEVICE_TYPE_WINDOWS); windowsDevice.setUser(getRequestedUser(headerBinarySecurityToken)); List contextItems = requestContextItems.getcontextitem(); - for (int x = 0; x < contextItems.size(); x++) { - switch (x) { - case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_NAME: - windowsDevice.setDeviceName(contextItems.get(x).getValue()); - case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_IMEI: - windowsDevice.setImei(contextItems.get(x).getValue()); - case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_ID: - windowsDevice.setDeviceId(contextItems.get(x).getValue()); - case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_VERSION: - windowsDevice.setOsVersion(contextItems.get(x).getValue()); + for(ContextItem contextItem : contextItems) { + if (PluginConstants.WindowsEnrollmentProperties.DEVICE_ID.equals(contextItem.getName())) { + windowsDevice.setDeviceId(contextItem.getValue()); + } + if (PluginConstants.WindowsEnrollmentProperties.DEVICE_NAME.equals(contextItem.getName())) { + windowsDevice.setDeviceName(contextItem.getValue()); + } + if (PluginConstants.WindowsEnrollmentProperties.IMEI.equals(contextItem.getName())) { + windowsDevice.setImei(contextItem.getValue()); + } + if (PluginConstants.WindowsEnrollmentProperties.DEVICE_VERSION.equals(contextItem.getName())) { + windowsDevice.setOsVersion(contextItem.getValue()); } } Device device = generateDevice(windowsDevice); 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/SyncmlService.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/SyncmlService.java index d165763ae..d92b52e65 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/SyncmlService.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/SyncmlService.java @@ -20,6 +20,8 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml; import io.swagger.annotations.*; import org.w3c.dom.Document; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; @@ -39,6 +41,16 @@ import javax.ws.rs.core.Response; */ @Path("/devicemanagement") +@Scopes( + scopes = { + @Scope( + name = "Pending operations", + description = "Register an Windows device", + key = "perm:windows:enroll", + permissions = {"/device-mgt/devices/enroll/windows"} + ) + } +) public interface SyncmlService { @Path("/request") diff --git a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_10_Device_management_v1.0.0.xml b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_10_Device_management_v1.0.0.xml index dfbbd89b3..a63d36bd0 100644 --- a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_10_Device_management_v1.0.0.xml +++ b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_10_Device_management_v1.0.0.xml @@ -3,12 +3,13 @@ + + - - + diff --git a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service.xml b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service.xml index e8756d3bd..82148f1cb 100644 --- a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service.xml +++ b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service.xml @@ -1,7 +1,8 @@ - + + @@ -33,7 +34,7 @@ - + 60000 fault @@ -45,6 +46,8 @@ + + diff --git a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service_v1.0.0.xml b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service_v1.0.0.xml index af46dfc72..18dac5d58 100644 --- a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service_v1.0.0.xml +++ b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Device_Management_Service_v1.0.0.xml @@ -1,4 +1,4 @@ - + @@ -7,8 +7,7 @@ - - + @@ -19,6 +18,8 @@ + + diff --git a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service.xml b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service.xml index 57c18f375..805bfdb94 100644 --- a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service.xml +++ b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service.xml @@ -2,6 +2,7 @@ + @@ -45,6 +46,8 @@ + + diff --git a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service_v1.0.0.xml b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service_v1.0.0.xml index 74724bd8c..a935972c0 100644 --- a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service_v1.0.0.xml +++ b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_8.1_Enrollment_Service_v1.0.0.xml @@ -8,7 +8,7 @@ - + @@ -19,6 +19,8 @@ + + diff --git a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_Enrollment_policy_Service.xml b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_Enrollment_policy_Service.xml index 9e2e438d6..6514bdb26 100644 --- a/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_Enrollment_policy_Service.xml +++ b/features/mobile-plugins-feature/windows-plugin-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/apis/admin--Windows_Enrollment_policy_Service.xml @@ -46,7 +46,7 @@ - +