@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { Device device; try { if (log.isDebugEnabled()) { log.debug("Getting the details of Arduino device : " + deviceId.getId()); } device = arduinoDAO.getDeviceDAO().getDevice(deviceId.getId()); } catch (ArduinoDeviceMgtPluginException e) { String msg = "Error while fetching the Arduino device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return device; }
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { Device device; try { if (log.isDebugEnabled()) { log.debug("Getting the details of Raspberrypi device : " + deviceId.getId()); } device = raspberrypiDAO.getDeviceDAO().getDevice(deviceId.getId()); } catch (RaspberrypiDeviceMgtPluginException e) { String msg = "Error while fetching the Raspberrypi device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return device; }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Raspberrypi device : " + deviceId.getId()); } Device iotDevice = raspberrypiDAO.getDeviceDAO().getDevice(deviceId.getId()); if (iotDevice != null) { isEnrolled = true; } } catch (RaspberrypiDeviceMgtPluginException e) { String msg = "Error while checking the enrollment status of Raspberrypi device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return isEnrolled; }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Android device : " + deviceId.getId()); } MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); if (mobileDevice != null) { isEnrolled = true; } } catch (MobileDeviceManagementDAOException e) { String msg = "Error while checking the enrollment status of Android device : " + deviceId.getId(); throw new DeviceManagementException(msg, e); } return isEnrolled; }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Arduino device : " + deviceId.getId()); } Device iotDevice = arduinoDAO.getDeviceDAO().getDevice(deviceId.getId()); if (iotDevice != null) { isEnrolled = true; } } catch (ArduinoDeviceMgtPluginException e) { String msg = "Error while checking the enrollment status of Arduino device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return isEnrolled; }
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Windows device : " + deviceId.getId()); } MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); if (mobileDevice != null) { isEnrolled = true; } } catch (MobileDeviceManagementDAOException e) { String msg = "Error while checking the enrollment status of Windows device : " + deviceId.getId(); throw new DeviceManagementException(msg, e); } return isEnrolled; }
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { Device device; try { if (log.isDebugEnabled()) { log.debug("Getting the details of Android device : '" + deviceId.getId() + "'"); } MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO(). getMobileDevice(deviceId.getId()); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException( "Error occurred while fetching the Android device: '" + deviceId.getId() + "'", e); } return device; }
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { Device device = null; try { if (log.isDebugEnabled()) { log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'"); } WindowsDAOFactory.openConnection(); MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO(). getMobileDevice(deviceId.getId()); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException( "Error occurred while fetching the Windows device: '" + deviceId.getId() + "'", e); } finally { WindowsDAOFactory.closeConnection(); } return device; }
@Override public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload) throws PolicyComplianceException { if (log.isDebugEnabled()) { log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); } List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) compliancePayload; List<ComplianceFeature> nonComplianceFeatures = new ArrayList<>(); ComplianceData complianceData = new ComplianceData(); if (policy == null || compliancePayload == null) { return complianceData; } for (ComplianceFeature complianceFeature : complianceFeatures) { if (!complianceFeature.isCompliant()) { complianceData.setStatus(false); nonComplianceFeatures.add(complianceFeature); break; } } complianceData.setComplianceFeatures(nonComplianceFeatures); return complianceData; }
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { boolean status; try { if (log.isDebugEnabled()) { log.debug("Dis-enrolling Arduino device : " + deviceId); } ArduinoDAOUtil.beginTransaction(); status = arduinoDAO.getDeviceDAO().deleteDevice(deviceId.getId()); ArduinoDAOUtil.commitTransaction(); } catch (ArduinoDeviceMgtPluginException e) { try { ArduinoDAOUtil.rollbackTransaction(); } catch (ArduinoDeviceMgtPluginException iotDAOEx) { String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString(); log.warn(msg, iotDAOEx); } String msg = "Error while removing the Arduino device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return status; }
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { boolean status; try { if (log.isDebugEnabled()) { log.debug("Dis-enrolling Raspberrypi device : " + deviceId); } RaspberrypiDAOUtil.beginTransaction(); status = raspberrypiDAO.getDeviceDAO().deleteDevice(deviceId.getId()); RaspberrypiDAOUtil.commitTransaction(); } catch (RaspberrypiDeviceMgtPluginException e) { try { RaspberrypiDAOUtil.rollbackTransaction(); } catch (RaspberrypiDeviceMgtPluginException iotDAOEx) { String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString(); log.warn(msg, iotDAOEx); } String msg = "Error while removing the Raspberrypi device : " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } return status; }
@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); } }
@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); } }
@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 boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { try { DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); Device device = service.getDevice(deviceIdentifier, false); PolicyManagementDAOFactory.openConnection(); policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId()); return true; } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while setting the policy has applied to device (" + deviceIdentifier.getId() + ")", e); } catch (DeviceManagementException e) { throw new PolicyManagementException("Error occurred while getting the device details (" + deviceIdentifier.getId() + ")", e); } catch (SQLException e) { throw new PolicyManagementException("Error occurred while opening a connection to the data source", e); } finally { PolicyManagementDAOFactory.closeConnection(); } }
@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 boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { boolean exist; try { DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); Device device = service.getDevice(deviceIdentifier, false); PolicyManagementDAOFactory.openConnection(); exist = policyDAO.checkPolicyAvailable(device.getId(), device.getEnrolmentInfo().getId()); } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while checking whether device has a policy " + "to apply.", e); } catch (DeviceManagementException e) { throw new PolicyManagementException("Error occurred while getting the device details (" + deviceIdentifier.getId() + ")", e); } catch (SQLException e) { throw new PolicyManagementException("Error occurred while opening a connection to the data source", e); } finally { PolicyManagementDAOFactory.closeConnection(); } return exist; }
@Override public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException { int deviceId = -1; try { DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); Device device = service.getDevice(deviceIdentifier, false); deviceId = device.getId(); PolicyManagementDAOFactory.beginTransaction(); Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); if (policySaved != null && policySaved.getId() != 0) { policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); } else { policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); } PolicyManagementDAOFactory.commitTransaction(); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while adding the evaluated policy to device (" + deviceId + " - " + policy.getId() + ")", e); } catch (DeviceManagementException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while getting the device details (" + deviceIdentifier.getId() + ")", e); } finally { PolicyManagementDAOFactory.closeConnection(); } }