Merged with local changes

revert-70aa11f8
mharindu 10 years ago
commit 0a671373e5

@ -24,13 +24,6 @@ import java.util.List;
* device type plugin implementation intended to be managed through CDM. * device type plugin implementation intended to be managed through CDM.
*/ */
public interface DeviceManager { public interface DeviceManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getProviderType();
/** /**
* Method to return feature manager implementation associated with a particular platform-specific plugin. * Method to return feature manager implementation associated with a particular platform-specific plugin.
* *

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.mgt.common.spi; package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
@ -25,6 +26,19 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
* Composite interface that acts as the SPI exposing all device management as well as application management * Composite interface that acts as the SPI exposing all device management as well as application management
* functionalities * functionalities
*/ */
public interface DeviceManagementService extends DeviceManager, ApplicationManager { public interface DeviceManagementService extends ApplicationManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getType();
void init() throws DeviceManagementException;
DeviceManager getDeviceManager();
ApplicationManager getApplicationManager();
} }

@ -34,8 +34,10 @@ public class DeviceManagementPluginRepository {
} }
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getType();
try { try {
/* Initializing Device Management Service Provider */
provider.init();
DeviceManagerUtil.registerDeviceType(deviceType); DeviceManagerUtil.registerDeviceType(deviceType);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new DeviceManagementException("Error occurred while adding device management provider '" + throw new DeviceManagementException("Error occurred while adding device management provider '" +
@ -45,7 +47,7 @@ public class DeviceManagementPluginRepository {
} }
public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getType();
providers.remove(deviceType); providers.remove(deviceType);
} }

@ -203,7 +203,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
pluginRepository.addDeviceManagementProvider(deviceManagementService); pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" + log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }
@ -213,7 +213,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
pluginRepository.removeDeviceManagementProvider(deviceManagementService); pluginRepository.removeDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" + log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }
} }

