read auth rest url from xml file and tenant resolve it
package org.wso2.carbon.identity.application.authentication.endpoint.util.filter;
import com.google.gson.Gson;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.authentication.endpoint.util.AuthContextAPIClient;
import org.wso2.carbon.identity.application.authentication.endpoint.util.Constants;
import org.wso2.carbon.identity.application.authentication.endpoint.util.client.exception.AuthenticationEndpointException;
import org.wso2.carbon.identity.application.authentication.endpoint.util.client.model.AuthenticationRequestWrapper;
import org.wso2.carbon.identity.core.ServiceURLBuilder;
import org.wso2.carbon.identity.core.URLBuilderException;
+import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import java.io.IOException;
import java.util.Map;
@@ -124,10 +127,12 @@ public class AuthParameterFilter implements Filter {
private String buildAPIPath(String key, String value) throws AuthenticationEndpointException {
try {
- String authAPIURL = ServiceURLBuilder.create().addPath(DATA_API_PATH).build().getAbsoluteInternalURL();
- if (authAPIURL == null) {
- context.getInitParameter(Constants.AUTHENTICATION_REST_ENDPOINT_URL);
+ String authAPIURL = context.getInitParameter(Constants.AUTHENTICATION_REST_ENDPOINT_URL);
+ if (StringUtils.isBlank(authAPIURL)) {
+ authAPIURL = ServiceURLBuilder.create().addPath(DATA_API_PATH).build().getAbsoluteInternalURL();
+ } else {
+ authAPIURL = resolveTenantDomain(authAPIURL);
}
if (!authAPIURL.endsWith("/")) {
@@ -154,6 +159,29 @@ public class AuthParameterFilter implements Filter {
}
}
+ /**
+ * Resolve "${tenantDomain}" in the authentication REST endpoint URL.
+ *
+ * @param authAPIURL authentication REST endpoint URL
+ * @return Tenant resolved authentication REST endpoint URL
+ */
+ private String resolveTenantDomain(String authAPIURL) {
+
+ // Resolve tenant domain for the authentication API URl
+ if (authAPIURL.contains("${tenantDomain}")) {
+ String tenantDomain = IdentityTenantUtil.getTenantDomainFromContext();
+ if (StringUtils.isBlank(tenantDomain)) {
+ tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ }
+ if (tenantDomain.equals("carbon.super")) {
+ authAPIURL = authAPIURL.replace("t/${tenant}/", "");
+ } else {
+ authAPIURL = authAPIURL.replace("${tenant}", tenantDomain);
+ }
+ }
+ return authAPIURL;
+ }
+
@Override
public void destroy() {
}
