mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
This commit is contained in:
parent
94d270863e
commit
afe312152f
@ -47,6 +47,7 @@ public final class DeviceManagementConfig {
|
|||||||
private DeviceStatusTaskConfig deviceStatusTaskConfig;
|
private DeviceStatusTaskConfig deviceStatusTaskConfig;
|
||||||
private DeviceCacheConfiguration deviceCacheConfiguration;
|
private DeviceCacheConfiguration deviceCacheConfiguration;
|
||||||
private GeoLocationConfiguration geoLocationConfiguration;
|
private GeoLocationConfiguration geoLocationConfiguration;
|
||||||
|
private String defaultGroupsConfiguration;
|
||||||
|
|
||||||
@XmlElement(name = "ManagementRepository", required = true)
|
@XmlElement(name = "ManagementRepository", required = true)
|
||||||
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
|
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
|
||||||
@ -138,5 +139,14 @@ public final class DeviceManagementConfig {
|
|||||||
public void setGeoLocationConfiguration(GeoLocationConfiguration geoLocationConfiguration) {
|
public void setGeoLocationConfiguration(GeoLocationConfiguration geoLocationConfiguration) {
|
||||||
this.geoLocationConfiguration = geoLocationConfiguration;
|
this.geoLocationConfiguration = geoLocationConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "DefaultGroupsConfiguration", required = true)
|
||||||
|
public String getDefaultGroupsConfiguration() {
|
||||||
|
return defaultGroupsConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultGroupsConfiguration(String defaultGroupsConfiguration) {
|
||||||
|
this.defaultGroupsConfiguration = defaultGroupsConfiguration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoService;
|
import org.wso2.carbon.device.mgt.common.geo.service.GeoService;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
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.operation.mgt.OperationManager;
|
||||||
@ -253,6 +254,21 @@ public class DeviceManagementServiceComponent {
|
|||||||
|
|
||||||
/* Registering Group Management Service */
|
/* Registering Group Management Service */
|
||||||
GroupManagementProviderService groupManagementProvider = new GroupManagementProviderServiceImpl();
|
GroupManagementProviderService groupManagementProvider = new GroupManagementProviderServiceImpl();
|
||||||
|
String defaultGroups =
|
||||||
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getDefaultGroupsConfiguration();
|
||||||
|
List<String> groups = this.parseDefaultGroups(defaultGroups);
|
||||||
|
for(String group : groups){
|
||||||
|
try {
|
||||||
|
groupManagementProvider.createDefaultGroup(group);
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
// Error is ignored, because error could be group already exist exception. Therefore it does not require
|
||||||
|
// to print the error.
|
||||||
|
if(log.isDebugEnabled()){
|
||||||
|
log.error("Error occurred while adding the group");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(groupManagementProvider);
|
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(groupManagementProvider);
|
||||||
bundleContext.registerService(GroupManagementProviderService.class.getName(), groupManagementProvider, null);
|
bundleContext.registerService(GroupManagementProviderService.class.getName(), groupManagementProvider, null);
|
||||||
|
|
||||||
@ -311,6 +327,19 @@ public class DeviceManagementServiceComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> parseDefaultGroups(String defaultGroups) {
|
||||||
|
List<String> defaultGroupsList = new ArrayList<>();
|
||||||
|
if (defaultGroups != null && !defaultGroups.isEmpty()) {
|
||||||
|
String gps[] = defaultGroups.split(",");
|
||||||
|
if (gps.length != 0) {
|
||||||
|
for(String group : gps){
|
||||||
|
defaultGroupsList.add(group.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultGroupsList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Device Manager service.
|
* Sets Device Manager service.
|
||||||
*
|
*
|
||||||
@ -320,7 +349,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Setting Device Management Service Provider: '" +
|
log.debug("Setting Device Management Service Provider: '" +
|
||||||
deviceManagementService.getType() + "'");
|
deviceManagementService.getType() + "'");
|
||||||
}
|
}
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
deviceManagers.add(deviceManagementService);
|
deviceManagers.add(deviceManagementService);
|
||||||
|
|||||||
@ -212,4 +212,12 @@ public interface GroupManagementProviderService {
|
|||||||
*/
|
*/
|
||||||
List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException;
|
List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for the default group existence and create group based on device ownership.
|
||||||
|
* @param groupName
|
||||||
|
* @return
|
||||||
|
* @throws GroupManagementException
|
||||||
|
*/
|
||||||
|
DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,10 +30,7 @@ import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
|||||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
import org.wso2.carbon.device.mgt.common.group.mgt.*;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||||
@ -572,4 +569,31 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
GroupManagementDAOFactory.closeConnection();
|
GroupManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException {
|
||||||
|
|
||||||
|
DeviceGroup defaultGroup = this.getGroup(groupName);
|
||||||
|
if (defaultGroup == null) {
|
||||||
|
defaultGroup = new DeviceGroup(groupName);
|
||||||
|
// Setting system level user (wso2.system.user) as the owner
|
||||||
|
defaultGroup.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
|
||||||
|
defaultGroup.setDescription("Default system group for devices with " + groupName + " ownership.");
|
||||||
|
try {
|
||||||
|
this.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE,
|
||||||
|
DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS);
|
||||||
|
} catch (GroupAlreadyExistException e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Default group: " + defaultGroup.getName() + " already exists. Skipping group creation.",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.getGroup(groupName);
|
||||||
|
} else {
|
||||||
|
return defaultGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,5 +82,6 @@
|
|||||||
<isEnabled>false</isEnabled>
|
<isEnabled>false</isEnabled>
|
||||||
<PublishLocationOperationResponse>false</PublishLocationOperationResponse>
|
<PublishLocationOperationResponse>false</PublishLocationOperationResponse>
|
||||||
</GeoLocationConfiguration>
|
</GeoLocationConfiguration>
|
||||||
|
<DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration>
|
||||||
</DeviceMgtConfiguration>
|
</DeviceMgtConfiguration>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user