@ -242,7 +242,7 @@ public class DeviceManagementServiceComponent {
protected void setDeviceManagementService(DeviceManagementService deviceManagementService) { protected void setDeviceManagementService(DeviceManagementService deviceManagementService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" + log.debug("Setting Device Management Service Provider: '" +
deviceManagementService.getProviderType() + "'"); deviceManagementService.getType() + "'");
} }
synchronized (LOCK) { synchronized (LOCK) {
deviceManagers.add(deviceManagementService); deviceManagers.add(deviceManagementService);
@ -260,7 +260,7 @@ public class DeviceManagementServiceComponent {
protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) { protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Un setting Device Management Service Provider : '" + log.debug("Un setting Device Management Service Provider : '" +
deviceManagementService.getProviderType() + "'"); deviceManagementService.getType() + "'");
} }
for (PluginInitializationListener listener : listeners) { for (PluginInitializationListener listener : listeners) {
listener.unregisterDeviceManagementService(deviceManagementService); listener.unregisterDeviceManagementService(deviceManagementService);

@ -21,7 +21,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -68,11 +67,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementServiceComponent.registerPluginInitializationListener(this); DeviceManagementServiceComponent.registerPluginInitializationListener(this);
} }
@Override
public String getProviderType() {
return null;
}
@Override @Override
public FeatureManager getFeatureManager() { public FeatureManager getFeatureManager() {
return null; return null;
@ -81,14 +75,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public FeatureManager getFeatureManager(String type) { public FeatureManager getFeatureManager(String type) {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(type); this.getPluginRepository().getDeviceManagementService(type).getDeviceManager();
return dms.getFeatureManager(); return dms.getFeatureManager();
} }
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.enrollDevice(device); boolean status = dms.enrollDevice(device);
try { try {
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) { if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) {
@ -134,7 +128,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.modifyEnrollment(device); boolean status = dms.modifyEnrollment(device);
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -167,7 +161,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
try { try {
Device device = deviceDAO.getDevice(deviceId,tenantId); Device device = deviceDAO.getDevice(deviceId,tenantId);
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType()); DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
@ -188,14 +182,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isEnrolled(deviceId); return dms.isEnrolled(deviceId);
} }
@Override @Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isActive(deviceId); return dms.isActive(deviceId);
} }
@ -203,7 +197,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public boolean setActive(DeviceIdentifier deviceId, boolean status) public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException { throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.setActive(deviceId, status); return dms.setActive(deviceId, status);
} }
@ -227,7 +221,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
@ -259,7 +254,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
@ -411,7 +407,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
} }
if (device != null) { if (device != null) {
DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType()); DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
Device pluginSpecificInfo = dms.getDevice(deviceId); Device pluginSpecificInfo = dms.getDevice(deviceId);
if (pluginSpecificInfo != null) { if (pluginSpecificInfo != null) {
device.setFeatures(pluginSpecificInfo.getFeatures()); device.setFeatures(pluginSpecificInfo.getFeatures());
@ -424,7 +421,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
return dms.updateDeviceInfo(deviceIdentifier, device); return dms.updateDeviceInfo(deviceIdentifier, device);
} }
@ -432,14 +429,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException { throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.setOwnership(deviceId, ownershipType); return dms.setOwnership(deviceId, ownershipType);
} }
@Override @Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isClaimable(deviceId); return dms.isClaimable(deviceId);
} }
@ -558,7 +555,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (Device device : userDevices) { for (Device device : userDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
@ -602,7 +600,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : userDevices) { for (Device device : userDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
@ -651,7 +650,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
@ -685,7 +685,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
pluginRepository.addDeviceManagementProvider(deviceManagementService); pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" + log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }
@ -695,7 +695,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
pluginRepository.removeDeviceManagementProvider(deviceManagementService); pluginRepository.removeDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" + log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }

@ -41,9 +41,9 @@ public class DeviceManagementRepositoryTests {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e); Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e);
} }
DeviceManager targetProvider = DeviceManagementService targetProvider =
this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST); this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST);
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType()); Assert.assertEquals(targetProvider.getType(), sourceProvider.getType());
} }
@Test(dependsOnMethods = "testAddDeviceManagementService") @Test(dependsOnMethods = "testAddDeviceManagementService")
@ -54,7 +54,7 @@ public class DeviceManagementRepositoryTests {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e); Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e);
} }
DeviceManager targetProvider = DeviceManagementService targetProvider =
this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST); this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST);
Assert.assertNull(targetProvider); Assert.assertNull(targetProvider);
} }

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -29,77 +30,27 @@ public class TestDeviceManagementService implements DeviceManagementService {
public static final String DEVICE_TYPE_TEST = "Test"; public static final String DEVICE_TYPE_TEST = "Test";
@Override
public String getProviderType() {
return TestDeviceManagementService.DEVICE_TYPE_TEST;
}
@Override
public FeatureManager getFeatureManager() {
return null;
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public String getType() {
return false; return TestDeviceManagementService.DEVICE_TYPE_TEST;
} }
@Override @Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { public void init() throws DeviceManagementException {
return false;
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
return false;
} }
@Override @Override
public List<Device> getAllDevices() throws DeviceManagementException { public DeviceManager getDeviceManager() {
return null; return null;
} }
@Override @Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public ApplicationManager getApplicationManager() {
return null; return null;
} }
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
return false;
}
@Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
EnrolmentInfo.Status status) throws DeviceManagementException {
return false;
}
@Override @Override
public Application[] getApplications(String domain, int pageNumber, public Application[] getApplications(String domain, int pageNumber,
int size) throws ApplicationManagementException { int size) throws ApplicationManagementException {
@ -119,8 +70,9 @@ public class TestDeviceManagementService implements DeviceManagementService {
} }
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) public void installApplication(Operation operation,
throws ApplicationManagementException { List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
} }
} }

