Skip to content

Commit

Permalink
Add methods to get absolute urls of the portals
Browse files Browse the repository at this point in the history
  • Loading branch information
madurangasiriwardena committed Oct 25, 2023
1 parent 1a46f70 commit a8d41c3
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
Expand Down Expand Up @@ -193,6 +195,12 @@ public String getAuthenticationEndpointURL() {
FileBasedConfigurationBuilder.getInstance()::getAuthenticationEndpointURL);
}

public String getAuthenticationEndpointAbsoluteURL() {

return buildAbsoluteUrl(AUTHENTICATION_ENDPOINT,
FileBasedConfigurationBuilder.getInstance()::getAuthenticationEndpointURL);
}

public String getAuthenticationEndpointRetryURL() {

return buildUrl(AUTHENTICATION_ENDPOINT_RETRY,
Expand All @@ -211,6 +219,11 @@ public String getAuthenticationEndpointWaitURL() {
FileBasedConfigurationBuilder.getInstance()::getAuthenticationEndpointWaitURL);
}

public String getAccountRecoveryEndpointAbsolutePath() {

return buildAbsoluteUrl(ACCOUNT_RECOVERY_ENDPOINT_PATH, this::readAccountRecoveryEndpointPath);
}

public String getAccountRecoveryEndpointPath() {

return buildUrl(ACCOUNT_RECOVERY_ENDPOINT_PATH, this::readAccountRecoveryEndpointPath);
Expand Down Expand Up @@ -327,4 +340,25 @@ private String buildUrl(String defaultContext, Supplier<String> getValueFromFile
}
}
}

private String buildAbsoluteUrl(String defaultContext, Supplier<String> getValueFromFileBasedConfig) {

String urlFromFileBasedConfig = getValueFromFileBasedConfig.get();
String path = defaultContext;
if (StringUtils.isNotBlank(urlFromFileBasedConfig)) {
// If the file based URL is set, then we have to use the file based URL.
if (urlFromFileBasedConfig.startsWith("http://") || urlFromFileBasedConfig.startsWith("https://")) {
// If the full URL is configured, we can use it as it is.
return urlFromFileBasedConfig;
} else {
path = urlFromFileBasedConfig;
}
}
try {
return ServiceURLBuilder.create().addPath(path).build().getAbsolutePublicURL();
} catch (URLBuilderException e) {
throw new IdentityRuntimeException(
"Error while building tenant qualified url for context: " + defaultContext, e);
}
}
}

0 comments on commit a8d41c3

Please sign in to comment.