Java Code Examples for org.wso2.carbon.identity.core.util.IdentityTenantUtil#isTenantQualifiedUrlsEnabled()

The following examples show how to use org.wso2.carbon.identity.core.util.IdentityTenantUtil#isTenantQualifiedUrlsEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationFacade.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private String buildUrl(String defaultContext, Supplier<String> getValueFromFileBasedConfig) {

        if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
            try {
                return ServiceURLBuilder.create().addPath(defaultContext).build().getAbsolutePublicURL();
            } catch (URLBuilderException e) {
                throw new IdentityRuntimeException(
                        "Error while building tenant qualified url for context: " + defaultContext, e);
            }
        } else {
            String urlFromFileBasedConfig = getValueFromFileBasedConfig.get();
            if (StringUtils.isNotBlank(urlFromFileBasedConfig)) {
                // If the file based URL is set, then we have to return the file based URL.
                return urlFromFileBasedConfig;
            } else {
                return defaultContext;
            }
        }
    }
 
Example 2
Source File: LoginContextManagementUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private static String getTenantDomain(HttpServletRequest request) {

        String tenantDomain;
        if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
            if (log.isDebugEnabled()) {
                log.debug("Tenant Qualified URL mode enabled. Retrieving tenantDomain from thread local context.");
            }
            tenantDomain = IdentityTenantUtil.getTenantDomainFromContext();
        } else {
            tenantDomain = request.getParameter("tenantDomain");
        }

        if (log.isDebugEnabled()) {
            log.debug("Service Provider tenant domain: " + tenantDomain);
        }
        return tenantDomain;
    }
 
Example 3
Source File: DefaultServiceURLBuilder.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private String getResolvedUrlPath(String tenantDomain) {

        String resolvedUrlContext = buildUrlPath(urlPaths);
        StringBuilder resolvedUrlStringBuilder = new StringBuilder();

        if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
            if (isNotSuperTenant(tenantDomain)) {
                resolvedUrlStringBuilder.append("/t/").append(tenantDomain);
            }
        }

        if (StringUtils.isNotBlank(resolvedUrlContext)) {
            if (resolvedUrlContext.trim().charAt(0) != '/') {
                resolvedUrlStringBuilder.append("/").append(resolvedUrlContext.trim());
            } else {
                resolvedUrlStringBuilder.append(resolvedUrlContext.trim());
            }
        }

        return resolvedUrlStringBuilder.toString();
    }
 
Example 4
Source File: IdentityProviderManager.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the public service url given the default context and the url picked from the configuration based on
 * the 'tenant_context.enable_tenant_qualified_urls' mode set in deployment.toml.
 *
 * @param defaultUrlContext default url context path
 * @param urlFromConfig     url picked from the file configuration
 * @return absolute public url of the service if 'enable_tenant_qualified_urls' is 'true', else returns the url
 * from the file config
 * @throws IdentityProviderManagementServerException when fail to build the absolute public url
 */
private String resolveAbsoluteURL(String defaultUrlContext, String urlFromConfig) throws IdentityProviderManagementServerException {

    if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled() && StringUtils.isNotBlank(urlFromConfig)) {
        if (log.isDebugEnabled()) {
            log.debug("Resolved URL:" + urlFromConfig + " from file configuration for default url context: " +
                    defaultUrlContext);
        }
        return urlFromConfig;
    }

    try {
        return ServiceURLBuilder.create().addPath(defaultUrlContext).build().getAbsolutePublicURL();
    } catch (URLBuilderException e) {
        throw IdentityProviderManagementException.error(IdentityProviderManagementServerException.class,
                "Error while building URL: " + defaultUrlContext, e);
    }
}
 
Example 5
Source File: ContextLoader.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the API context on whether the tenant qualified url is enabled or not. In tenant qualified mode the
 * ServiceURLBuilder appends the tenant domain to the URI as a path param automatically. But
 * in non tenant qualified mode we need to append the tenant domain to the path manually.
 *
 * @param endpoint Relative endpoint path.
 * @return Context of the API.
 */
private static String getContext(String endpoint) {

    String context;
    if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
        context = SERVER_API_PATH_COMPONENT + endpoint;
    } else {
        context = String.format(TENANT_CONTEXT_PATH_COMPONENT, getTenantDomainFromContext()) +
                SERVER_API_PATH_COMPONENT + endpoint;
    }
    return context;
}
 
Example 6
Source File: DefaultRequestCoordinator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String getTenantDomainFromContext() {

        // We use the tenant domain set in context only in tenant qualified URL mode.
        if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
            return IdentityTenantUtil.getTenantDomainFromContext();
        }

        return null;
    }
 
Example 7
Source File: IdentityManagementEndpointUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get base path URL for API clients.
 *
 * @param tenantDomain          Tenant Domain.
 * @param context               URL context.
 * @param isEndpointTenantAware Whether the endpoint is tenant aware.
 * @return Base path.
 * @throws ApiException ApiException.
 */
public static String getBasePath(String tenantDomain, String context, boolean isEndpointTenantAware)
        throws ApiException {

    String basePath;
    String serverUrl = IdentityManagementServiceUtil.getInstance().getContextURLFromFile();
    try {
        if (StringUtils.isBlank(serverUrl)) {
            if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
                basePath = ServiceURLBuilder.create().addPath(context).build().getAbsoluteInternalURL();
            } else {
                serverUrl = ServiceURLBuilder.create().build().getAbsoluteInternalURL();
                if (StringUtils.isNotBlank(tenantDomain) && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME
                        .equalsIgnoreCase(tenantDomain) && isEndpointTenantAware) {
                    basePath = serverUrl + "/t/" + tenantDomain + context;
                } else {
                    basePath = serverUrl + context;
                }
            }
        } else {
            basePath = serverUrl + context;
        }
    } catch (URLBuilderException e) {
        throw new ApiException("Error while building url for context: " + context);
    }
    return basePath;
}
 
Example 8
Source File: IdentityProviderManager.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String addTenantPathParamInLegacyMode(String resolvedUrl, String tenantDomain) {

        try {
            if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled() && StringUtils.isNotBlank(tenantDomain) &&
                    !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                resolvedUrl = getTenantUrl(resolvedUrl, tenantDomain);
            }
        } catch (URISyntaxException e) {
            log.error(String.format("%s endpoint is malformed.", resolvedUrl), e);
        }
        return resolvedUrl;
    }