From 0ac795903f03dfab35429dc24197e4fe383ada93 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Mon, 14 Oct 2024 11:24:02 +0530 Subject: [PATCH 1/6] Remove code quality check from PRs --- Jenkinsfile | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1ca3c229ba..11676b7a12 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,6 @@ pipeline { environment { def isPendingUpstreamDependenciesExists = false def triggeredViaPush = false - SCANNER_HOME = tool 'sonar-scanner' JAVA_HOME = '/usr/lib/jvm/java-11-openjdk' PATH = "${JAVA_HOME}/bin:${env.PATH}" } @@ -48,22 +47,6 @@ pipeline { } } } - - stage('Check SonarQube Installation') { - steps { - script { - echo "Initial JAVA_HOME: ${env.JAVA_HOME}" - echo "Initial PATH: ${env.PATH}" - - withEnv(["JAVA_HOME=${env.JAVA_HOME}", "PATH=${env.JAVA_HOME}/bin:${env.PATH}"]) { - sh """ - java -version - ${SCANNER_HOME}/bin/sonar-scanner --version - """ - } - } - } -} stage('Fetch Pending Upstream Dependencies') { steps { @@ -111,24 +94,6 @@ pipeline { } } } - - stage('Code Quality Check') { - steps { - script { - def projectName = "device-mgt-core-${env.CHANGE_ID}" - def projectKey = "device-mgt-core-${env.CHANGE_ID}" - - withSonarQubeEnv('sonar') { - sh """ - $SCANNER_HOME/bin/sonar-scanner \ - -Dsonar.projectName=${projectName} \ - -Dsonar.projectKey=${projectKey} \ - -Dsonar.java.binaries=target - """ - } - } - } -} stage('Report Job Status') { steps { From cba9f7ce080de366543b594be3b13206296db85a Mon Sep 17 00:00:00 2001 From: nipuni Date: Tue, 15 Oct 2024 19:04:43 +0530 Subject: [PATCH 2/6] Fix the validation issue when the APK file and screenshot names contain spaces --- .../application/mgt/core/util/APIUtil.java | 45 ++++++++++--------- .../application/mgt/core/util/Constants.java | 5 +++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java index 4a0687052a..2ac54352fe 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java @@ -48,6 +48,8 @@ import org.apache.commons.validator.routines.UrlValidator; import org.wso2.carbon.context.PrivilegedCarbonContext; import javax.ws.rs.core.Response; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -503,31 +505,29 @@ public class APIUtil { applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); applicationRelease.setRating(applicationReleaseDTO.getRating()); applicationRelease.setIconPath( - basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName()); - - if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())){ + basePath + Constants.ICON_ARTIFACT + Constants.FILE_NAME_PARAM + + URLEncoder.encode(applicationReleaseDTO.getIconName(), StandardCharsets.UTF_8)); + if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) { applicationRelease.setBannerPath( - basePath + Constants.BANNER_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO - .getBannerName()); + basePath + Constants.BANNER_ARTIFACT + Constants.FILE_NAME_PARAM + + URLEncoder.encode(applicationReleaseDTO.getBannerName(), StandardCharsets.UTF_8)); } - - applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(), - applicationReleaseDTO.getAppHashValue())); - + applicationRelease.setInstallerPath( + constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue())); if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) { - screenshotPaths - .add(basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FORWARD_SLASH + applicationReleaseDTO - .getScreenshotName1()); + screenshotPaths.add( + basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FILE_NAME_PARAM + + URLEncoder.encode(applicationReleaseDTO.getScreenshotName1(), StandardCharsets.UTF_8)); } if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) { - screenshotPaths - .add(basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FORWARD_SLASH + applicationReleaseDTO - .getScreenshotName2()); + screenshotPaths.add( + basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FILE_NAME_PARAM + + URLEncoder.encode(applicationReleaseDTO.getScreenshotName2(), StandardCharsets.UTF_8)); } if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) { - screenshotPaths - .add(basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FORWARD_SLASH + applicationReleaseDTO - .getScreenshotName3()); + screenshotPaths.add( + basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FILE_NAME_PARAM + + URLEncoder.encode(applicationReleaseDTO.getScreenshotName3(), StandardCharsets.UTF_8)); } applicationRelease.setScreenshots(screenshotPaths); return applicationRelease; @@ -543,9 +543,12 @@ public class APIUtil { public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); UrlValidator urlValidator = new UrlValidator(); - String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH; - return urlValidator.isValid(installerName) ? installerName - : basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName; + String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + + appHash + Constants.FORWARD_SLASH; + return urlValidator.isValid(installerName) + ? installerName + : basePath + Constants.APP_ARTIFACT + Constants.FILE_NAME_PARAM + + URLEncoder.encode(installerName, StandardCharsets.UTF_8); } public static String getArtifactDownloadBaseURL() throws ApplicationManagementException { diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java index 81e5bef788..57ed6b7189 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java @@ -140,6 +140,11 @@ public class Constants { public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; } + /** + * Query parameter for specifying the filename in the App artifact URL. + */ + public static final String FILE_NAME_PARAM = "?fileName="; + /** * Directory name of the icon artifact that are saved in the file system. */ From b7e0580112f6e138054a706a6f918b367c3695e6 Mon Sep 17 00:00:00 2001 From: nipuni Date: Mon, 21 Oct 2024 13:48:27 +0530 Subject: [PATCH 3/6] Fix missing commit by moving transaction commit after metadata update. --- .../core/metadata/mgt/DeviceStatusManagementServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java index 351ba5a63f..c04e5deae8 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java @@ -151,9 +151,9 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) { // Add default device status check metadata entries metadataDAO.updateMetadata(tenantId, constructDeviceStatusCheckMetadata(isChecked)); + MetadataManagementDAOFactory.commitTransaction(); return true; } - MetadataManagementDAOFactory.commitTransaction(); } catch (MetadataManagementDAOException e) { MetadataManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while updating device status check metadata entry."; From 8f47c448bdf0d5e140ed0e0f3269cbed89f7c186 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Thu, 17 Oct 2024 23:58:56 +0530 Subject: [PATCH 4/6] Fix login issues in sub tenants --- .../ui/request/interceptor/LoginHandler.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/LoginHandler.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/LoginHandler.java index 6a97630e99..e699bc7675 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/LoginHandler.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/LoginHandler.java @@ -37,6 +37,8 @@ import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.NameValuePair; import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; import org.apache.hc.core5.http.message.BasicNameValuePair; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; @@ -44,6 +46,10 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Base64; @@ -61,6 +67,8 @@ public class LoginHandler extends HttpServlet { private static String uiConfigUrl; private static String iotCoreUrl; private static String kmManagerUrl; + private static String adminUsername; + private static String adminPassword; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { @@ -87,14 +95,14 @@ public class LoginHandler extends HttpServlet { LoginCache loginCache = HandlerUtil.getLoginCache(httpSession); OAuthAppCacheKey oAuthAppCacheKey = new OAuthAppCacheKey(applicationName, username); OAuthApp oAuthApp = loginCache.getOAuthAppCache(oAuthAppCacheKey); - if (oAuthApp == null) { + initializeAdminCredentials(); ArrayList supportedGrantTypes = new ArrayList<>(); supportedGrantTypes.add(HandlerConstants.PASSWORD_GRANT_TYPE); supportedGrantTypes.add(HandlerConstants.REFRESH_TOKEN_GRANT_TYPE); ClassicHttpRequest apiRegEndpoint = ClassicRequestBuilder.post(gatewayUrl + HandlerConstants.APP_REG_ENDPOINT) .setEntity(HandlerUtil.constructAppRegPayload(tags, applicationName, - username, password, null, supportedGrantTypes)) + adminUsername, adminPassword, null, supportedGrantTypes)) .setHeader(org.apache.hc.core5.http.HttpHeaders.CONTENT_TYPE, org.apache.hc.core5.http.ContentType.APPLICATION_JSON.toString()) .setHeader(org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC + Base64.getEncoder().encodeToString((username + HandlerConstants.COLON + password).getBytes())) @@ -143,6 +151,10 @@ public class LoginHandler extends HttpServlet { log.error("Error occurred while sending the response into the socket. ", e); } catch (JsonSyntaxException e) { log.error("Error occurred while parsing the response. ", e); + } catch (ParserConfigurationException e) { + log.error("Error while creating the document builder. "); + } catch (SAXException e) { + log.error("Error while parsing xml file. ", e); } catch (LoginException e) { log.error("Error occurred while getting token data. ", e); } @@ -251,4 +263,21 @@ public class LoginHandler extends HttpServlet { .build(); return HandlerUtil.execute(tokenEndpoint); } + + /** + * Initialize the admin credential variables + * + * @throws ParserConfigurationException - Throws when error occur during initializing the document builder + * @throws IOException - Throws when error occur during document parsing + * @throws SAXException - Throws when error occur during document parsing + */ + private void initializeAdminCredentials() throws ParserConfigurationException, IOException, SAXException { + File userMgtConf = new File("repository/conf/user-mgt.xml"); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(userMgtConf); + + adminUsername = doc.getElementsByTagName("UserName").item(0).getTextContent(); + adminPassword = doc.getElementsByTagName("Password").item(0).getTextContent(); + } } From 20df0c879f88a0bc8afffcfd1ac1cef33b3b3988 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 23 Oct 2024 09:13:59 +0530 Subject: [PATCH 5/6] Improved SQL query with DESC sorting --- .../mgt/core/dao/impl/GenericCertificateDAOImpl.java | 2 +- .../certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java | 2 +- .../mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java | 2 +- .../mgt/core/dao/impl/SQLServerCertificateDAOImpl.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java index 92891754ed..26217b4667 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java @@ -139,7 +139,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { isCertificateUsernameProvided = true; } - query += "ORDER BY ID LIMIT ?,?"; + query += "ORDER BY ID DESC LIMIT ?,?"; try (PreparedStatement stmt = conn.prepareStatement(query)) { int paramIdx = 1; diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java index 9fd87d6ed0..716d5df388 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java @@ -78,7 +78,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { isCertificateUsernameProvided = true; } - query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + query += "ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement stmt = conn.prepareStatement(query)) { int paramIdx = 1; diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java index ef06ec0000..2d1cc90851 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java @@ -78,7 +78,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { isCertificateUsernameProvided = true; } - query += "ORDER BY ID LIMIT ? OFFSET ?"; + query += "ORDER BY ID DESC LIMIT ? OFFSET ?"; try (PreparedStatement stmt = conn.prepareStatement(query)) { int paramIdx = 1; diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java index 22874dd7b7..a9f37a6143 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java @@ -78,7 +78,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { isCertificateUsernameProvided = true; } - query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + query += "ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement stmt = conn.prepareStatement(query)) { int paramIdx = 1; From 0e82c9c304117468a97fce39bd9fd98bccc7cebd Mon Sep 17 00:00:00 2001 From: Subodhinie Date: Wed, 23 Oct 2024 16:57:32 +0530 Subject: [PATCH 6/6] Remove unused windows os updates scopes --- .../src/main/resources/conf/mdm-ui-config.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index 45c3ebe581..31350a1f6f 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -392,7 +392,6 @@ win:ops:os-updates-info win:microsoft-store:search win:updates:read - win:update:modify admin:tenant:view dm:admin:devices:usage:view and:ops:clear-app