Merge pull request #501 from ayyoob/release-3.0.x

made policy manager to be part of device mgt service
revert-dabc3590
Rasika Perera 8 years ago committed by GitHub
commit 81c62b3a13

@ -28,18 +28,10 @@
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
</web-app>

@ -28,19 +28,11 @@
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
</web-app>

@ -28,19 +28,11 @@
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
</web-app>

@ -34,9 +34,5 @@
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
</web-app>

@ -28,19 +28,11 @@
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
</web-app>

@ -39,7 +39,7 @@ import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
import org.wso2.carbon.mdm.services.android.util.Message;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.validation.Valid;

@ -47,6 +47,7 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
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.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
@ -55,7 +56,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.ws.rs.core.MediaType;
@ -275,7 +276,8 @@ public class AndroidAPIUtils {
if (log.isDebugEnabled()) {
log.info("Received compliance status from MONITOR operation ID: " + operation.getId());
}
getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getPayLoad());
getPolicyManagerService().checkPolicyCompliance(deviceIdentifier,
getComplianceFeatures(operation.getPayLoad()));
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
OperationCodes.APPLICATION_LIST.equals(operation.getCode())) {
if (log.isDebugEnabled()) {
@ -493,4 +495,29 @@ public class AndroidAPIUtils {
}
return "";
}
private static List<ComplianceFeature> getComplianceFeatures(Object compliancePayload) throws PolicyComplianceException {
String compliancePayloadString = new Gson().toJson(compliancePayload);
if (compliancePayload == null) {
return null;
}
// Parsing json string to get compliance features.
JsonElement jsonElement;
if (compliancePayloadString instanceof String) {
jsonElement = new JsonParser().parse(compliancePayloadString);
} else {
throw new PolicyComplianceException("Invalid policy compliance payload");
}
JsonArray jsonArray = jsonElement.getAsJsonArray();
Gson gson = new Gson();
ComplianceFeature complianceFeature;
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>(jsonArray.size());
for (JsonElement element : jsonArray) {
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
complianceFeatures.add(complianceFeature);
}
return complianceFeatures;
}
}

