From 2164a30f8805313f2c6ba7bea858adb3e8c4d91c Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Mon, 21 Nov 2016 16:16:00 +0530 Subject: [PATCH] changing group owner to super user Changing the owner of the default system generated groups from the group creator to the super user of the system. --- .../DeviceManagementProviderServiceImpl.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 37d9cb9fe3..6c62345aaa 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 @@ -37,6 +37,7 @@ 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.DeviceManagementPluginRepository; +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.device.details.mgt.dao.DeviceDetailsDAO; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException; @@ -1868,7 +1869,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } catch (DeviceNotFoundException e) { throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(), e); - } catch (GroupManagementException | GroupAlreadyExistException e) { + } catch (GroupManagementException | UserStoreException e) { throw new DeviceManagementException("An error occurred when adding the device to the group.", e); } } @@ -1876,19 +1877,20 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv /** * Checks for the default group existence and create group based on device ownership * - * @param service {@link GroupManagementProviderService} + * @param service {@link GroupManagementProviderService} instance. * @param groupName of the group to create. * @param groupDescription of the group to create. * @return Group with details. * @throws GroupManagementException - * @throws GroupAlreadyExistException */ private DeviceGroup createDefaultGroup(GroupManagementProviderService service, String groupName, - String groupDescription) throws GroupManagementException, GroupAlreadyExistException { + String groupDescription) throws GroupManagementException, UserStoreException { DeviceGroup defaultGroup = service.getGroup(groupName); if (defaultGroup == null) { defaultGroup = new DeviceGroup(groupName, groupDescription); - defaultGroup.setOwner(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); + defaultGroup.setOwner( + PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() + .getAdminUserName()); defaultGroup.setDateOfCreation(new Date().getTime()); defaultGroup.setDateOfLastUpdate(new Date().getTime()); try { @@ -1896,7 +1898,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS); } catch (GroupAlreadyExistException e) { if (log.isDebugEnabled()) { - log.debug("Default group: " + defaultGroup.getName() + " already exists.", e); + log.debug("Default group: " + defaultGroup.getName() + " already exists. Skipping group creation.", + e); } } return service.getGroup(groupName);