@ -18,8 +18,12 @@
*/ */
package org.wso2.carbon.identity.oauth.extension; package org.wso2.carbon.identity.oauth.extension;
public class ApplicationConstants { public final class ApplicationConstants {
public static class ClientMetadata {
private ClientMetadata() {
throw new AssertionError();
}
public static final String OAUTH_CLIENT_ID = "client_id"; //this means consumer key public static final String OAUTH_CLIENT_ID = "client_id"; //this means consumer key
public static final String OAUTH_CLIENT_SECRET = "client_secret"; public static final String OAUTH_CLIENT_SECRET = "client_secret";
public static final String OAUTH_REDIRECT_URIS = "redirect_uris"; public static final String OAUTH_REDIRECT_URIS = "redirect_uris";
@ -46,5 +50,6 @@ public class ApplicationConstants {
public static final String OAUTH_CLIENT_USERNAME = "username"; public static final String OAUTH_CLIENT_USERNAME = "username";
public static final String OAUTH_CLIENT_APPLICATION = "application"; public static final String OAUTH_CLIENT_APPLICATION = "application";
public static final String VALIDITY_PERIOD = "validityPeriod"; public static final String VALIDITY_PERIOD = "validityPeriod";
}
} }

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.identity.oauth.extension.impl; package org.wso2.carbon.identity.oauth.extension;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -37,7 +37,6 @@ import org.wso2.carbon.identity.oauth.OAuthAdminService;
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO; import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.identity.oauth.extension.ApplicationConstants; import org.wso2.carbon.identity.oauth.extension.ApplicationConstants;
import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo; import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo;
import org.wso2.carbon.identity.oauth.extension.RegistrationProfile;
import org.wso2.carbon.identity.oauth.extension.RegistrationService; import org.wso2.carbon.identity.oauth.extension.RegistrationService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
@ -49,13 +48,15 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.util.Arrays; import java.util.Arrays;
@Produces(MediaType.APPLICATION_JSON) public class DynamicClientRegistrationUtil {
@Consumes(MediaType.APPLICATION_JSON)
public class ClientRegistrationServiceImpl implements RegistrationService {
private static final Log log = LogFactory.getLog(ClientRegistrationServiceImpl.class); private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class);
@POST @POST
@Override @Override
@ -93,7 +94,7 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
} }
private OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException { public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException {
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
//Subscriber's name should be passed as a parameter, since it's under the subscriber the OAuth App is created. //Subscriber's name should be passed as a parameter, since it's under the subscriber the OAuth App is created.
@ -114,7 +115,7 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
oAuthApplicationInfo.addParameter("tokenScope", Arrays.toString(tokenScopes)); oAuthApplicationInfo.addParameter("tokenScope", Arrays.toString(tokenScopes));
OAuthApplicationInfo info; OAuthApplicationInfo info;
try { try {
info = this.createOAuthApplication(userId, applicationName, callBackURL, grantType); info = createOAuthApplication(userId, applicationName, callBackURL, grantType);
} catch (Exception e) { } catch (Exception e) {
throw new APIManagementException("Can not create OAuth application : " + applicationName, e); throw new APIManagementException("Can not create OAuth application : " + applicationName, e);
} }
@ -130,26 +131,24 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
try { try {
JSONObject jsonObject = new JSONObject(info.getJsonString()); JSONObject jsonObject = new JSONObject(info.getJsonString());
if (jsonObject.has(ApplicationConstants.OAUTH_REDIRECT_URIS)) { if (jsonObject.has(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS)) {
oAuthApplicationInfo.addParameter(ApplicationConstants.OAUTH_REDIRECT_URIS, jsonObject.get(ApplicationConstants.OAUTH_REDIRECT_URIS)); oAuthApplicationInfo.addParameter(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS,
jsonObject.get(ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS));
} }
if (jsonObject.has(ApplicationConstants.OAUTH_CLIENT_GRANT)) { if (jsonObject.has(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT)) {
oAuthApplicationInfo.addParameter(ApplicationConstants. oAuthApplicationInfo.addParameter(ApplicationConstants.ClientMetadata.
OAUTH_CLIENT_GRANT, jsonObject.get(ApplicationConstants.OAUTH_CLIENT_GRANT)); OAUTH_CLIENT_GRANT, jsonObject.get(ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT));
} }
} catch (JSONException e) { } catch (JSONException e) {
throw new APIManagementException("Can not retrieve information of the created OAuth application", e); throw new APIManagementException("Can not retrieve information of the created OAuth application", e);
} }
return oAuthApplicationInfo; return oAuthApplicationInfo;
} }
public OAuthApplicationInfo createOAuthApplication( public static OAuthApplicationInfo createOAuthApplication(
String userId, String applicationName, String callbackUrl, String grantType) String userId, String applicationName, String callbackUrl, String grantType)
throws APIManagementException, IdentityException { throws APIManagementException, IdentityException {
if (userId == null || userId.isEmpty()) { if (userId == null || userId.isEmpty()) {
return null; return null;
} }
@ -166,7 +165,6 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
try { try {
// Append the username before Application name to make application name unique across two users. // Append the username before Application name to make application name unique across two users.
applicationName = userName + "_" + applicationName; applicationName = userName + "_" + applicationName;
@ -179,7 +177,6 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
appMgtService.createApplication(serviceProvider); appMgtService.createApplication(serviceProvider);
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
if (createdServiceProvider == null) { if (createdServiceProvider == null) {
throw new APIManagementException("Couldn't create Service Provider Application " + applicationName); throw new APIManagementException("Couldn't create Service Provider Application " + applicationName);
} }
@ -188,17 +185,23 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
OAuthAdminService oAuthAdminService = new OAuthAdminService(); OAuthAdminService oAuthAdminService = new OAuthAdminService();
OAuthConsumerAppDTO oAuthConsumerAppDTO = new OAuthConsumerAppDTO(); OAuthConsumerAppDTO oAuthConsumerAppDTO = new OAuthConsumerAppDTO();
oAuthConsumerAppDTO.setApplicationName(applicationName); oAuthConsumerAppDTO.setApplicationName(applicationName);
oAuthConsumerAppDTO.setCallbackUrl(callbackUrl); oAuthConsumerAppDTO.setCallbackUrl(callbackUrl);
oAuthConsumerAppDTO.setGrantTypes(grantType); oAuthConsumerAppDTO.setGrantTypes(grantType);
if (log.isDebugEnabled()) {
log.debug("Creating OAuth App " + applicationName); log.debug("Creating OAuth App " + applicationName);
}
oAuthAdminService.registerOAuthApplicationData(oAuthConsumerAppDTO); oAuthAdminService.registerOAuthApplicationData(oAuthConsumerAppDTO);
if (log.isDebugEnabled()) {
log.debug("Created OAuth App " + applicationName); log.debug("Created OAuth App " + applicationName);
}
OAuthConsumerAppDTO createdApp = oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerAppDTO OAuthConsumerAppDTO createdApp = oAuthAdminService.getOAuthApplicationDataByAppName(oAuthConsumerAppDTO
.getApplicationName()); .getApplicationName());
if (log.isDebugEnabled()) {
log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName()); log.debug("Retrieved Details for OAuth App " + createdApp.getApplicationName());
}
// Set the OAuthApp in InboundAuthenticationConfig // Set the OAuthApp in InboundAuthenticationConfig
InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig(); InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
InboundAuthenticationRequestConfig[] inboundAuthenticationRequestConfigs = new InboundAuthenticationRequestConfig[] inboundAuthenticationRequestConfigs = new
@ -224,20 +227,17 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
// Update the Service Provider app to add OAuthApp as an Inbound Authentication Config // Update the Service Provider app to add OAuthApp as an Inbound Authentication Config
appMgtService.updateApplication(createdServiceProvider); appMgtService.updateApplication(createdServiceProvider);
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
oAuthApplicationInfo.setClientId(createdApp.getOauthConsumerKey()); oAuthApplicationInfo.setClientId(createdApp.getOauthConsumerKey());
oAuthApplicationInfo.setCallBackURL(createdApp.getCallbackUrl()); oAuthApplicationInfo.setCallBackURL(createdApp.getCallbackUrl());
oAuthApplicationInfo.setClientSecret(createdApp.getOauthConsumerSecret()); oAuthApplicationInfo.setClientSecret(createdApp.getOauthConsumerSecret());
oAuthApplicationInfo.setClientName(createdApp.getApplicationName()); oAuthApplicationInfo.setClientName(createdApp.getApplicationName());
oAuthApplicationInfo.addParameter(ApplicationConstants. oAuthApplicationInfo.addParameter(
OAUTH_REDIRECT_URIS, createdApp.getCallbackUrl()); ApplicationConstants.ClientMetadata.OAUTH_REDIRECT_URIS, createdApp.getCallbackUrl());
oAuthApplicationInfo.addParameter(ApplicationConstants. oAuthApplicationInfo.addParameter(
OAUTH_CLIENT_GRANT, createdApp.getGrantTypes()); ApplicationConstants.ClientMetadata.OAUTH_CLIENT_GRANT, createdApp.getGrantTypes());
return oAuthApplicationInfo; return oAuthApplicationInfo;
} catch (IdentityApplicationManagementException e) { } catch (IdentityApplicationManagementException e) {
APIUtil.handleException("Error occurred while creating ServiceProvider for app " + applicationName, e); APIUtil.handleException("Error occurred while creating ServiceProvider for app " + applicationName, e);
} catch (Exception e) { } catch (Exception e) {
@ -249,9 +249,8 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
return null; return null;
} }
public void unregisterApplication(String userId, String applicationName, String consumerKey) public static void unregisterApplication(String userId, String applicationName,
throws APIManagementException { String consumerKey) throws APIManagementException {
String tenantDomain = MultitenantUtils.getTenantDomain(userId); String tenantDomain = MultitenantUtils.getTenantDomain(userId);
String baseUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); String baseUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
String userName = MultitenantUtils.getTenantAwareUsername(userId); String userName = MultitenantUtils.getTenantAwareUsername(userId);
@ -261,7 +260,8 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
if (userId == null || userId.isEmpty()) { if (userId == null || userId.isEmpty()) {
throw new APIManagementException("Error occurred while unregistering Application: userId cannot be null/empty"); throw new APIManagementException("Error occurred while unregistering Application: userId cannot " +
"be null/empty");
} }
try { try {
OAuthAdminService oAuthAdminService = new OAuthAdminService(); OAuthAdminService oAuthAdminService = new OAuthAdminService();
@ -290,4 +290,5 @@ public class ClientRegistrationServiceImpl implements RegistrationService {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser);
} }
} }
} }

