From 20db31c2a9d5225fd53f04ddbea85f0f2ebbbe91 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 17 Nov 2015 16:14:51 +0530 Subject: [PATCH 1/8] Add app manager features --- .../core/app/mgt/config/AppManagementConfigurationManager.java | 2 +- .../{app-management-config.xml => remote-appmanager-config.xml} | 0 .../src/main/resources/p2.inf | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/{app-management-config.xml => remote-appmanager-config.xml} (100%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java index 4fd12ca2dad..7ec4dc69a24 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java @@ -32,7 +32,7 @@ public class AppManagementConfigurationManager { private AppManagementConfig appManagementConfig; private static AppManagementConfigurationManager appManagementConfigManager; - private static final String APP_MANAGER_CONFIG_FILE = "app-management-config.xml"; + private static final String APP_MANAGER_CONFIG_FILE = "remote-appmanager-config.xml"; private static final String APP_MANAGER_CONFIG_PATH = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + APP_MANAGER_CONFIG_FILE; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/app-management-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/app-management-config.xml rename to features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf index 8da383c571c..3d7d4ba5b66 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf @@ -2,6 +2,6 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/app-management-config.xml,target:${installFolder}/../../conf/etc/app-management-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\ \ No newline at end of file From 5772ca4a3526ec613b18e2b94ec2ecdc84f49571 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Wed, 18 Nov 2015 21:08:57 +0530 Subject: [PATCH 2/8] Removing the unique key --- .../src/main/resources/dbscripts/cdm/mssql.sql | 1 - .../src/main/resources/dbscripts/cdm/mysql.sql | 1 - .../src/main/resources/dbscripts/cdm/oracle.sql | 1 - .../src/main/resources/dbscripts/cdm/postgresql.sql | 1 - 4 files changed, 4 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index f812b1575d7..447a99f1426 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -305,7 +305,6 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( LAST_FAILED_TIME DATETIME2(0) NULL, ATTEMPTS INT NULL, PRIMARY KEY (ID), - CONSTRAINT DEVICE_ID_UNIQUE UNIQUE (DEVICE_ID ASC), CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY FOREIGN KEY (POLICY_ID) REFERENCES DM_POLICY (ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index cdb2d3c0194..e340450d4cf 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -297,7 +297,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( LAST_FAILED_TIME TIMESTAMP NULL, ATTEMPTS INT NULL, PRIMARY KEY (ID), - UNIQUE INDEX DEVICE_ID_UNIQUE (DEVICE_ID ASC), CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY FOREIGN KEY (POLICY_ID) REFERENCES DM_POLICY (ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 2b33f64118e..229556c1104 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -486,7 +486,6 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( LAST_FAILED_TIME TIMESTAMP(0) NULL, ATTEMPTS NUMBER(10) NULL, CONSTRAINT PK_DM_POLICY_COMP_STATUS PRIMARY KEY (ID), - CONSTRAINT DEVICE_ID_UNIQUE UNIQUE (DEVICE_ID), CONSTRAINT FK_POLICY_COMP_STATUS_POLICY FOREIGN KEY (POLICY_ID) REFERENCES DM_POLICY (ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 1740e5d551b..7b14cbb5cb1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -267,7 +267,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE UNIQUE INDEX DEVICE_ID_UNIQUE ON DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID ASC); CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID BIGSERIAL NOT NULL PRIMARY KEY, From 767ea70436bb597cc5aa69bf406b2366e65d06e6 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Wed, 18 Nov 2015 22:05:15 +0530 Subject: [PATCH 3/8] Refactored CommandOperation DAO class --- .../mgt/dao/impl/CommandOperationDAOImpl.java | 3 ++- .../src/main/resources/dbscripts/cdm/postgresql.sql | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index e5663b38445..8fdd35591a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -134,7 +134,8 @@ public class CommandOperationDAOImpl extends OperationDAOImpl { while (rs.next()) { commandOperation = new CommandOperation(); commandOperation.setId(rs.getInt("ID")); - commandOperation.setEnabled(rs.getInt("ENABLED") != 0); + //commandOperation.setEnabled(rs.getInt("ENABLED") != 0); + commandOperation.setEnabled(rs.getBoolean("ENABLED") != false); commandOperation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); commandOperation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); commandOperation.setCreatedTimeStamp(rs.getString("CREATED_TIMESTAMP")); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 1740e5d551b..f42655f7903 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -316,6 +316,17 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( TENANT_ID INTEGER NOT NULL ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( + ID BIGSERIAL NOT NULL PRIMARY KEY, + DEVICE_ID INTEGER NOT NULL, + APPLICATION_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, + CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES + DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + -- POLICY RELATED TABLES FINISHED -- -- NOTIFICATION TABLE -- From a04658af140b83ba7dc7e95e339e1dfc6ec177ae Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 19 Nov 2015 10:21:59 +0530 Subject: [PATCH 4/8] App Manager integration --- .../common/app/mgt/ApplicationManager.java | 6 +- .../ApplicationManagementProviderService.java | 2 +- .../app/mgt/ApplicationManagerFactory.java | 8 +- ...ApplicationManagerProviderServiceImpl.java | 135 ++++++++++++------ .../DeviceManagementServiceComponent.java | 7 +- .../mgt/core/TestDeviceManagementService.java | 14 +- ...licationManagementProviderServiceTest.java | 2 +- ...management-config-no-client-key-secret.xml | 8 +- .../conf/remote-appmanager-config.xml | 2 + 9 files changed, 121 insertions(+), 63 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java index a341768d17f..bf660566f82 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java @@ -66,8 +66,12 @@ public interface ApplicationManager { throws ApplicationManagementException; - void installApplication(Operation operation, List deviceIdentifiers) + void installApplicationForDevices(Operation operation, List deviceIdentifiers) throws ApplicationManagementException; + void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException; + void installApplicationForUserRoles(Operation operation, List userRoleList) + throws ApplicationManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java index e13f0cbfbf5..0ea859a1406 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java @@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import java.util.List; -public interface ApplicationManagementProviderService extends ApplicationManager { +public interface ApplicationManagementProviderService extends ApplicationManager{ void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, List applications) throws ApplicationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java index e89563622e5..f0a11ad25dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java @@ -24,14 +24,8 @@ import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; public class ApplicationManagerFactory { - private static DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); - - public DeviceManagementPluginRepository getPluginRepository() { - return pluginRepository; - } - public static ApplicationManager getConnector(AppManagementConfig config) { - return new ApplicationManagerProviderServiceImpl(config, pluginRepository); + return new ApplicationManagerProviderServiceImpl(config); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index ea0ce55365d..6f63f034192 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -31,15 +31,14 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException; 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.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.dao.*; -import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; @@ -52,13 +51,11 @@ import java.util.List; /** * Implements Application Manager interface */ -public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService, - PluginInitializationListener { +public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService { private ConfigurationContext configCtx; private ServiceAuthenticator authenticator; private String oAuthAdminServiceUrl; - private DeviceManagementPluginRepository pluginRepository; private DeviceDAO deviceDAO; private ApplicationDAO applicationDAO; private ApplicationMappingDAO applicationMappingDAO; @@ -66,8 +63,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class); - public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig, - DeviceManagementPluginRepository pluginRepository) { + public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig) { IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). getDeviceManagementConfigRepository().getIdentityConfigurations(); @@ -81,14 +77,12 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " + "Please check if an appropriate axis2.xml is provided", e); } - this.pluginRepository = pluginRepository; this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO(); } - ApplicationManagerProviderServiceImpl(DeviceManagementPluginRepository pluginRepository) { - this.pluginRepository = pluginRepository; + ApplicationManagerProviderServiceImpl() { this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); this.applicationMappingDAO = DeviceManagementDAOFactory.getApplicationMappingDAO(); @@ -102,24 +96,105 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem @Override public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, - String status) throws ApplicationManagementException { + String status) throws ApplicationManagementException { } @Override public String getApplicationStatus(DeviceIdentifier deviceId, - Application application) throws ApplicationManagementException { + Application application) throws ApplicationManagementException { return null; } @Override - public void installApplication(Operation operation, List deviceIds) + public void installApplicationForDevices(Operation operation, List deviceIds) throws ApplicationManagementException { - for (DeviceIdentifier deviceId : deviceIds) { - DeviceManagementService dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); - dms.installApplication(operation, deviceIds); + try { + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, deviceIds); + } catch (OperationManagementException opeEx) { + String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); + log.error(errorMsg, opeEx); + throw new ApplicationManagementException(errorMsg, opeEx); + } + } + + @Override + public void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException { + + String userName = null; + try { + List deviceList; + List deviceIdentifierList = new ArrayList<>(); + DeviceIdentifier deviceIdentifier; + + + + for (String user : userNameList) { + userName = user; + deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser + (user); + for (Device device : deviceList) { + deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(Integer.toString(device.getId())); + deviceIdentifier.setType(device.getType()); + + deviceIdentifierList.add(deviceIdentifier); + } + } + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .addOperation(operation, deviceIdentifierList); + + } catch (DeviceManagementException devEx) { + String errorMsg = "Error in get devices for user: "+userName+ " in app installation:" + devEx.getErrorMessage(); + log.error(errorMsg, devEx); + throw new ApplicationManagementException(errorMsg, devEx); + + } catch (OperationManagementException opeEx) { + String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); + log.error(errorMsg, opeEx); + throw new ApplicationManagementException(errorMsg, opeEx); + + } + } + + @Override + public void installApplicationForUserRoles(Operation operation, List userRoleList) + throws ApplicationManagementException { + + String userRole = null; + try { + List deviceList; + List deviceIdentifierList = new ArrayList<>(); + DeviceIdentifier deviceIdentifier; + + for (String role : userRoleList) { + userRole = role; + deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .getAllDevicesOfRole(userRole); + for (Device device : deviceList) { + deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(Integer.toString(device.getId())); + deviceIdentifier.setType(device.getType()); + + deviceIdentifierList.add(deviceIdentifier); + } + } + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .addOperation(operation, deviceIdentifierList); + + } catch (DeviceManagementException devEx) { + String errorMsg = "Error in get devices for user role "+userRole+ " in app installation:" + + devEx.getErrorMessage(); + log.error(errorMsg, devEx); + throw new ApplicationManagementException(errorMsg, devEx); + + } catch (OperationManagementException opeEx) { + String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); + log.error(errorMsg, opeEx); + throw new ApplicationManagementException(errorMsg, opeEx); + } } @@ -167,10 +242,6 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem throw new ApplicationManagementException(msg, e); } - public DeviceManagementPluginRepository getPluginRepository() { - return pluginRepository; - } - @Override public void updateApplicationListInstalledInDevice( DeviceIdentifier deviceIdentifier, List applications) throws ApplicationManagementException { @@ -256,24 +327,4 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem } } - @Override - public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { - try { - pluginRepository.addDeviceManagementProvider(deviceManagementService); - } catch (DeviceManagementException e) { - log.error("Error occurred while registering device management plugin '" + - deviceManagementService.getType() + "'", e); - } - } - - @Override - public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) { - try { - pluginRepository.removeDeviceManagementProvider(deviceManagementService); - } catch (DeviceManagementException e) { - log.error("Error occurred while un-registering device management plugin '" + - deviceManagementService.getType() + "'", e); - } - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 646ca8b7965..7aa6bcf5383 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -101,7 +101,6 @@ import java.util.List; public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); - private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); private static final Object LOCK = new Object(); private static List listeners = new ArrayList<>(); @@ -208,7 +207,7 @@ public class DeviceManagementServiceComponent { AppManagementConfig appConfig = AppManagementConfigurationManager.getInstance().getAppManagementConfig(); bundleContext.registerService(ApplicationManagementProviderService.class.getName(), - new ApplicationManagerProviderServiceImpl(appConfig, pluginRepository), null); + new ApplicationManagerProviderServiceImpl(appConfig), null); } catch (ApplicationManagementException e) { log.error("Application management service not registered.", e); } @@ -309,10 +308,6 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setRegistryService(null); } - private DeviceManagementPluginRepository getPluginRepository() { - return pluginRepository; - } - protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { //do nothing } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index 0c3386fddf1..fa878e6327b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -77,7 +77,19 @@ public class TestDeviceManagementService implements DeviceManagementService { } @Override - public void installApplication(Operation operation, List deviceIdentifiers) + public void installApplicationForDevices(Operation operation, List deviceIdentifiers) + throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUserRoles(Operation operation, List userRoleList) throws ApplicationManagementException { } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java index c5b69b3a176..b98745f8a2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java @@ -83,7 +83,7 @@ public class ApplicationManagementProviderServiceTest { deviceId.setType(device.getType()); AppManagementConfig appManagementConfig = new AppManagementConfig(); - appMgtProvider = new ApplicationManagerProviderServiceImpl(deviceManagementPluginRepository); + appMgtProvider = new ApplicationManagerProviderServiceImpl(); try { appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml index ef7a146cdd1..44b57d20d18 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml @@ -17,7 +17,7 @@ ~ under the License. --> - - true - http:/www.google.com - + + true + http:/www.google.com + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml index ef7a146cdd1..0297d0fca0d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml @@ -20,4 +20,6 @@ true http:/www.google.com + http:/www.google.com + http:/www.google.com From c1eea6894d0241c63c599e0f198ad750ec6a2518 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 19 Nov 2015 14:45:08 +0530 Subject: [PATCH 5/8] Fixing the feature remove from the policy --- .../policy/mgt/core/dao/FeatureDAO.java | 2 ++ .../mgt/core/dao/impl/FeatureDAOImpl.java | 30 +++++++++++++++++-- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 18 ++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java index 3b8ecec20c0..b299fdd1210 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java @@ -123,4 +123,6 @@ public interface FeatureDAO { */ boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException; + boolean deleteProfileFeatures(int featureId) throws FeatureManagerDAOException; + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java index 0af516ac70a..196001c041d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java @@ -20,7 +20,6 @@ package org.wso2.carbon.policy.mgt.core.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Profile; @@ -28,14 +27,16 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO; import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException; 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.util.PolicyManagementDAOUtil; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -177,6 +178,29 @@ public class FeatureDAOImpl implements FeatureDAO { } } + + @Override + public boolean deleteProfileFeatures(int featureId) throws FeatureManagerDAOException { + Connection conn; + PreparedStatement stmt = null; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + conn = this.getConnection(); + String query = "DELETE FROM DM_PROFILE_FEATURES WHERE ID = ? AND TENANT_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, featureId); + stmt.setInt(2, tenantId); + if (stmt.executeUpdate() > 0) { + return true; + } + return false; + } catch (SQLException e) { + throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } + } + @Override public List getAllProfileFeatures() throws FeatureManagerDAOException { Connection conn; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 06b71d071a2..5c280c0baf4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -134,7 +134,7 @@ public class PolicyManagerImpl implements PolicyManager { public Policy updatePolicy(Policy policy) throws PolicyManagementException { try { - // Previous policy needs to be obtained before begining the transaction + // Previous policy needs to be obtained before beginning the transaction Policy previousPolicy = this.getPolicy(policy.getId()); PolicyManagementDAOFactory.beginTransaction(); @@ -144,7 +144,9 @@ public class PolicyManagerImpl implements PolicyManager { List existingFeaturesList = new ArrayList<>(); List newFeaturesList = new ArrayList<>(); + List feturesToDelete = new ArrayList<>(); List temp = new ArrayList<>(); + List updateDFes = new ArrayList<>(); List updatedFeatureList = policy.getProfile().getProfileFeaturesList(); @@ -158,6 +160,14 @@ public class PolicyManagerImpl implements PolicyManager { temp.add(feature.getFeatureCode()); } } + updateDFes.add(feature.getFeatureCode()); + } + + // Check for the features to delete + for(ProfileFeature feature : existingProfileFeaturesList) { + if(!updateDFes.contains(feature.getFeatureCode())){ + feturesToDelete.add(feature); + } } // Checks for the new features @@ -180,6 +190,12 @@ public class PolicyManagerImpl implements PolicyManager { if (!newFeaturesList.isEmpty()) { featureDAO.addProfileFeatures(newFeaturesList, profileId); } + + if(!feturesToDelete.isEmpty()){ + for (ProfileFeature pf : feturesToDelete) + featureDAO.deleteProfileFeatures(pf.getId()); + } + policyDAO.deleteCriteriaAndDeviceRelatedConfigs(policy.getId()); From b4d17b888b217335af06fd479b0c4510ff0f0bd5 Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 20 Nov 2015 00:43:01 +0530 Subject: [PATCH 6/8] fixed secondary user-store related issues & multi-tenancy issues --- .../DeviceAccessAuthorizationServiceImpl.java | 17 +++++++++++------ .../policy/mgt/core/util/PolicyManagerUtil.java | 2 +- .../framework/WebappAuthenticationValve.java | 2 +- .../authenticator/OAuthAuthenticator.java | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java index 47f1a8024e9..857f0f63e94 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java @@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.api.UserStoreManager; import java.util.HashMap; import java.util.List; @@ -215,7 +216,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori UserRealm userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId); if (userRealm != null && userRealm.getAuthorizationManager() != null) { return userRealm.getAuthorizationManager() - .isUserAuthorized(username, PermissionUtils.getAbsolutePermissionPath(EMM_ADMIN_PERMISSION), + .isUserAuthorized(removeTenantDomain(username), PermissionUtils.getAbsolutePermissionPath(EMM_ADMIN_PERMISSION), PermissionMethod.UI_EXECUTE); } return false; @@ -224,15 +225,19 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori private String getUserName() { String username = CarbonContext.getThreadLocalCarbonContext().getUsername(); if (username != null && !username.isEmpty()) { - String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); - if (username.endsWith(tenantDomain)) { - return username.substring(0, username.lastIndexOf("@")); - } - return username; + return removeTenantDomain(username); } return null; } + private String removeTenantDomain(String username) { + String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (username.endsWith(tenantDomain)) { + return username.substring(0, username.lastIndexOf("@")); + } + return username; + } + private int getTenantId() { return CarbonContext.getThreadLocalCarbonContext().getTenantId(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index 990cb24875d..26fd3db790e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -207,7 +207,7 @@ public class PolicyManagerUtil { if (configuration != null && !configuration.isEmpty()) { for (ConfigurationEntry cEntry : configuration) { if (cEntry.getName().equalsIgnoreCase(MONITORING_FREQUENCY)) { - monitoringFrequency = (int) cEntry.getValue(); + monitoringFrequency = Integer.parseInt((String)cEntry.getValue()); } } } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java index 25ef4165065..da8b4cfabc9 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java @@ -139,7 +139,7 @@ public class WebappAuthenticationValve extends CarbonTomcatValve { msg = authenticationInfo.getMessage(); response.setHeader("WWW-Authenticate", msg); } - log.error(msg); + log.error(msg + " , API : " + request.getRequestURI()); AuthenticationFrameworkUtil .handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, msg); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java index adc31a9c143..ca8eb6c7002 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java @@ -112,9 +112,9 @@ public class OAuthAuthenticator implements WebappAuthenticator { if (oAuth2TokenValidationResponseDTO.isValid()) { String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser(); //Remove the userstore domain from username - if (username.contains("/")) { + /*if (username.contains("/")) { username = username.substring(username.indexOf('/') + 1); - } + }*/ authenticationInfo.setUsername(username); authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username)); authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username)); From fe04f5b51e606005b6ba65957d912a341add8566 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 20 Nov 2015 19:51:45 +0530 Subject: [PATCH 7/8] Adding the source control management id --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index fd4032a8a6d..b85ea094895 100644 --- a/pom.xml +++ b/pom.xml @@ -1542,6 +1542,9 @@ 2.3.1 1.1.1 1.2 + + + github-scm From e1dc3d2ea3f84d7afbe0dc09e67f9ea33c5da43a Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 20 Nov 2015 22:14:18 +0530 Subject: [PATCH 8/8] add notify mechanisam to plugins for some operations - Ex -: IOS send push note to apns when add operation --- .../common/spi/DeviceManagementService.java | 6 ++++++ ...ApplicationManagerProviderServiceImpl.java | 9 +++++++++ .../DeviceManagementServiceComponent.java | 1 + .../operation/mgt/OperationManagerImpl.java | 1 + .../DeviceManagementProviderService.java | 3 ++- .../DeviceManagementProviderServiceImpl.java | 19 +++++++++++++++++++ .../mgt/core/TestDeviceManagementService.java | 6 ++++++ 7 files changed, 44 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index 053de06aed1..bf2e44f3d83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -18,9 +18,13 @@ */ package org.wso2.carbon.device.mgt.common.spi; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.operation.mgt.Operation; + +import java.util.List; /** * Composite interface that acts as the SPI exposing all device management as well as application management @@ -41,4 +45,6 @@ public interface DeviceManagementService extends ApplicationManager { ApplicationManager getApplicationManager(); + void notifyOperationToDevices(Operation operation, List deviceIds) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 6f63f034192..c0a8318af1a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -32,13 +32,16 @@ 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.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.dao.*; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; +import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; @@ -112,10 +115,16 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem try { DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, deviceIds); + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices + (operation, deviceIds); } catch (OperationManagementException opeEx) { String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); log.error(errorMsg, opeEx); throw new ApplicationManagementException(errorMsg, opeEx); + }catch (DeviceManagementException deviceEx){ + String errorMsg = "Error in notify operation at app installation:" + deviceEx.getErrorMessage(); + log.error(errorMsg, deviceEx); + throw new ApplicationManagementException(errorMsg, deviceEx); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 7aa6bcf5383..89cbf660cb1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -106,6 +106,7 @@ public class DeviceManagementServiceComponent { private static List listeners = new ArrayList<>(); private static List deviceManagers = new ArrayList<>(); private static List startupListeners = new ArrayList<>(); + private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); @SuppressWarnings("unused") protected void activate(ComponentContext componentContext) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 3238fcdb322..58cb057153c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization 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.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 5592be55b27..4ab5651cffd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.dto.DeviceType; @@ -161,6 +162,6 @@ public interface DeviceManagementProviderService extends OperationManager { boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException; - + void notifyOperationToDevices(Operation operation, List deviceIds)throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 6a49235aef3..5e211a48848 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; @@ -792,6 +793,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } + @Override + public void notifyOperationToDevices(Operation operation, List deviceIds) + throws DeviceManagementException { + + try { + for (DeviceIdentifier deviceId : deviceIds) { + DeviceManagementService dms = + getPluginRepository().getDeviceManagementService(deviceId.getType()); + dms.notifyOperationToDevices(operation, deviceIds); + } + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error in notify operations to plugins for app installation:" + deviceMgtEx.getErrorMessage(); + log.error(errorMsg, deviceMgtEx); + throw new DeviceManagementException(errorMsg, deviceMgtEx); + } + + } + @Override public License getLicense(String deviceType, String languageCode) throws DeviceManagementException { DeviceManager deviceManager = this.getDeviceManager(deviceType); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index fa878e6327b..63128cbbdda 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -58,6 +58,12 @@ public class TestDeviceManagementService implements DeviceManagementService { return null; } + @Override + public void notifyOperationToDevices(Operation operation, List deviceIds) + throws DeviceManagementException { + + } + @Override public Application[] getApplications(String domain, int pageNumber, int size) throws ApplicationManagementException {