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 { 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. */ 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; 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."; 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(); + } } 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