Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a config to update console & myaccount callback url & access url #5304

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ 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 CONSOLE_ACCESS_URL_FROM_SERVER_CONFIGS = "Console.AccessURL";
public static final String MY_ACCOUNT_ACCESS_URL_FROM_SERVER_CONFIGS = "MyAccount.AccessURL";
public static final String TENANT_DOMAIN_PLACEHOLDER = "{TENANT_DOMAIN}";

/**
* Group the constants related to logs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.CONSOLE_ACCESS_URL_FROM_SERVER_CONFIGS;
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.ENABLE_V2_AUDIT_LOGS;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.MY_ACCOUNT_ACCESS_URL_FROM_SERVER_CONFIGS;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.TENANT_DOMAIN_PLACEHOLDER;
import static org.wso2.carbon.user.core.constants.UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS;
import static org.wso2.carbon.utils.CarbonUtils.isLegacyAuditLogsDisabled;

Expand Down Expand Up @@ -1081,8 +1084,71 @@ public static String resolveOriginUrlFromPlaceholders(String absoluteUrl) throws
*/
public static boolean isConsoleOrMyAccount(String name) {

return ApplicationConstants.CONSOLE_APPLICATION_NAME.equals(name) ||
ApplicationConstants.MY_ACCOUNT_APPLICATION_NAME.equals(name);
return isConsole(name) || isMyAccount(name);
}

/**
* Check whether the application is Console by app name.
*
* @param name Application name.
* @return True if the application is Console.
*/
public static boolean isConsole(String name) {

return ApplicationConstants.CONSOLE_APPLICATION_NAME.equals(name);
}

/**
* Check whether the application is My Account by app name.
*
* @param name Application name.
* @return True if the application is My Account.
*/
public static boolean isMyAccount(String name) {

return ApplicationConstants.MY_ACCOUNT_APPLICATION_NAME.equals(name);
}

/**
* Resolve Console application access url for a specific tenant based on the access url configured in toml.
*
* @param tenantDomain Tenant domain.
* @return Console access url.
*/
public static String getConsoleAccessUrlFromServerConfig(String tenantDomain) {

String accessUrl = IdentityUtil.getProperty(CONSOLE_ACCESS_URL_FROM_SERVER_CONFIGS);
if (StringUtils.isNotBlank(accessUrl)) {
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain) &&
!IdentityTenantUtil.isSuperTenantRequiredInUrl()) {
accessUrl = accessUrl.replace("/t/" + TENANT_DOMAIN_PLACEHOLDER, StringUtils.EMPTY);
} else {
accessUrl = accessUrl.replace(TENANT_DOMAIN_PLACEHOLDER, tenantDomain);
}
return accessUrl;
}
return null;
}

/**
* Resolve MyAccount application access url for a specific tenant based on the access url configured in toml.
*
* @param tenantDomain Tenant domain.
* @return MyAccount access url.
*/
public static String getMyAccountAccessUrlFromServerConfig(String tenantDomain) {

String accessUrl = IdentityUtil.getProperty(MY_ACCOUNT_ACCESS_URL_FROM_SERVER_CONFIGS);
if (StringUtils.isNotBlank(accessUrl)) {
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain) &&
!IdentityTenantUtil.isSuperTenantRequiredInUrl()) {
accessUrl = accessUrl.replace("/t/" + TENANT_DOMAIN_PLACEHOLDER, StringUtils.EMPTY);
} else {
accessUrl = accessUrl.replace(TENANT_DOMAIN_PLACEHOLDER, tenantDomain);
}
return accessUrl;
}
return null;
}

private static class InboundAuthRequestConfigSerializer extends StdSerializer<InboundAuthenticationRequestConfig> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.TEMPLATE_ID_SP_PROPERTY_DISPLAY_NAME;
import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.TEMPLATE_ID_SP_PROPERTY_NAME;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.LOCAL_SP;
import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getConsoleAccessUrlFromServerConfig;
import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getMyAccountAccessUrlFromServerConfig;
import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getUserTenantDomain;
import static org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationMgtDBQueries.ADD_APPLICATION_ASSOC_ROLES_TAIL;
import static org.wso2.carbon.identity.base.IdentityConstants.SKIP_CONSENT;
Expand Down Expand Up @@ -1940,6 +1942,19 @@ private ServiceProvider getBasicApplicationData(String applicationName, Connecti
serviceProvider.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders(
basicAppDataResultSet.getString(ApplicationTableColumns.ACCESS_URL)));
}
String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantID);
if (ApplicationMgtUtil.isConsole(serviceProvider.getApplicationName())) {
String consoleAccessUrl = getConsoleAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(consoleAccessUrl)) {
serviceProvider.setAccessUrl(consoleAccessUrl);
}
}
if (ApplicationMgtUtil.isMyAccount(serviceProvider.getApplicationName())) {
String myAccountAccessUrl = getMyAccountAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(myAccountAccessUrl)) {
serviceProvider.setAccessUrl(myAccountAccessUrl);
}
}

