Fixing windows policy issues

revert-dabc3590
Hasunie 8 years ago
parent 95a7ff6aaf
commit 1362e2d7fe

@ -342,11 +342,10 @@ public final class PluginConstants {
} }
public static final String REQUESTED_WIN10_VERSION = "3.0"; public static final String REQUESTED_WIN10_VERSION = "3.0";
public static final String REQUESTED_WIN81_VERSION = "2.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 { public final class WindowsEnrollmentProperties {
@ -354,10 +353,10 @@ public final class PluginConstants {
throw new AssertionError(); throw new AssertionError();
} }
public static final int WIN_DEVICE_ID = 12; public static final String DEVICE_NAME = "DeviceName";
public static final int WIN_DEVICE_NAME = 2; public static final String DEVICE_VERSION = "OSVersion";
public static final int WIN_DEVICE_VERSION = 15; public static final String DEVICE_ID = "DeviceID";
public static final int WIN_DEVICE_IMEI = 3; public static final String IMEI = "MobileEquipmentId";
} }
} }

@ -243,7 +243,6 @@ public class OperationHandler {
public void updateDeviceLocationStatus(SyncmlDocument syncmlDocument) throws OperationManagementException { public void updateDeviceLocationStatus(SyncmlDocument syncmlDocument) throws OperationManagementException {
List<? extends Operation> pendingDataOperations; List<? extends Operation> pendingDataOperations;
List<StatusTag> statuses = syncmlDocument.getBody().getStatus();
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject( DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
syncmlDocument.getHeader().getSource().getLocURI()); syncmlDocument.getHeader().getSource().getLocURI());
try { try {
@ -253,13 +252,16 @@ public class OperationHandler {
} }
for (Operation operation : pendingDataOperations) { for (Operation operation : pendingDataOperations) {
if (PluginConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { if (PluginConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
for (StatusTag statusTag : statuses) { if (syncmlDocument.getBody().getResults() != null) {
if (Constants.GET.equals(statusTag.getCommand()) && statusTag.getTargetReference() != null List<ItemTag> items = syncmlDocument.getBody().getResults().getItem();
&& OperationCode.Command.LATITUDE.getCode().equals(statusTag.getTargetReference())) { for (ItemTag itemTag : items) {
if (Constants.SyncMLResponseCodes.ACCEPTED.equals(statusTag.getData())) { if (OperationCode.Command.LATITUDE.getCode().equals(itemTag.getSource().getLocURI())) {
operation.setStatus(Operation.Status.COMPLETED); // at this moment we can't get accepted value 200 from the device.
} else { if (itemTag.getData() != null) {
operation.setStatus(Operation.Status.ERROR); operation.setStatus(Operation.Status.COMPLETED);
} else {
operation.setStatus(Operation.Status.ERROR);
}
} }
} }
} }
@ -282,16 +284,13 @@ public class OperationHandler {
SyncmlBody syncmlBody = syncmlDocument.getBody(); SyncmlBody syncmlBody = syncmlDocument.getBody();
List<? extends Operation> pendingOperations; List<? extends Operation> pendingOperations;
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource().getLocURI()); DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource().getLocURI());
List<StatusTag> statuses = syncmlBody.getStatus(); if (syncmlBody.getResults() != null) {
for (StatusTag status : statuses ) { List<ItemTag> items = syncmlBody.getResults().getItem();
if (OperationCode.Command.LATITUDE.getCode().equals(status.getTargetReference()) && for (ItemTag itemTag : items) {
Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData())) { if (OperationCode.Command.LATITUDE.getCode().equals(itemTag.getSource().getLocURI())) {
updateLocation(syncmlDocument); updateLocation(syncmlDocument);
} }
if (OperationCode.Command.TOTAL_RAM.getCode().equals(itemTag.getSource().getLocURI())) {
if (OperationCode.Command.TOTAL_RAM.getCode().equals(status.getTargetReference()) &&
Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData())) {
if ((syncmlBody.getResults() != null)) {
updateDeviceInfo(syncmlDocument); updateDeviceInfo(syncmlDocument);
} }
} }
@ -377,6 +376,9 @@ public class OperationHandler {
operation.getId() == status.getCommandReference()) { operation.getId() == status.getCommandReference()) {
operation.setStatus(Operation.Status.ERROR); operation.setStatus(Operation.Status.ERROR);
} }
if (PluginConstants.OperationCodes.POLICY_REVOKE.equals(operation.getCode())) {
operation.setStatus(Operation.Status.COMPLETED);
}
} }
updateStatus(syncmlDocument.getHeader().getSource().getLocURI(), updateStatus(syncmlDocument.getHeader().getSource().getLocURI(),
pendingDataOperations); pendingDataOperations);

@ -46,7 +46,7 @@ import javax.ws.rs.core.Response;
scopes = { scopes = {
@Scope( @Scope(
name = "Pending operations", name = "Pending operations",
description = "Register an Android device", description = "Register an Windows device",
key = "perm:windows:enroll", key = "perm:windows:enroll",
permissions = {"/device-mgt/devices/enroll/windows"} permissions = {"/device-mgt/devices/enroll/windows"}
) )

@ -22,14 +22,16 @@ import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ContextItem", namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE, @XmlType(name = "ContextItem", namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE,
propOrder = {"Name", "Value"}) propOrder = {"Value"})
public class ContextItem { public class ContextItem {
@XmlAttribute(name = "Name", required = true, namespace = PluginConstants.SOAP_AUTHORIZATION_TARGET_NAMESPACE) @XmlAttribute(name = "Name")
protected String 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; protected String Value;
public String getValue() { public String getValue() {

@ -85,7 +85,6 @@ import java.util.List;
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING) @BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
public class EnrollmentServiceImpl implements EnrollmentService { public class EnrollmentServiceImpl implements EnrollmentService {
private static Log log = LogFactory.getLog(EnrollmentServiceImpl.class); private static Log log = LogFactory.getLog(EnrollmentServiceImpl.class);
private X509Certificate rootCACertificate;
private String pollingFrequency; private String pollingFrequency;
private String provisioningURL; private String provisioningURL;
private String domain; private String domain;
@ -224,7 +223,7 @@ public class EnrollmentServiceImpl implements EnrollmentService {
CertificateManagementServiceImpl certMgtServiceImpl = CertificateManagementServiceImpl.getInstance(); CertificateManagementServiceImpl certMgtServiceImpl = CertificateManagementServiceImpl.getInstance();
Base64 base64Encoder = new Base64(); Base64 base64Encoder = new Base64();
try { try {
rootCACertificate = (X509Certificate) certMgtServiceImpl.getCACertificate(); X509Certificate rootCACertificate = (X509Certificate) certMgtServiceImpl.getCACertificate();
rootCertEncodedString = base64Encoder.encodeAsString(rootCACertificate.getEncoded()); rootCertEncodedString = base64Encoder.encodeAsString(rootCACertificate.getEncoded());
@ -353,8 +352,7 @@ public class EnrollmentServiceImpl implements EnrollmentService {
*/ */
private String getRequestedUser(String bst) { private String getRequestedUser(String bst) {
CacheEntry cacheEntry = (CacheEntry) DeviceUtil.getCacheEntry(bst); CacheEntry cacheEntry = (CacheEntry) DeviceUtil.getCacheEntry(bst);
String userName = cacheEntry.getUsername(); return cacheEntry.getUsername();
return userName;
} }
/** /**
@ -413,16 +411,18 @@ public class EnrollmentServiceImpl implements EnrollmentService {
MOBILE_DEVICE_TYPE_WINDOWS); MOBILE_DEVICE_TYPE_WINDOWS);
windowsDevice.setUser(getRequestedUser(headerBinarySecurityToken)); windowsDevice.setUser(getRequestedUser(headerBinarySecurityToken));
List<ContextItem> contextItems = requestContextItems.getcontextitem(); List<ContextItem> contextItems = requestContextItems.getcontextitem();
for (int x = 0; x < contextItems.size(); x++) { for(ContextItem contextItem : contextItems) {
switch (x) { if (PluginConstants.WindowsEnrollmentProperties.DEVICE_ID.equals(contextItem.getName())) {
case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_NAME: windowsDevice.setDeviceId(contextItem.getValue());
windowsDevice.setDeviceName(contextItems.get(x).getValue()); }
case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_IMEI: if (PluginConstants.WindowsEnrollmentProperties.DEVICE_NAME.equals(contextItem.getName())) {
windowsDevice.setImei(contextItems.get(x).getValue()); windowsDevice.setDeviceName(contextItem.getValue());
case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_ID: }
windowsDevice.setDeviceId(contextItems.get(x).getValue()); if (PluginConstants.WindowsEnrollmentProperties.IMEI.equals(contextItem.getName())) {
case PluginConstants.WindowsEnrollmentProperties.WIN_DEVICE_VERSION: windowsDevice.setImei(contextItem.getValue());
windowsDevice.setOsVersion(contextItems.get(x).getValue()); }
if (PluginConstants.WindowsEnrollmentProperties.DEVICE_VERSION.equals(contextItem.getName())) {
windowsDevice.setOsVersion(contextItem.getValue());
} }
} }
Device device = generateDevice(windowsDevice); Device device = generateDevice(windowsDevice);

@ -20,6 +20,8 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.w3c.dom.Document; 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.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
@ -39,6 +41,16 @@ import javax.ws.rs.core.Response;
*/ */
@Path("/devicemanagement") @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 { public interface SyncmlService {
@Path("/request") @Path("/request")

@ -3,12 +3,13 @@
<inSequence> <inSequence>
<property name="api.ut.backendRequestTime" expression="get-property('SYSTEM_TIME')"/> <property name="api.ut.backendRequestTime" expression="get-property('SYSTEM_TIME')"/>
<property name="AM_KEY_TYPE" value="PRODUCTION" scope="default"/> <property name="AM_KEY_TYPE" value="PRODUCTION" scope="default"/>
<property name="uri.var.portnum" expression="get-property('system','iot.core.https.port')"/>
<property name="uri.var.hostname" expression="get-property('system','iot.core.host')"/>
<filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION"> <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
<then> <then>
<send> <send>
<endpoint name="admin--Windows 10 Device management_APIproductionEndpoint_0"> <endpoint name="admin--Windows 10 Device management_APIproductionEndpoint_0">
<http uri-template="https://localhost:9443/api/device-mgt/windows/v1.0/management/devicemgt"/> <http uri-template="https://{uri.var.hostname}:{uri.var.portnum}/api/device-mgt/windows/v1.0/management/devicemgt"/>
<property name="ENDPOINT_ADDRESS" value="https://localhost:9443/api/device-mgt/windows/v1.0/management/devicemgt"/>
</endpoint> </endpoint>
</send> </send>
</then> </then>

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><api xmlns="http://ws.apache.org/ns/synapse" name="admin--Windows 8.1 Device Management Service" context="/api/device-mgt/windows/v1.0/syncml"> <?xml version="1.0" encoding="UTF-8"?><api xmlns="http://ws.apache.org/ns/synapse" name="admin--Windows 8.1 Device Management Service" context="/api/device-mgt/windows/v1.0/syncml/devicemanagement">
<resource methods="HEAD DELETE POST GET OPTIONS PATCH PUT" url-mapping="/*" faultSequence="fault"> <resource methods="HEAD DELETE POST GET OPTIONS PATCH PUT" url-mapping="/*" faultSequence="fault">
<inSequence> <inSequence>
<property name="isDefault" expression="$trp:WSO2_AM_API_DEFAULT_VERSION"/> <property name="isDefault" expression="$trp:WSO2_AM_API_DEFAULT_VERSION"/>
<property name="AM_KEY_TYPE" value="PRODUCTION" scope="default"/>
<filter source="$ctx:isDefault" regex="true"> <filter source="$ctx:isDefault" regex="true">
<then> <then>
<log level="custom"> <log level="custom">
@ -33,7 +34,7 @@
<property name="uri.var.portnum" expression="get-property('http.nio.port')"/> <property name="uri.var.portnum" expression="get-property('http.nio.port')"/>
<send> <send>
<endpoint> <endpoint>
<http uri-template="http://localhost:{uri.var.portnum}/api/device-mgt/windows/v1.0/syncml/1.0.0"> <http uri-template="http://localhost:{uri.var.portnum}/api/device-mgt/windows/v1.0/syncml/devicemanagement/1.0.0">
<timeout> <timeout>
<duration>60000</duration> <duration>60000</duration>
<responseAction>fault</responseAction> <responseAction>fault</responseAction>
@ -45,6 +46,8 @@
</filter> </filter>
</inSequence> </inSequence>
<outSequence> <outSequence>
<property name="FORCE_HTTP_CONTENT_LENGTH" scope="axis2" value="true"/>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"/>
<send/> <send/>
</outSequence> </outSequence>
</resource> </resource>

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?><api xmlns="http://ws.apache.org/ns/synapse" name="admin--Windows 8.1 Device Management Service" context="/api/device-mgt/windows/v1.0/syncml/1.0.0" version="1.0.0" version-type="context"> <?xml version="1.0" encoding="UTF-8"?><api xmlns="http://ws.apache.org/ns/synapse" name="admin--Windows 8.1 Device Management Service" context="/api/device-mgt/windows/v1.0/syncml/devicemanagement/1.0.0" version="1.0.0" version-type="context">
<resource methods="POST" url-mapping="/request" faultSequence="fault"> <resource methods="POST" url-mapping="/request" faultSequence="fault">
<inSequence> <inSequence>
<property name="api.ut.backendRequestTime" expression="get-property('SYSTEM_TIME')"/> <property name="api.ut.backendRequestTime" expression="get-property('SYSTEM_TIME')"/>
@ -7,8 +7,7 @@
<then> <then>
<send> <send>
<endpoint name="admin--Windows 8.1 Device Management Service_APIproductionEndpoint_0"> <endpoint name="admin--Windows 8.1 Device Management Service_APIproductionEndpoint_0">
<http uri-template="https://localhost:9443/api/device-mgt/windows/v1.0/syncml"/> <http uri-template="https://localhost:9443/api/device-mgt/windows/v1.0/syncml/devicemanagement"/>
<property name="ENDPOINT_ADDRESS" value="https://localhost:9443/api/device-mgt/windows/v1.0/syncml"/>
</endpoint> </endpoint>
</send> </send>
</then> </then>
@ -19,6 +18,8 @@
</inSequence> </inSequence>
<outSequence> <outSequence>
<class name="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtResponseHandler"/> <class name="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtResponseHandler"/>
<property name="FORCE_HTTP_CONTENT_LENGTH" scope="axis2" value="true"/>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"/>
<send/> <send/>
</outSequence> </outSequence>
</resource> </resource>

@ -2,6 +2,7 @@
<resource methods="HEAD DELETE POST GET OPTIONS PATCH PUT" url-mapping="/*" faultSequence="fault"> <resource methods="HEAD DELETE POST GET OPTIONS PATCH PUT" url-mapping="/*" faultSequence="fault">
<inSequence> <inSequence>
<property name="isDefault" expression="$trp:WSO2_AM_API_DEFAULT_VERSION"/> <property name="isDefault" expression="$trp:WSO2_AM_API_DEFAULT_VERSION"/>
<property name="AM_KEY_TYPE" value="PRODUCTION" scope="default"/>
<filter source="$ctx:isDefault" regex="true"> <filter source="$ctx:isDefault" regex="true">
<then> <then>
<log level="custom"> <log level="custom">
@ -45,6 +46,8 @@
</filter> </filter>
</inSequence> </inSequence>
<outSequence> <outSequence>
<property name="FORCE_HTTP_CONTENT_LENGTH" scope="axis2" value="true"/>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"/>
<send/> <send/>
</outSequence> </outSequence>
</resource> </resource>

@ -8,7 +8,7 @@
<send> <send>
<endpoint name="admin--Windows 8.1 Enrollment Service_APIproductionEndpoint_0"> <endpoint name="admin--Windows 8.1 Enrollment Service_APIproductionEndpoint_0">
<http uri-template="https://localhost:9443/api/device-mgt/windows/v1.0/deviceenrolment/wstep"/> <http uri-template="https://localhost:9443/api/device-mgt/windows/v1.0/deviceenrolment/wstep"/>
<property name="ENDPOINT_ADDRESS" value="https://localhost:9443/api/device-mgt/windows/v1.0/deviceenrolment/wstep"/> <!--property name="ENDPOINT_ADDRESS" value="https://localhost:9443/api/device-mgt/windows/v1.0/deviceenrolment/wstep"/-->
</endpoint> </endpoint>
</send> </send>
</then> </then>
@ -19,6 +19,8 @@
</inSequence> </inSequence>
<outSequence> <outSequence>
<class name="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtResponseHandler"/> <class name="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtResponseHandler"/>
<property name="FORCE_HTTP_CONTENT_LENGTH" scope="axis2" value="true"/>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"/>
<send/> <send/>
</outSequence> </outSequence>
</resource> </resource>

@ -46,7 +46,7 @@
</inSequence> </inSequence>
<outSequence> <outSequence>
<property name="FORCE_HTTP_CONTENT_LENGTH" scope="axis2" value="true"/> <property name="FORCE_HTTP_CONTENT_LENGTH" scope="axis2" value="true"/>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"/> <property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"/>
<send/> <send/>
</outSequence> </outSequence>
</resource> </resource>

Loading…
Cancel
Save