|
|
@ -56,9 +56,7 @@ import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.policy.mgt.common.*;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.*;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
|
|
@ -74,12 +72,12 @@ import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
private PolicyDAO policyDAO;
|
|
|
|
private final PolicyDAO policyDAO;
|
|
|
|
private ProfileDAO profileDAO;
|
|
|
|
private final ProfileDAO profileDAO;
|
|
|
|
private FeatureDAO featureDAO;
|
|
|
|
private final FeatureDAO featureDAO;
|
|
|
|
private ProfileManager profileManager;
|
|
|
|
private final ProfileManager profileManager;
|
|
|
|
private PolicyConfiguration policyConfiguration;
|
|
|
|
private final PolicyConfiguration policyConfiguration;
|
|
|
|
private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(PolicyManagerImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
public PolicyManagerImpl() {
|
|
|
|
public PolicyManagerImpl() {
|
|
|
|
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
|
|
|
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
|
|
@ -495,10 +493,11 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
Policy policy) throws PolicyManagementException {
|
|
|
|
Policy policy) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
Device device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
deviceList.add(device);
|
|
|
|
deviceList.add(device);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while retrieving device information", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while retrieving device information", e);
|
|
|
@ -732,19 +731,23 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting device related to device identifier (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policyIdList = policyDAO.getPolicyIdsOfDevice(device);
|
|
|
|
policyIdList = policyDAO.getPolicyIdsOfDevice(device);
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policies for device identifier (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policies for device identifier (" +
|
|
|
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")", e);
|
|
|
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting device related to device identifier (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")", e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while open a data source connection", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while open a data source connection", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -814,7 +817,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policyIdList = policyDAO.getPolicyOfRole(roleName);
|
|
|
|
policyIdList = policyDAO.getPolicyOfRole(roleName);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policies.", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policies.", e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -882,9 +884,16 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Integer> deviceIds;
|
|
|
|
List<Integer> deviceIds;
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
List<Device> allDevices;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
allDevices = deviceManagementService.getAllDevices();
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the devices related to policy id (" +
|
|
|
|
|
|
|
|
policyId + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
List<Device> allDevices = service.getAllDevices();
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
|
|
|
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
|
|
|
HashMap<Integer, Device> allDeviceMap = new HashMap<>();
|
|
|
|
HashMap<Integer, Device> allDeviceMap = new HashMap<>();
|
|
|
@ -906,9 +915,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
policyId + ")", e);
|
|
|
|
policyId + ")", e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the devices related to policy id (" +
|
|
|
|
|
|
|
|
policyId + ")", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -918,12 +924,17 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier,
|
|
|
|
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier,
|
|
|
|
Policy policy) throws PolicyManagementException {
|
|
|
|
Policy policy) throws PolicyManagementException {
|
|
|
|
int deviceId = -1;
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int deviceId = device.getId();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
deviceId = device.getId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
boolean exist = policyDAO.checkPolicyAvailable(deviceId, device.getEnrolmentInfo().getId());
|
|
|
|
boolean exist = policyDAO.checkPolicyAvailable(deviceId, device.getEnrolmentInfo().getId());
|
|
|
|
if (exist) {
|
|
|
|
if (exist) {
|
|
|
@ -936,9 +947,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the evaluated policy to device (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the evaluated policy to device (" +
|
|
|
|
deviceId + " - " + policy.getId() + ")", e);
|
|
|
|
deviceId + " - " + policy.getId() + ")", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -997,12 +1005,18 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
|
|
|
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
|
|
|
throws PolicyManagementException {
|
|
|
|
throws PolicyManagementException {
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
int deviceId = -1;
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int deviceId = device.getId();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
deviceId = device.getId();
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
|
|
|
|
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
|
|
|
@ -1016,10 +1030,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the evaluated policy to device (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the evaluated policy to device (" +
|
|
|
|
deviceId + " - " + policy.getId() + ")", e);
|
|
|
|
deviceId + " - " + policy.getId() + ")", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1027,12 +1037,18 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void removeAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public void removeAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
int deviceId = -1;
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int deviceId = device.getId();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
deviceId = device.getId();
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
|
|
|
|
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
|
|
|
@ -1044,10 +1060,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new PolicyManagementException("Error occurred while removing the applied policy to device (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while removing the applied policy to device (" +
|
|
|
|
deviceId + ")", e);
|
|
|
|
deviceId + ")", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1057,17 +1069,21 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
boolean exist;
|
|
|
|
boolean exist;
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
exist = policyDAO.checkPolicyAvailable(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
exist = policyDAO.checkPolicyAvailable(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while checking whether device has a policy " +
|
|
|
|
throw new PolicyManagementException("Error occurred while checking whether device has a policy " +
|
|
|
|
"to apply.", e);
|
|
|
|
"to apply.", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -1078,19 +1094,24 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
device = deviceManagementService.getDevice(deviceIdentifier, false);
|
|
|
|
Device device = service.getDevice(deviceIdentifier, false);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while setting the policy has applied to device (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while setting the policy has applied to device (" +
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -1115,10 +1136,11 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
@Deprecated
|
|
|
|
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceId) throws PolicyManagementException {
|
|
|
|
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceId) throws PolicyManagementException {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
Device device;
|
|
|
|
Device device;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = service.getDevice(deviceId, false);
|
|
|
|
device = deviceManagementService.getDevice(deviceId, false);
|
|
|
|
if (device == null) {
|
|
|
|
if (device == null) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
|
|
|
|
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
|
|
|
@ -1163,17 +1185,18 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceGroupWrapper> getDeviceGroupNames(List<DeviceGroupWrapper> groupWrappers) throws GroupManagementException {
|
|
|
|
private List<DeviceGroupWrapper> getDeviceGroupNames(List<DeviceGroupWrapper> groupWrappers)
|
|
|
|
GroupManagementProviderService groupManagementProviderService = new GroupManagementProviderServiceImpl();
|
|
|
|
throws GroupManagementException {
|
|
|
|
|
|
|
|
GroupManagementProviderService groupManagementService = PolicyManagementDataHolder
|
|
|
|
|
|
|
|
.getInstance().getGroupManagementService();
|
|
|
|
for (DeviceGroupWrapper wrapper : groupWrappers) {
|
|
|
|
for (DeviceGroupWrapper wrapper : groupWrappers) {
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(wrapper.getId(), false);
|
|
|
|
DeviceGroup deviceGroup = groupManagementService.getGroup(wrapper.getId(), false);
|
|
|
|
wrapper.setName(deviceGroup.getName());
|
|
|
|
wrapper.setName(deviceGroup.getName());
|
|
|
|
wrapper.setOwner(deviceGroup.getOwner());
|
|
|
|
wrapper.setOwner(deviceGroup.getOwner());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return groupWrappers;
|
|
|
|
return groupWrappers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<DeviceIdentifier> convertDevices(List<Device> devices) {
|
|
|
|
private List<DeviceIdentifier> convertDevices(List<Device> devices) {
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
for (Device device : devices) {
|
|
|
|
for (Device device : devices) {
|
|
|
@ -1185,7 +1208,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
return deviceIdentifiers;
|
|
|
|
return deviceIdentifiers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyManagementException {
|
|
|
|
private void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String type = null;
|
|
|
|
String type = null;
|
|
|
|