private void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyManagementException { try { String type = null; if (deviceIdentifiers.size() > 0) { type = deviceIdentifiers.get(0).getType(); PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, this.getPolicyRevokeOperation(), deviceIdentifiers); } } catch (InvalidDeviceException e) { String msg = "Invalid DeviceIdentifiers found."; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (OperationManagementException e) { String msg = "Error occurred while adding the operation to device."; log.error(msg, e); throw new PolicyManagementException(msg, e); } }
@Override public void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyDelegationException { try { String type = null; if (deviceIdentifiers.size() > 0) { type = deviceIdentifiers.get(0).getType(); } PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, this.getPolicyRevokeOperation(), deviceIdentifiers); } catch (InvalidDeviceException e) { String msg = "Invalid DeviceIdentifiers found."; log.error(msg, e); throw new PolicyDelegationException(msg, e); } catch (OperationManagementException e) { String msg = "Error occurred while adding the operation to device."; log.error(msg, e); throw new PolicyDelegationException(msg, e); } }
@Override public void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws PolicyDelegationException { try { String type = null; if (deviceIdentifiers.size() > 0) { type = deviceIdentifiers.get(0).getType(); } PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers); } catch (InvalidDeviceException e) { String msg = "Invalid DeviceIdentifiers found."; log.error(msg, e); throw new PolicyDelegationException(msg, e); } catch (OperationManagementException e) { String msg = "Error occurred while adding the operation to device."; log.error(msg, e); throw new PolicyDelegationException(msg, e); } }
@Override public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { try { PolicyEvaluationPoint policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); if (policyEvaluationPoint != null) { return policyEvaluationPoint.getEffectiveFeatures(deviceIdentifier); } else { throw new FeatureManagementException("Error occurred while getting the policy evaluation point " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); } } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective features from the PEP service " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new FeatureManagementException(msg, e); } }
@Override public void markDeviceAsCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { DeviceManagementProviderService service = this.getDeviceManagementProviderService(); Device device = service.getDevice(deviceIdentifier, false); service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), EnrolmentInfo.Status.ACTIVE); } catch (DeviceManagementException e) { String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); } }
} else { throw new PolicyEvaluationException("Error occurred while getting the policy evaluation point " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); type = deviceIdentifiers.get(0).getType(); } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective policies from the PEP service for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (OperationManagementException e) { String msg = "Error occurred while adding the effective feature to database." + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyManagementException(msg, e);
@Override public void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { DeviceManagementProviderService service = this.getDeviceManagementProviderService(); Device device = service.getDevice(deviceIdentifier, false); service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), EnrolmentInfo.Status.ACTIVE); } catch (DeviceManagementException e) { String msg = "Error occurred while setting the device as reachable for " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyComplianceException(msg, e); } }
@Override public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { DeviceManagementProviderService service = this.getDeviceManagementProviderService(); Device device = service.getDevice(deviceIdentifier, false); service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), EnrolmentInfo.Status.INACTIVE); } catch (DeviceManagementException e) { String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyComplianceException(msg, e); } }
@Override public void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { DeviceManagementProviderService service = this.getDeviceManagementProviderService(); Device device = service.getDevice(deviceIdentifier, false); service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), EnrolmentInfo.Status.ACTIVE); } catch (DeviceManagementException e) { String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyComplianceException(msg, e); } }
private void addMonitoringOperationsToDatabase(List<Device> devices) throws PolicyComplianceException, OperationManagementException, InvalidDeviceException { List<DeviceIdentifier> deviceIdentifiers = this.getDeviceIdentifiersFromDevices(devices); CommandOperation monitoringOperation = new CommandOperation(); monitoringOperation.setEnabled(true); monitoringOperation.setType(Operation.Type.COMMAND); monitoringOperation.setCode(OPERATION_MONITOR); // CommandOperation infoOperation = new CommandOperation(); // infoOperation.setEnabled(true); // infoOperation.setType(Operation.Type.COMMAND);\\ // infoOperation.setCode(OPERATION_INFO); // CommandOperation appListOperation = new CommandOperation(); // appListOperation.setEnabled(true); // appListOperation.setType(Operation.Type.COMMAND); // appListOperation.setCode(OPERATION_APP_LIST); //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()" String type = null; if (deviceIdentifiers.size() > 0) { type = deviceIdentifiers.get(0).getType(); } DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); service.addOperation(type, monitoringOperation, deviceIdentifiers); // service.addOperation(infoOperation, deviceIdentifiers); // service.addOperation(appListOperation, deviceIdentifiers); }
} catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while getting the policies for device identifier (" + 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) { throw new PolicyManagementException("Error occurred while open a data source connection", e);
@Override public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceId) throws PolicyManagementException { Policy policy; DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); Device device; try { device = service.getDevice(deviceId, false); if (device == null) { if (log.isDebugEnabled()) { log.debug("No device is found upon the device identifier '" + deviceId.getId() + "' and type '" + deviceId.getType() + "'. Therefore returning null"); } return null; } } catch (DeviceManagementException e) { throw new PolicyManagementException("Error occurred while getting device id.", e); } try { //int policyId = policyDAO.getAppliedPolicyId(device.getId()); PolicyManagementDAOFactory.openConnection(); policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId()); } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while getting policy id or policy.", e); } catch (SQLException e) { throw new PolicyManagementException("Error occurred while opening a connection to the data source", e); } finally { PolicyManagementDAOFactory.closeConnection(); } return policy; }
@Override public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { Device device; try { DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); device = service.getDevice(deviceIdentifier, false); } catch (DeviceManagementException e) { throw new PolicyComplianceException("Unable to retrieve device data for " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } try { PolicyManagementDAOFactory.openConnection(); NonComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo() .getId()); if (complianceData != null && !complianceData.isStatus()) { return false; } } catch (MonitoringDAOException e) { throw new PolicyComplianceException("Unable to retrieve compliance status for " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } catch (SQLException e) { throw new PolicyComplianceException("Error occurred while opening a connection to the data source", e); } finally { PolicyManagementDAOFactory.closeConnection(); } return true; }
@Override public NonComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { NonComplianceData complianceData; try { PolicyManagementDAOFactory.openConnection(); DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); Device device = service.getDevice(deviceIdentifier, false); complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId()); List<ComplianceFeature> complianceFeatures = monitoringDAO.getNoneComplianceFeatures(complianceData.getId()); complianceData.setComplianceFeatures(complianceFeatures); } catch (DeviceManagementException e) { throw new PolicyComplianceException("Unable to retrieve device data for " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } catch (MonitoringDAOException e) { throw new PolicyComplianceException("Unable to retrieve compliance data for " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } catch (SQLException e) { throw new PolicyComplianceException("Error occurred while opening a connection to the data source", e); } finally { PolicyManagementDAOFactory.closeConnection(); } return complianceData; }
if (policy != null) { PolicyMonitoringManager monitoringService = PolicyManagementDataHolder.getInstance(). getDeviceManagementService().getPolicyMonitoringManager(deviceIdentifier.getType()); throw new PolicyComplianceException( "Unable to add the none compliance features to database for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } finally { PolicyManagementDAOFactory.closeConnection(); throw new PolicyComplianceException( "Unable to add the none compliance features to database for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } finally { PolicyManagementDAOFactory.closeConnection(); throw new PolicyComplianceException( "Unable to remove the none compliance features from database for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } finally { PolicyManagementDAOFactory.closeConnection(); deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); } catch (PolicyManagerDAOException | PolicyManagementException e) { throw new PolicyComplianceException("Unable tor retrieve policy data from DB for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
Device device; DeviceType deviceType = new DeviceType(); deviceType.setName(deviceIdentifier.getType()); DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl(); GroupManagementProviderService groupManagementProviderService = new GroupManagementProviderServiceImpl();