@ -51,10 +51,6 @@
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<context-param>
<param-name>doAuthentication</param-name>
<param-value>true</param-value>

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.mobile.android.impl.util.AndroidPluginConstants;
@ -47,6 +48,7 @@ public class AndroidDeviceManagementService implements DeviceManagementService {
private static final String NOTIFIER_PROPERTY = "notifierType";
private static final String GCM_API_KEY = "gcmAPIKey";
private static final String GCM_SENDER_ID = "gcmSenderId";
private PolicyMonitoringManager policyMonitoringManager;
@Override
public String getType() {
@ -61,6 +63,7 @@ public class AndroidDeviceManagementService implements DeviceManagementService {
@Override
public void init() throws DeviceManagementException {
this.deviceManager = new AndroidDeviceManager();
this.policyMonitoringManager = new AndroidPolicyMonitoringManager();
}
@Override
@ -105,6 +108,11 @@ public class AndroidDeviceManagementService implements DeviceManagementService {
return null;
}
@Override
public PolicyMonitoringManager getPolicyMonitoringManager() {
return policyMonitoringManager;
}
private String getConfigProperty(List<ConfigurationEntry> configs, String propertyName) {
for (ConfigurationEntry entry : configs) {
if (propertyName.equals(entry.getName())) {

@ -25,39 +25,27 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.mobile.android.impl.gcm.GCMService;
import org.wso2.carbon.device.mgt.mobile.android.internal.AndroidDeviceManagementDataHolder;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
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;
public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
public class AndroidPolicyMonitoringManager implements PolicyMonitoringManager {
private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class);
private static Log log = LogFactory.getLog(AndroidPolicyMonitoringManager.class);
@Override
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
GCMService gcmService = AndroidDeviceManagementDataHolder.getInstance().getGCMService();
if (gcmService.isGCMEnabled() && !list.isEmpty()) {
gcmService.sendNotification("POLICY_BUNDLE", list);
}
}
@Override
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy,
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy,
Object compliancePayload) throws PolicyComplianceException {
if (log.isDebugEnabled()) {
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
}
ComplianceData complianceData = new ComplianceData();
NonComplianceData complianceData = new NonComplianceData();
if (compliancePayload == null || policy == null) {
return complianceData;
}
@ -93,8 +81,4 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
return complianceData;
}
@Override
public String getType() {
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
}
}

@ -25,10 +25,8 @@ import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.mobile.android.impl.AndroidDeviceManagementService;
import org.wso2.carbon.device.mgt.mobile.android.impl.AndroidPolicyMonitoringService;
import org.wso2.carbon.device.mgt.mobile.android.impl.gcm.GCMService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.registry.core.service.RegistryService;
/**
@ -75,8 +73,8 @@ public class AndroidDeviceManagementServiceComponent {
// Policy management service
bundleContext.registerService(PolicyMonitoringService.class,
new AndroidPolicyMonitoringService(), null);
// bundleContext.registerService(PolicyMonitoringManager.class,
// new AndroidPolicyMonitoringManager(), null);
AndroidDeviceManagementDataHolder.getInstance().setAndroidDeviceManagementService(
androidDeviceManagementService);

@ -35,9 +35,9 @@ import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils
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.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
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;

@ -33,7 +33,7 @@ import org.wso2.carbon.device.mgt.mobile.windows.api.services.syncml.beans.Wifi;
import org.wso2.carbon.device.mgt.mobile.windows.api.operations.*;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.ArrayList;
import java.util.List;

@ -56,10 +56,6 @@
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<context-param>
<param-name>doAuthentication</param-name>
<param-value>true</param-value>

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -34,6 +35,7 @@ public class WindowsDeviceManagementService implements DeviceManagementService {
private DeviceManager deviceManager;
public static final String DEVICE_TYPE_WINDOWS = "windows";
private final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super";
private PolicyMonitoringManager policyMonitoringManager;
@Override
public String getType() {
@ -48,6 +50,7 @@ public class WindowsDeviceManagementService implements DeviceManagementService {
@Override
public void init() throws DeviceManagementException {
this.deviceManager = new WindowsDeviceManager();
this.policyMonitoringManager = new WindowsPolicyMonitoringManager();
}
@Override
@ -70,4 +73,9 @@ public class WindowsDeviceManagementService implements DeviceManagementService {
return null;
}
@Override
public PolicyMonitoringManager getPolicyMonitoringManager() {
return policyMonitoringManager;
}
}

@ -20,36 +20,29 @@ package org.wso2.carbon.device.mgt.mobile.windows.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
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;
public class WindowsPolicyMonitoringService implements PolicyMonitoringService {
public class WindowsPolicyMonitoringManager implements PolicyMonitoringManager {
private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class);
private static Log log = LogFactory.getLog(WindowsPolicyMonitoringManager.class);
@Override
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
}
@Override
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload)
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload)
throws PolicyComplianceException {
if (log.isDebugEnabled()) {
log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
}
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) compliancePayload;
List<ComplianceFeature> nonComplianceFeatures = new ArrayList<>();
ComplianceData complianceData = new ComplianceData();
NonComplianceData complianceData = new NonComplianceData();
if (policy == null || compliancePayload == null) {
return complianceData;
@ -66,8 +59,4 @@ public class WindowsPolicyMonitoringService implements PolicyMonitoringService {
return complianceData;
}
@Override
public String getType() {
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
}
}

@ -23,11 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsDeviceManagementService;
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsPolicyMonitoringService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.registry.core.service.RegistryService;
/**
@ -67,8 +63,8 @@ public class WindowsDeviceManagementServiceComponent {
// Policy management service
bundleContext.registerService(PolicyMonitoringService.class,
new WindowsPolicyMonitoringService(), null);
// bundleContext.registerService(PolicyMonitoringManager.class,
// new WindowsPolicyMonitoringManager(), null);
if (log.isDebugEnabled()) {
log.debug("Android Mobile Device Management Service Component has been successfully activated");

@ -253,11 +253,11 @@
</propertyDef>
</properties>
</adviceFile>
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.android:${carbon.devicemgt.plugins.version}
</bundleDef>
</bundles>
<!--<bundles>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.android:${carbon.devicemgt.plugins.version}-->
<!--</bundleDef>-->
<!--</bundles>-->
<importFeatures>
<importFeatureDef>
org.wso2.carbon.core.server:${carbon.kernel.version}

@ -348,4 +348,5 @@
</Operation>
</Operations>
</TaskConfiguration>
<PolicyMonitoring enabled="true"/>
</DeviceTypeConfiguration>

@ -202,11 +202,11 @@
</propertyDef>
</properties>
</adviceFile>
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.windows:${carbon.devicemgt.plugins.version}
</bundleDef>
</bundles>
<!--<bundles>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.windows:${carbon.devicemgt.plugins.version}-->
<!--</bundleDef>-->
<!--</bundles>-->
<importFeatures>
<importFeatureDef>
org.wso2.carbon.core.server:${carbon.kernel.version}

@ -124,4 +124,6 @@
<authorizationRequired>false</authorizationRequired>
</DeviceAuthorizationConfig>
<PolicyMonitoring enabled="true"/>
</DeviceTypeConfiguration>

Loading…
Cancel
Save