|
|
@ -19,12 +19,17 @@ package org.wso2.carbon.device.mgt.core.service;
|
|
|
|
|
|
|
|
|
|
|
|
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.CarbonConstants;
|
|
|
|
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.app.mgt.Application;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
|
|
|
|
|
|
|
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.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.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
@ -32,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.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
|
|
|
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.dao.*;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
|
|
|
@ -130,7 +136,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deviceManager.enrollDevice(device);
|
|
|
|
deviceManager.enrollDevice(device);
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceManager.isClaimable(deviceIdentifier)) {
|
|
|
|
if (deviceManager.isClaimable(deviceIdentifier)) {
|
|
|
|
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE);
|
|
|
|
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -221,6 +226,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
status = true;
|
|
|
|
status = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
|
|
|
|
addDeviceToGroups(deviceIdentifier, device.getEnrolmentInfo().getOwnership());
|
|
|
|
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1834,4 +1842,58 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
return deviceManagementService.getDeviceManager();
|
|
|
|
return deviceManagementService.getDeviceManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Adds the enrolled devices to the default groups based on ownership
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceIdentifier of the device.
|
|
|
|
|
|
|
|
* @param ownership of the device.
|
|
|
|
|
|
|
|
* @throws DeviceManagementException If error occurred in adding the device to the group.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void addDeviceToGroups(DeviceIdentifier deviceIdentifier, EnrolmentInfo.OwnerShip ownership)
|
|
|
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
|
|
|
GroupManagementProviderService groupManagementProviderService = new GroupManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceGroup defaultGroup = createDefaultGroup(groupManagementProviderService, ownership.toString());
|
|
|
|
|
|
|
|
if (defaultGroup != null) {
|
|
|
|
|
|
|
|
groupManagementProviderService.addDevice(defaultGroup.getGroupId(), deviceIdentifier);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(),
|
|
|
|
|
|
|
|
e);
|
|
|
|
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException("An error occurred when adding the device to the group.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Checks for the default group existence and create group based on device ownership
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param service {@link GroupManagementProviderService} instance.
|
|
|
|
|
|
|
|
* @param groupName of the group to create.
|
|
|
|
|
|
|
|
* @return Group with details.
|
|
|
|
|
|
|
|
* @throws GroupManagementException
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private DeviceGroup createDefaultGroup(GroupManagementProviderService service, String groupName)
|
|
|
|
|
|
|
|
throws GroupManagementException {
|
|
|
|
|
|
|
|
DeviceGroup defaultGroup = service.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.setDateOfCreation(new Date().getTime());
|
|
|
|
|
|
|
|
defaultGroup.setDateOfLastUpdate(new Date().getTime());
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
service.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 service.getGroup(groupName);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return defaultGroup;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|