serviceProvider.setDiscoverable(getBooleanValue(basicAppDataResultSet.getString(ApplicationTableColumns
.IS_DISCOVERABLE)));
Expand Down Expand Up @@ -2476,6 +2491,19 @@ private ServiceProvider getBasicApplicationData(int appId, Connection connection
serviceProvider.setAccessUrl(ApplicationMgtUtil.resolveOriginUrlFromPlaceholders(
rs.getString(ApplicationTableColumns.ACCESS_URL)));
}
String tenantDomain = IdentityTenantUtil.getTenantDomain(rs.getInt(ApplicationTableColumns.TENANT_ID));
if (ApplicationMgtUtil.isConsole(serviceProvider.getApplicationName())) {
String consoleAccessUrl = getConsoleAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(consoleAccessUrl)) {
serviceProvider.setAccessUrl(consoleAccessUrl);
}
}
if (ApplicationMgtUtil.isMyAccount(serviceProvider.getApplicationName())) {
String myAccountAccessUrl = getMyAccountAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(myAccountAccessUrl)) {
serviceProvider.setAccessUrl(myAccountAccessUrl);
}
}

serviceProvider.setDiscoverable(getBooleanValue(rs.getString(ApplicationTableColumns.IS_DISCOVERABLE)));

Expand Down Expand Up @@ -5887,6 +5915,20 @@ private ApplicationBasicInfo buildApplicationBasicInfo(ResultSet appNameResultSe
throw new IdentityApplicationManagementException(
"Error occurred when resolving origin of the access URL with placeholders", e);
}
String tenantDomain =
IdentityTenantUtil.getTenantDomain(appNameResultSet.getInt(ApplicationTableColumns.TENANT_ID));
if (ApplicationMgtUtil.isConsole(basicInfo.getApplicationName())) {
String consoleAccessUrl = getConsoleAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(consoleAccessUrl)) {
basicInfo.setAccessUrl(consoleAccessUrl);
}
}
if (ApplicationMgtUtil.isMyAccount(basicInfo.getApplicationName())) {
String myAccountAccessUrl = getMyAccountAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(myAccountAccessUrl)) {
basicInfo.setAccessUrl(myAccountAccessUrl);
}
}

String username = appNameResultSet.getString(ApplicationTableColumns.USERNAME);
String userStoreDomain = appNameResultSet.getString(ApplicationTableColumns.USER_STORE);
Expand Down Expand Up @@ -5930,6 +5972,20 @@ private ApplicationBasicInfo buildApplicationBasicInfoWithInboundConfig(ResultSe
throw new IdentityApplicationManagementException(
"Error occurred when resolving origin of the access URL with placeholders", e);
}
String tenantDomain =
IdentityTenantUtil.getTenantDomain(appNameResultSet.getInt(ApplicationTableColumns.TENANT_ID));
if (ApplicationMgtUtil.isConsole(basicInfo.getApplicationName())) {
String consoleAccessUrl = getConsoleAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(consoleAccessUrl)) {
basicInfo.setAccessUrl(consoleAccessUrl);
}
}
if (ApplicationMgtUtil.isMyAccount(basicInfo.getApplicationName())) {
String myAccountAccessUrl = getMyAccountAccessUrlFromServerConfig(tenantDomain);
if (StringUtils.isNotBlank(myAccountAccessUrl)) {
basicInfo.setAccessUrl(myAccountAccessUrl);
}
}

String inboundAuthKey = appNameResultSet.getString(ApplicationInboundTableColumns.INBOUND_AUTH_KEY);
String inboundAuthType = appNameResultSet.getString(ApplicationInboundTableColumns.INBOUND_AUTH_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3931,4 +3931,16 @@
</InputValidation>
{% endif %}

<!-- Console Application configurations -->
<Console>
<CallbackURL>{{console.callback_url}}</CallbackURL>
<AccessURL>{{console.access_url}}</AccessURL>
</Console>

<!-- MyAccount Application configurations -->
<MyAccount>
<CallbackURL>{{myaccount.callback_url}}</CallbackURL>
<AccessURL>{{myaccount.access_url}}</AccessURL>
</MyAccount>

</Server>
Loading