From a5a9d02deec97dfd69d04c3b5c747fd3215a1323 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 14 Jul 2015 19:39:03 +0530 Subject: [PATCH 1/4] Implemented getDeviceByStatus function --- .../device/mgt/common/EnrolmentInfo.java | 2 +- .../carbon/device/mgt/core/dao/DeviceDAO.java | 2 ++ .../mgt/core/dao/impl/DeviceDAOImpl.java | 28 +++++++++++++++ .../DeviceManagementProviderService.java | 9 +++++ .../DeviceManagementProviderServiceImpl.java | 36 +++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index 82e3fb57d4..b3a594a95c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.common; public class EnrolmentInfo { public enum Status { - CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED + CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED } public enum OwnerShip { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index ad87c15096..75cddd8141 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -60,5 +60,7 @@ public interface DeviceDAO { EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException; + + List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 55d19152ff..06a17f0685 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -442,4 +442,32 @@ public class DeviceDAOImpl implements DeviceDAO { return enrolmentInfo; } + public List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + List devices = new ArrayList(); + try { + conn = this.getConnection(); + stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_TYPE_ID, " + + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + + "AND STATUS = ?) e, DM_DEVICE d WHERE DEVICE_ID = e.DEVICE_ID AND d.TENANT_ID = ?"); + stmt.setInt(1, tenantId); + stmt.setString(2, status.toString()); + stmt.setInt(3, tenantId); + ResultSet rs = stmt.executeQuery(); + + while (rs.next()) { + Device device = this.loadDevice(rs); + devices.add(device); + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + + "'" + status + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return devices; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 9c72e0323c..345838a1e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -79,4 +79,13 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM List getDevicesByName(String deviceName) throws DeviceManagementException; void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; + + /** + * This method is used to retrieve list of devices based on the device status + * + * @param status Device status + * @return List of devices + * @throws DeviceManagementException + */ + List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 9aa80d7e25..6e9ccdd050 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -699,4 +699,40 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } + public List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException { + List devices = new ArrayList(); + List allDevices; + try { + DeviceManagementDAOFactory.getConnection(); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + allDevices = deviceDAO.getDevicesByStatus(status, tenantId); + + } catch (DeviceManagementDAOException e) { + String errorMsg = "Error occurred while fetching the list of devices that matches to status: '" + + status + "'"; + log.error(errorMsg, e); + throw new DeviceManagementException(errorMsg, e); + } finally { + + try { + DeviceManagementDAOFactory.closeConnection(); + } catch (DeviceManagementDAOException e) { + log.warn("Error occurred while closing the connection", e); + } + } + + for (Device device : allDevices) { + Device dmsDevice = + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( + new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } + devices.add(device); + } + return devices; + } + } From a82351f53fdb5c5ea5bf181865fd409a37a94a44 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 14 Jul 2015 20:31:37 +0530 Subject: [PATCH 2/4] Refactered getDevicesByType query --- .../wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 06a17f0685..fdb18454f7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -448,11 +448,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = new ArrayList(); try { conn = this.getConnection(); - stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_TYPE_ID, " + + stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + - "AND STATUS = ?) e, DM_DEVICE d WHERE DEVICE_ID = e.DEVICE_ID AND d.TENANT_ID = ?"); + "AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " + + "AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"); stmt.setInt(1, tenantId); stmt.setString(2, status.toString()); stmt.setInt(3, tenantId); From 5a4231485569683e6fb4d6b8b1198b3b32467745 Mon Sep 17 00:00:00 2001 From: milanperera Date: Thu, 16 Jul 2015 19:58:13 +0530 Subject: [PATCH 3/4] Added dynamic-client-authentication-feature --- carbon-devicemgt.ids | 197 ++++++++++++++++++ .../pom.xml | 154 ++++++++++++++ .../src/main/resources/p2.inf | 2 + features/oauth-extensions/pom.xml | 42 ++++ pom.xml | 1 + 5 files changed, 396 insertions(+) create mode 100644 carbon-devicemgt.ids create mode 100644 features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml create mode 100644 features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf create mode 100644 features/oauth-extensions/pom.xml diff --git a/carbon-devicemgt.ids b/carbon-devicemgt.ids new file mode 100644 index 0000000000..d0219166cf --- /dev/null +++ b/carbon-devicemgt.ids @@ -0,0 +1,197 @@ + + + + + " + + + + + + + + +
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + +
+ + + + + + + +
+ + + + + + + +
+
+
\ No newline at end of file diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml new file mode 100644 index 0000000000..a20ebb17c6 --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml @@ -0,0 +1,154 @@ + + + + + + + + org.wso2.carbon.devicemgt + oauth-extentions-feature + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.oauth.extensions.server.feature + pom + 0.9.2-SNAPSHOT + WSO2 Carbon - Oauth Extensions Server Feature + http://wso2.org + This feature contains oauth functionality + + + + + + + + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + copy + package + + copy + + + + + org.wso2.mdm + dynamic-client-manager + ${project.version} + war + true + ${basedir}/src/main/resources/ + dynamic-client-manager.war + + + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.oauth.extensions.server + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + + + + + + + + + + + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + + + + + + + + + + + diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..3143c5e9df --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf @@ -0,0 +1,2 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.oauth.extensions.server_${feature.version}/dynamic-client-manager.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-manager.war,overwrite:true);\ \ No newline at end of file diff --git a/features/oauth-extensions/pom.xml b/features/oauth-extensions/pom.xml new file mode 100644 index 0000000000..87ed9a7ef0 --- /dev/null +++ b/features/oauth-extensions/pom.xml @@ -0,0 +1,42 @@ + + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 0.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt + oauth-extentions-feature + 0.9.2-SNAPSHOT + pom + WSO2 Carbon - Policy Management Feature + http://wso2.org + + + org.wso2.carbon.oauth.extensions.server.feature + + + diff --git a/pom.xml b/pom.xml index f31068a457..ffd4eda2eb 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ features/device-mgt features/policy-mgt features/webapp-authenticator-framework + features/oauth-extensions From f20037432075d5dfca0893b9bd48cec9c46655a1 Mon Sep 17 00:00:00 2001 From: milanperera Date: Thu, 16 Jul 2015 20:05:09 +0530 Subject: [PATCH 4/4] removing ids --- carbon-devicemgt.ids | 197 ------------------------------------------- 1 file changed, 197 deletions(-) delete mode 100644 carbon-devicemgt.ids diff --git a/carbon-devicemgt.ids b/carbon-devicemgt.ids deleted file mode 100644 index d0219166cf..0000000000 --- a/carbon-devicemgt.ids +++ /dev/null @@ -1,197 +0,0 @@ - - - - - " - - - - - - - - -
- - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - -
- - - - - - - -
- - - - - - - -
-
-
\ No newline at end of file