diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 82f3989017..c3c1362c30 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; +import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginUtils; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.Resource; @@ -56,6 +57,12 @@ public class WindowsDeviceManager implements DeviceManager { public WindowsDeviceManager() { this.daoFactory = new WindowsDAOFactory(); this.licenseManager = new RegistryBasedLicenseManager(); + License defaultLicense = WindowsPluginUtils.getDefaultLicense(); + try { + licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); + } catch (LicenseManagementException e) { + log.error("Error occurred while adding default license for Windows devices", e); + } } @Override @@ -66,7 +73,7 @@ public class WindowsDeviceManager implements DeviceManager { @Override public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException { - boolean status = false; + boolean status; Resource resource; try { if (log.isDebugEnabled()) { @@ -243,7 +250,7 @@ public class WindowsDeviceManager implements DeviceManager { @Override public License getLicense(String languageCode) throws LicenseManagementException { - return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode); + return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java index f1034d4ce7..b4bb0bac15 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java @@ -18,26 +18,52 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; +import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; +import java.util.ArrayList; import java.util.List; public class WindowsPolicyMonitoringService implements PolicyMonitoringService { + private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class); + @Override public void notifyDevices(List list) throws PolicyComplianceException { } @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException { - return null; + 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 complianceFeatures = (List) compliancePayload; + List 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 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index c3fd864d9c..3c1ba0424b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -117,8 +117,6 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory } } catch (SQLException e) { log.error("Error occurred while committing the transaction", e); - } finally { - closeConnection(); } } @@ -145,8 +143,6 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory } } catch (SQLException e) { log.warn("Error occurred while roll-backing the transaction", e); - } finally { - closeConnection(); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java index bb9910ac0e..237f881687 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java @@ -53,7 +53,8 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { conn = WindowsDAOFactory.getConnection(); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS, OS_VERSION, DEVICE_NAME " + + "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + + " OS_VERSION, DEVICE_NAME " + "FROM WINDOWS_DEVICE WHERE MOBILE_DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); @@ -62,17 +63,21 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { while (rs.next()) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.MOBILE_DEVICE_ID)); - mobileDevice.setVendor(rs.getString(WindowsPluginConstants.IMEI)); - mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.IMSI)); - mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.OS_VERSION)); - mobileDevice.setImei(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); - mobileDevice.setImsi(rs.getString(WindowsPluginConstants.VENDOR)); + mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI)); + mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI)); + mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); + mobileDevice.setVendor(rs.getString(WindowsPluginConstants.VENDOR)); + mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.LATITUDE)); + mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.LONGITUDE)); + mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL)); mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); Map propertyMap = new HashMap(); propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); + propertyMap.put(WindowsPluginConstants.MAC_ADDRESS, rs.getString(WindowsPluginConstants.MAC_ADDRESS)); propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME)); + mobileDevice.setDeviceProperties(propertyMap); } if (log.isDebugEnabled()) { @@ -214,7 +219,8 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { conn = WindowsDAOFactory.getConnection(); String selectDBQuery = "SELECT MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS, OS_VERSION, DEVICE_NAME " + + "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + + " OS_VERSION, DEVICE_NAME " + "FROM WINDOWS_DEVICE"; stmt = conn.prepareStatement(selectDBQuery); rs = stmt.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java index 05e4f6fe5a..50f8f15c3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java @@ -25,7 +25,7 @@ public class WindowsPluginConstants { //properties related to database table WINDOWS_DEVICE public static final String MOBILE_DEVICE_ID = "MOBILE_DEVICE_ID"; - public static final String CHANNEL_URI = "CHANNEL_URI "; + public static final String CHANNEL_URI = "CHANNEL_URI"; public static final String DEVICE_INFO = "DEVICE_INFO"; public static final String IMEI = "IMEI"; public static final String IMSI = "IMSI"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java new file mode 100644 index 0000000000..48de7d53d3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * / + */ + +package org.wso2.carbon.device.mgt.mobile.impl.windows.util; + +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService; + +/** + * Contains utility method used by Windows plugin. + */ +public class WindowsPluginUtils { + + public static License getDefaultLicense() { + License license = new License(); + license.setName(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS); + license.setLanguage("en_US"); + license.setVersion("1.0.0"); + license.setText("This End User License Agreement (“Agreement”) is a legal agreement between you (“You”) " + + "and WSO2, Inc., regarding the enrollment of Your personal mobile device (“Device”) in SoR’s " + + "mobile device management program, and the loading to and removal from Your Device and Your use " + + "of certain applications and any associated software and user documentation, whether provided in " + + "“online” or electronic format, used in connection with the operation of or provision of services " + + "to WSO2, Inc., BY SELECTING “I ACCEPT” DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + + "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + + "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + + "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + + "\n" + + "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + + "\n" + + "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + + "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + + "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + + "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + + "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + + "the cessation of Your relationship with SoR (including termination of Your employment if You are " + + "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + + "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + + "rights not expressly granted herein."); + return license; + } +}