From 5d83c833212b68ed0537def331abb3edb5de79ea Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Thu, 5 Mar 2020 17:02:13 +0530 Subject: [PATCH 1/4] Create HTTP client based on hostname verification property --- .../request/interceptor/util/HandlerUtil.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java index a17e3dcb707..f35c0700eef 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java @@ -27,6 +27,7 @@ import org.apache.http.Consts; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; @@ -53,7 +54,7 @@ public class HandlerUtil { * @throws IOException IO exception returns if error occurs when executing the httpMethod */ public static ProxyResponse execute(HttpRequestBase httpRequest) throws IOException { - try (CloseableHttpClient client = HttpClients.createDefault()) { + try (CloseableHttpClient client = getHttpClient()) { HttpResponse response = client.execute(httpRequest); ProxyResponse proxyResponse = new ProxyResponse(); @@ -217,4 +218,18 @@ public class HandlerUtil { return gatewayPort; } + /** + * Retrieve Http client based on hostname verification. + * @return {@link CloseableHttpClient} http client + */ + public static CloseableHttpClient getHttpClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System. + getProperty("org.wso2.ignoreHostnameVerification")); + if (isIgnoreHostnameVerification) { + return HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); + } else { + return HttpClients.createDefault(); + } + } + } From 8a30914f90688bbda91cd178fd1e51ecd93fdd47 Mon Sep 17 00:00:00 2001 From: shamalka Date: Fri, 6 Mar 2020 13:12:20 +0530 Subject: [PATCH 2/4] Add scopes --- .../src/main/resources/conf/application-mgt.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index a8f23258219..e8375b32ad6 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -258,6 +258,8 @@ perm:geo-service:alerts-manage appm:read perm:devices:permanent-delete + perm:android:manage-configuration + perm:android:view-configuration app-mgt From d5911b900d4d50c3e79f3296cd20a382a6ffe03a Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Tue, 10 Mar 2020 12:22:38 +0530 Subject: [PATCH 3/4] Fix duplicate result issue by adding missing conditions --- .../device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 1 + .../device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java | 1 + .../device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java | 1 + .../device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java | 1 + 4 files changed, 4 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index e2a35770c2b..7d3c6afd903 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -899,6 +899,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { ") d1 " + "WHERE d1.DEVICE_ID = e.DEVICE_ID " + "AND d1.DEVICE_ID = ddi.DEVICE_ID " + + "AND d1.DEVICE_ID = ddd.DEVICE_ID " + "AND ddi.KEY_FIELD = ? "; if (dataSourceType.contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2)) { sql += "AND CAST( ddi.VALUE_FIELD AS BIGINT ) < ? "; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index 2ef6697453c..db30811c589 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -865,6 +865,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { ") d1 " + "WHERE d1.DEVICE_ID = e.DEVICE_ID " + "AND d1.DEVICE_ID = ddi.DEVICE_ID " + + "AND d1.DEVICE_ID = ddd.DEVICE_ID " + "AND ddi.KEY_FIELD = ? " + "AND CAST( ddi.VALUE_FIELD AS BIGINT ) < ? " + "ORDER BY ENROLMENT_ID " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index fc137897bbe..d4a6ba853ee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -851,6 +851,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { ") d1 " + "WHERE d1.DEVICE_ID = e.DEVICE_ID " + "AND d1.DEVICE_ID = ddi.DEVICE_ID " + + "AND d1.DEVICE_ID = ddd.DEVICE_ID " + "AND ddi.KEY_FIELD = ? " + "AND CAST( ddi.VALUE_FIELD AS BIGINT ) < ? " + "LIMIT ? OFFSET ?"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index ecda3ef66d7..64e8912db32 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -667,6 +667,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { ") d1 " + "WHERE d1.DEVICE_ID = e.DEVICE_ID " + "AND d1.DEVICE_ID = ddi.DEVICE_ID " + + "AND d1.DEVICE_ID = ddd.DEVICE_ID " + "AND ddi.KEY_FIELD = ? " + "AND CAST( ddi.VALUE_FIELD AS BIGINT ) < ? " + "LIMIT ? OFFSET ?"; From b352354020af763da40274e1ae141a01c88c2159 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 10 Mar 2020 23:02:06 +0530 Subject: [PATCH 4/4] Fix issue in initial location persistence from fresh device --- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 aad18333e4d..d5adc3538aa 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 @@ -3427,7 +3427,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv deviceLocation.setDistance(Double.parseDouble(distance)); deviceLocation.setSpeed(Float.parseFloat(speed)); deviceLocation.setBearing(Float.parseFloat(bearing)); - deviceInformationManager.addDeviceLocation(device, deviceLocation); + deviceInformationManager.addDeviceLocation(deviceLocation); } catch (Exception e) { //We are not failing the execution since this is not critical for the functionality. But logging as // a warning for reference.