diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java index 845d71ef0680..16bef328cffb 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationConstants.java @@ -102,8 +102,8 @@ private ApplicationConstants() { // Console and My Account application names. public static final String CONSOLE_APPLICATION_NAME = "Console"; public static final String MY_ACCOUNT_APPLICATION_NAME = "My Account"; - public static final String MY_ACCOUNT_APP_PATH = "/myaccount"; - public static final String CONSOLE_APP_PATH = "/console"; + public static final String MY_ACCOUNT_APP_NAME = "myaccount"; + public static final String CONSOLE_APP_NAME = "console"; /** * Group the constants related to logs. diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationMgtUtil.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationMgtUtil.java index a8fbcf5a722f..e6fe3eefcda9 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationMgtUtil.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationMgtUtil.java @@ -71,12 +71,12 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; -import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.CONSOLE_APP_PATH; +import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.CONSOLE_APP_NAME; import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.ENABLE_APPLICATION_ROLE_VALIDATION_PROPERTY; import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.LogConstants.APP_OWNER; import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.LogConstants.DISABLE_LEGACY_AUDIT_LOGS_IN_APP_MGT_CONFIG; import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.LogConstants.INBOUND_AUTHENTICATION_CONFIG; -import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.MY_ACCOUNT_APP_PATH; +import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.MY_ACCOUNT_APP_NAME; import static org.wso2.carbon.user.core.constants.UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS; import static org.wso2.carbon.utils.CarbonUtils.isLegacyAuditLogsDisabled; @@ -1039,14 +1039,13 @@ public static boolean isLegacyAuditLogsDisabledInAppMgt() { * @return The URL which origin replaced placeholders. * @throws URLBuilderException If any error occurs when building absolute public url without path. */ - public static String replaceUrlOriginWithPlaceholders(String absoluteUrl) throws URLBuilderException { + public static String replaceUrlOriginWithPlaceholders(String applicationName, String absoluteUrl) throws URLBuilderException { - if (StringUtils.contains(absoluteUrl, CONSOLE_APP_PATH) || - StringUtils.contains(absoluteUrl, MY_ACCOUNT_APP_PATH)) { + if (applicationName.equalsIgnoreCase(CONSOLE_APP_NAME) || + applicationName.equalsIgnoreCase(MY_ACCOUNT_APP_NAME)) { String origin = ServiceURLBuilder.create().build().getAbsolutePublicUrlWithoutPath(); absoluteUrl = StringUtils.replace(absoluteUrl, origin, BASE_URL_PLACEHOLDER); } - return absoluteUrl; } @@ -1057,14 +1056,13 @@ public static String replaceUrlOriginWithPlaceholders(String absoluteUrl) throws * @return The resolved URL from placeholders. * @throws URLBuilderException If any error occurs when building absolute public url without path. */ - public static String resolveOriginUrlFromPlaceholders(String absoluteUrl) throws URLBuilderException { + public static String resolveOriginUrlFromPlaceholders(String applicationName, String absoluteUrl) throws URLBuilderException { - if (StringUtils.contains(absoluteUrl, CONSOLE_APP_PATH) || - StringUtils.contains(absoluteUrl, MY_ACCOUNT_APP_PATH)) { + if (applicationName.equalsIgnoreCase(CONSOLE_APP_NAME) || + applicationName.equalsIgnoreCase(MY_ACCOUNT_APP_NAME)) { String origin = ServiceURLBuilder.create().build().getAbsolutePublicUrlWithoutPath(); absoluteUrl = StringUtils.replace(absoluteUrl, BASE_URL_PLACEHOLDER, origin); } - return absoluteUrl; } } diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java index 24cfc0a7d1a5..c24e56efece0 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java @@ -399,7 +399,7 @@ private ApplicationCreateResult persistBasicApplicationInformation(Connection co storeAppPrepStmt.setString(10, resourceId); storeAppPrepStmt.setString(11, application.getImageUrl()); storeAppPrepStmt.setString(12, - ApplicationMgtUtil.replaceUrlOriginWithPlaceholders(application.getAccessUrl())); + ApplicationMgtUtil.replaceUrlOriginWithPlaceholders(applicationName, application.getAccessUrl())); storeAppPrepStmt.execute(); results = storeAppPrepStmt.getGeneratedKeys(); @@ -958,7 +958,7 @@ private void updateBasicApplicationData(ServiceProvider serviceProvider, Connect statement.setString(ApplicationTableColumns.IS_DISCOVERABLE, isDiscoverable ? "1" : "0"); statement.setString(ApplicationTableColumns.IMAGE_URL, serviceProvider.getImageUrl()); statement.setString(ApplicationTableColumns.ACCESS_URL, - ApplicationMgtUtil.replaceUrlOriginWithPlaceholders(serviceProvider.getAccessUrl())); + ApplicationMgtUtil.replaceUrlOriginWithPlaceholders(serviceProvider.getApplicationName(), serviceProvider.getAccessUrl())); if (isValidUserForOwnerUpdate) { User owner = serviceProvider.getOwner(); statement.setString(ApplicationTableColumns.USERNAME, owner.getUserName()); @@ -1890,6 +1890,7 @@ private ServiceProvider getBasicApplicationData(String applicationName, Connecti serviceProvider.setDescription(basicAppDataResultSet.getString(6)); serviceProvider.setImageUrl(basicAppDataResultSet.getString(ApplicationTableColumns.IMAGE_URL)); serviceProvider.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders( + serviceProvider.getApplicationName(), basicAppDataResultSet.getString(ApplicationTableColumns.ACCESS_URL))); serviceProvider.setDiscoverable(getBooleanValue(basicAppDataResultSet.getString(ApplicationTableColumns .IS_DISCOVERABLE))); @@ -2350,6 +2351,7 @@ private ServiceProvider getBasicApplicationData(int appId, Connection connection serviceProvider.setDescription(rs.getString(ApplicationTableColumns.DESCRIPTION)); serviceProvider.setImageUrl(rs.getString(ApplicationTableColumns.IMAGE_URL)); serviceProvider.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders( + serviceProvider.getApplicationName(), rs.getString(ApplicationTableColumns.ACCESS_URL))); serviceProvider.setDiscoverable(getBooleanValue(rs.getString(ApplicationTableColumns.IS_DISCOVERABLE))); @@ -5637,7 +5639,7 @@ private ApplicationBasicInfo buildApplicationBasicInfo(ResultSet appNameResultSe basicInfo.setImageUrl(appNameResultSet.getString(ApplicationTableColumns.IMAGE_URL)); try { - basicInfo.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders( + basicInfo.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders(basicInfo.getApplicationName(), appNameResultSet.getString(ApplicationTableColumns.ACCESS_URL))); } catch (URLBuilderException e) { throw new IdentityApplicationManagementException( @@ -5677,7 +5679,7 @@ private ApplicationBasicInfo buildApplicationBasicInfoWithInboundConfig(ResultSe basicInfo.setImageUrl(appNameResultSet.getString(ApplicationTableColumns.IMAGE_URL)); try { - basicInfo.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders( + basicInfo.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders(basicInfo.getApplicationName(), appNameResultSet.getString(ApplicationTableColumns.ACCESS_URL))); } catch (URLBuilderException e) { throw new IdentityApplicationManagementException(