@ -0,0 +1,71 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.identity.oauth.extension;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class FaultMessageBodyWriter implements MessageBodyWriter<FaultResponse> {
private static final String UTF_8 = "UTF-8";
@Override
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
return (FaultResponse.class == type);
}
@Override
public long getSize(FaultResponse faultResponse, Class<?> aClass, Type type, Annotation[] annotations,
MediaType mediaType) {
return -1;
}
@Override
public void writeTo(FaultResponse faultResponse, Class<?> aClass, Type type, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap,
OutputStream outputStream) throws IOException, WebApplicationException {
try (OutputStreamWriter writer = new OutputStreamWriter(outputStream, UTF_8)) {
JsonObject response = new JsonObject();
response.addProperty("error", faultResponse.getCode().getValue());
response.addProperty("error_description", faultResponse.getDescription());
getGson().toJson(response, type, writer);
}
}
private Gson getGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
return gsonBuilder.create();
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.identity.oauth.extension;
public class FaultResponse {
private RegistrationService.ErrorCode code;
private String description;
public FaultResponse(RegistrationService.ErrorCode code, String description) {
this.code = code;
this.description = description;
}
public RegistrationService.ErrorCode getCode() {
return code;
}
public String getDescription() {
return description;
}
}

@ -27,24 +27,16 @@ import java.util.Map;
public class OAuthApplicationInfo { public class OAuthApplicationInfo {
private String clientId; private String clientId;
private String clientName; private String clientName;
private String callBackURL; private String callBackURL;
private String clientSecret; private String clientSecret;
private Map<String,Object> parameters = new HashMap<String, Object>(); private Map<String,Object> parameters = new HashMap<String, Object>();
/**
* get client Id (consumer id)
* @return clientId
*/
public String getClientId() { public String getClientId() {
return clientId; return clientId;
} }
/**
* set client Id
* @param clientId
*/
public void setClientId(String clientId) { public void setClientId(String clientId) {
this.clientId = clientId; this.clientId = clientId;
} }
@ -57,18 +49,10 @@ public class OAuthApplicationInfo {
this.clientSecret = clientSecret; this.clientSecret = clientSecret;
} }
/**
* Set client Name of OAuthApplication.
* @param clientName
*/
public void setClientName(String clientName){ public void setClientName(String clientName){
this.clientName = clientName; this.clientName = clientName;
} }
/**
* Set callback URL of OAuthapplication.
* @param callBackURL
*/
public void setCallBackURL(String callBackURL){ public void setCallBackURL(String callBackURL){
this.callBackURL = callBackURL; this.callBackURL = callBackURL;
} }
@ -82,9 +66,7 @@ public class OAuthApplicationInfo {
} }
public String getJsonString(){ public String getJsonString(){
return JSONObject.toJSONString(parameters); return JSONObject.toJSONString(parameters);
} }
public String getClientName(){ public String getClientName(){

@ -18,6 +18,8 @@
*/ */
package org.wso2.carbon.identity.oauth.extension; package org.wso2.carbon.identity.oauth.extension;
import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.POST; import javax.ws.rs.POST;
@ -30,6 +32,19 @@ import javax.ws.rs.core.Response;
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface RegistrationService { public interface RegistrationService {
enum ErrorCode {
INVALID_URI("invalid_redirect_uri"), INVALID_CLIENT_METADATA("invalid_client_metadata");
private String value;
private ErrorCode(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
@POST @POST
Response register(RegistrationProfile profile); Response register(RegistrationProfile profile);

@ -0,0 +1,33 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.identity.oauth.extension.impl;
import org.wso2.carbon.identity.oauth.extension.ConfigurationService;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
public class ConfigurationServiceImpl implements ConfigurationService {
@Override
public Response getProfile(@PathParam("client_id") String clientId) {
return null;
}
}

@ -0,0 +1,93 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.identity.oauth.extension.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig;
import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig;
import org.wso2.carbon.identity.application.common.model.Property;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.oauth.OAuthAdminService;
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.identity.oauth.extension.*;
import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile;
import org.wso2.carbon.identity.oauth.extension.profile.UnregistrationProfile;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class RegistrationServiceImpl implements RegistrationService {
private static final Log log = LogFactory.getLog(RegistrationServiceImpl.class);
@POST
@Override
public Response register(RegistrationProfile profile) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
OAuthApplicationInfo info = DynamicClientRegistrationUtil.registerApplication(profile);
return Response.status(Response.Status.ACCEPTED).entity(info.toString()).build();
} catch (APIManagementException e) {
String msg = "Error occurred while registering client '" + profile.getClientName() + "'";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new FaultResponse(ErrorCode.INVALID_CLIENT_METADATA, msg)).build();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
@DELETE
@Override
public Response unregister(@QueryParam("applicationName") String applicationName,
@QueryParam("userId") String userId,
@QueryParam("consumerKey") String consumerKey) {
try {
DynamicClientRegistrationUtil.unregisterApplication(userId, applicationName, consumerKey);
return Response.status(Response.Status.ACCEPTED).build();
} catch (APIManagementException e) {
String msg = "Error occurred while un-registering client '" + applicationName + "'";
log.error(msg, e);
return Response.serverError().entity(new FaultResponse(ErrorCode.INVALID_CLIENT_METADATA, msg)).build();
}
}
}

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.identity.oauth.extension; package org.wso2.carbon.identity.oauth.extension.profile;
public class RegistrationProfile { public class RegistrationProfile {

@ -33,10 +33,12 @@
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<ref bean="jsonProvider"/> <ref bean="jsonProvider"/>
<ref bean="faultResponseWriter"/>
</jaxrs:providers> </jaxrs:providers>
</jaxrs:server> </jaxrs:server>
<bean id="RegistrationServiceBean" class="org.wso2.carbon.identity.oauth.extension.impl.ClientRegistrationServiceImpl"/> <bean id="RegistrationServiceBean" class="org.wso2.carbon.identity.oauth.extension.impl.RegistrationServiceImpl"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/> <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
<bean id="faultResponseWriter" class="org.wso2.carbon.identity.oauth.extension.FaultMessageBodyWriter"/>
</beans> </beans>

@ -19,6 +19,8 @@
package org.wso2.carbon.policy.mgt.common.monitor; package org.wso2.carbon.policy.mgt.common.monitor;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.List; import java.util.List;
public class ComplianceData { public class ComplianceData {
@ -30,6 +32,13 @@ public class ComplianceData {
private boolean status; private boolean status;
private String message; private String message;
/**
* This parameter is to inform the policy core, weather related device type plugins does need the full policy or
* the part which is none compliance.
*/
private boolean completePolicy;
private Policy policy;
public int getId() { public int getId() {
return id; return id;
} }
@ -77,4 +86,20 @@ public class ComplianceData {
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
public boolean isCompletePolicy() {
return completePolicy;
}
public void setCompletePolicy(boolean completePolicy) {
this.completePolicy = completePolicy;
}
public Policy getPolicy() {
return policy;
}
public void setPolicy(Policy policy) {
this.policy = policy;
}
} }

@ -31,7 +31,8 @@ public interface ComplianceDecisionPoint {
void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
void reEnforcePolicy(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; void reEnforcePolicy(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
PolicyComplianceException;
void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
@ -41,7 +42,7 @@ public interface ComplianceDecisionPoint {
void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy) throws void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
PolicyComplianceException; PolicyComplianceException;

@ -19,10 +19,11 @@
package org.wso2.carbon.policy.mgt.common; package org.wso2.carbon.policy.mgt.common;
import java.io.Serializable; import java.io.Serializable;
import org.wso2.carbon.device.mgt.common.Feature;
public class ProfileFeature implements Serializable { public class ProfileFeature implements Serializable {
private static final long serialVersionUID = 19981018L;
private int id; private int id;
private String featureCode; private String featureCode;
private int profileId; private int profileId;

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
@ -31,6 +32,6 @@ public interface PolicyMonitoringService {
void notifyDevices(List<Device> devices) throws PolicyComplianceException; void notifyDevices(List<Device> devices) throws PolicyComplianceException;
List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response) ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
throws PolicyComplianceException; throws PolicyComplianceException;
} }

@ -37,5 +37,9 @@ public interface MonitoringDAO {
List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException; List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException;
void deleteNoneComplianceData(int deviceId) throws MonitoringDAOException; void deleteNoneComplianceData(int policyComplianceStatusId) throws MonitoringDAOException;
void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException;
} }

@ -80,9 +80,10 @@ public class MonitoringDAOImpl implements MonitoringDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?"; String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ? WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId); stmt.setInt(1, 1);
stmt.setInt(2, deviceId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -193,15 +194,15 @@ public class MonitoringDAOImpl implements MonitoringDAO {
} }
@Override @Override
public void deleteNoneComplianceData(int deviceId) throws MonitoringDAOException { public void deleteNoneComplianceData(int policyComplianceStatusId) throws MonitoringDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?"; String query = "DELETE FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId); stmt.setInt(1, policyComplianceStatusId);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -214,6 +215,11 @@ public class MonitoringDAOImpl implements MonitoringDAO {
} }
@Override
public void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException {
}
private Connection getConnection() throws MonitoringDAOException { private Connection getConnection() throws MonitoringDAOException {
try { try {

@ -21,15 +21,31 @@ package org.wso2.carbon.policy.mgt.core.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
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.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.EnrolmentDAO; import org.wso2.carbon.device.mgt.core.dao.EnrolmentDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint;
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.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager; import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl; import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.util.ArrayList;
import java.util.List;
public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
@ -54,41 +70,191 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
@Override @Override
public void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.UNREACHABLE, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while setting the device as unreachable for " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
} }
@Override @Override
public void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while setting the device as reachable for " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
} }
@Override @Override
public void reEnforcePolicy(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void reEnforcePolicy(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
PolicyComplianceException {
try {
Policy policy = complianceData.getPolicy();
if (policy != null) {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier);
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
PolicyOperation policyOperation = new PolicyOperation();
policyOperation.setEnabled(true);
policyOperation.setType(Operation.Type.POLICY);
policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE);
if (complianceData.isCompletePolicy()) {
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation profileOperation = new ProfileOperation();
profileOperation.setCode(feature.getFeatureCode());
profileOperation.setEnabled(true);
profileOperation.setStatus(Operation.Status.PENDING);
profileOperation.setType(Operation.Type.PROFILE);
profileOperation.setPayLoad(feature.getContent());
profileOperationList.add(profileOperation);
}
} else {
List<ComplianceFeature> noneComplianceFeatures = complianceData.getComplianceFeatures();
for (ComplianceFeature feature : noneComplianceFeatures) {
ProfileOperation profileOperation = new ProfileOperation();
profileOperation.setCode(feature.getFeatureCode());
profileOperation.setEnabled(true);
profileOperation.setStatus(Operation.Status.PENDING);
profileOperation.setType(Operation.Type.PROFILE);
profileOperation.setPayLoad(feature.getFeature().getContent());
profileOperationList.add(profileOperation);
}
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setPayLoad(policyOperation.getProfileOperations());
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
addOperation(policyOperation, deviceIdentifiers);
} }
} catch (OperationManagementException e) {
String msg = "Error occurred while re-enforcing the policy to device " + deviceIdentifier.getId() + " - " +
deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
}
@Override @Override
public void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.BLOCKED, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while marking device as none compliance " + deviceIdentifier.getId() + " - " +
deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
} }
@Override @Override
public void markDeviceAsCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void markDeviceAsCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " +
deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
} }
@Override @Override
public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.INACTIVE, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " +
deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
} }
@Override @Override
public void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " +
deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyComplianceException(msg, e);
}
} }
@Override @Override
public void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy) throws public void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
PolicyComplianceException { PolicyComplianceException {
Policy policy = complianceData.getPolicy();
String compliance = this.getNoneComplianceRule(policy);
if (compliance.equals("")) {
String msg = "Compliance rule is empty for the policy " + policy.getPolicyName() + ". Therefore " +
"Monitoring Engine cannot run.";
throw new PolicyComplianceException(msg);
}
if (PolicyManagementConstants.ENFORCE.equalsIgnoreCase(compliance)) {
this.reEnforcePolicy(deviceIdentifier, complianceData);
}
if (PolicyManagementConstants.WARN.equalsIgnoreCase(compliance)) {
this.markDeviceAsNoneCompliance(deviceIdentifier);
}
if (PolicyManagementConstants.BLOCK.equalsIgnoreCase(compliance)) {
this.markDeviceAsNoneCompliance(deviceIdentifier);
}
} }
} }

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; 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.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
@ -37,6 +38,7 @@ import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAOException;
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO; import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import org.wso2.carbon.policy.mgt.core.impl.ComplianceDecisionPointImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
@ -48,6 +50,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
private PolicyDAO policyDAO; private PolicyDAO policyDAO;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private MonitoringDAO monitoringDAO; private MonitoringDAO monitoringDAO;
private ComplianceDecisionPoint complianceDecisionPoint;
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class); private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
@ -55,6 +58,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO(); this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO();
this.complianceDecisionPoint = new ComplianceDecisionPointImpl();
} }
@Override @Override
@ -71,13 +75,15 @@ public class MonitoringManagerImpl implements MonitoringManager {
PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance(). PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance().
getPolicyMonitoringService(deviceIdentifier.getType()); getPolicyMonitoringService(deviceIdentifier.getType());
complianceFeatures = monitoringService.checkPolicyCompliance(deviceIdentifier, ComplianceData complianceData = monitoringService.checkPolicyCompliance(deviceIdentifier,
policy, deviceResponse); policy, deviceResponse);
complianceData.setPolicy(policy);
complianceFeatures = complianceData.getComplianceFeatures();
if (!complianceFeatures.isEmpty()) { if (!complianceFeatures.isEmpty()) {
int complianceId = monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId()); int complianceId = monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId());
monitoringDAO.addNoneComplianceFeatures(complianceId, device.getId(), complianceFeatures); monitoringDAO.addNoneComplianceFeatures(complianceId, device.getId(), complianceFeatures);
complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData);
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList(); List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
for (ComplianceFeature compFeature : complianceFeatures) { for (ComplianceFeature compFeature : complianceFeatures) {
for (ProfileFeature profFeature : profileFeatures) { for (ProfileFeature profFeature : profileFeatures) {

@ -19,12 +19,22 @@
package org.wso2.carbon.policy.mgt.core.task; package org.wso2.carbon.policy.mgt.core.task;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import java.util.List;
import java.util.Map; import java.util.Map;
public class MonitoringTask implements Task { public class MonitoringTask implements Task {
private DeviceTypeDAO deviceTypeDAO;
@Override @Override
public void setProperties(Map<String, String> map) { public void setProperties(Map<String, String> map) {
@ -32,11 +42,29 @@ public class MonitoringTask implements Task {
@Override @Override
public void init() { public void init() {
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
} }
@Override @Override
public void execute() { public void execute() {
try {
List<DeviceType> deviceTypes = deviceTypeDAO.getDeviceTypes();
DeviceManagementProviderService deviceManagementProviderService =
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
for (DeviceType deviceType : deviceTypes) {
PolicyMonitoringService monitoringService =
PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType.getName());
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType.getName());
monitoringService.notifyDevices(devices);
}
} catch (Exception e) {
}
} }
} }

@ -24,4 +24,10 @@ public final class PolicyManagementConstants {
public static final String ANY = "ANY"; public static final String ANY = "ANY";
public static final String POLICY_BUNDLE = "POLICY_BUNDLE"; public static final String POLICY_BUNDLE = "POLICY_BUNDLE";
public static final String MONITOR = "MONITOR";
public static final String ENFORCE = "ENFORCE";
public static final String WARN = "WARN";
public static final String BLOCK = "BLOCK";
} }

@ -945,16 +945,16 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!--<plugin>--> <plugin>
<!--<groupId>org.apache.maven.plugins</groupId>--> <groupId>org.apache.maven.plugins</groupId>
<!--<artifactId>maven-compiler-plugin</artifactId>--> <artifactId>maven-compiler-plugin</artifactId>
<!--<version>2.3.1</version>--> <version>2.3.1</version>
<!--<configuration>--> <configuration>
<!--<encoding>UTF-8</encoding>--> <encoding>UTF-8</encoding>
<!--<source>1.6</source>--> <source>1.7</source>
<!--<target>1.6</target>--> <target>1.7</target>
<!--</configuration>--> </configuration>
<!--</plugin>--> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>

Loading…
Cancel
Save