Java Code Examples for org.keycloak.common.util.KeycloakUriBuilder#port()
The following examples show how to use
org.keycloak.common.util.KeycloakUriBuilder#port() .
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: AdapterDeploymentContext.java From keycloak with Apache License 2.0 | 6 votes |
protected KeycloakUriBuilder getBaseBuilder(HttpFacade facade, String base) { KeycloakUriBuilder builder = KeycloakUriBuilder.fromUri(base); URI request = URI.create(facade.getRequest().getURI()); String scheme = request.getScheme(); if (deployment.getSslRequired().isRequired(facade.getRequest().getRemoteAddr())) { scheme = "https"; if (!request.getScheme().equals(scheme) && request.getPort() != -1) { log.error("request scheme: " + request.getScheme() + " ssl required"); throw new RuntimeException("Can't resolve relative url from adapter config."); } } builder.scheme(scheme); builder.host(request.getHost()); if (request.getPort() != -1) { builder.port(request.getPort()); } return builder; }
Example 2
Source File: OAuthRequestAuthenticator.java From keycloak with Apache License 2.0 | 4 votes |
protected String getRedirectUri(String state) { String url = getRequestUrl(); log.debugf("callback uri: %s", url); if (!facade.getRequest().isSecure() && deployment.getSslRequired().isRequired(facade.getRequest().getRemoteAddr())) { int port = sslRedirectPort(); if (port < 0) { // disabled? return null; } KeycloakUriBuilder secureUrl = KeycloakUriBuilder.fromUri(url).scheme("https").port(-1); if (port != 443) secureUrl.port(port); url = secureUrl.build().toString(); } String loginHint = getQueryParamValue("login_hint"); url = UriUtils.stripQueryParam(url,"login_hint"); String idpHint = getQueryParamValue(AdapterConstants.KC_IDP_HINT); url = UriUtils.stripQueryParam(url, AdapterConstants.KC_IDP_HINT); String scope = getQueryParamValue(OAuth2Constants.SCOPE); url = UriUtils.stripQueryParam(url, OAuth2Constants.SCOPE); String prompt = getQueryParamValue(OAuth2Constants.PROMPT); url = UriUtils.stripQueryParam(url, OAuth2Constants.PROMPT); String maxAge = getQueryParamValue(OAuth2Constants.MAX_AGE); url = UriUtils.stripQueryParam(url, OAuth2Constants.MAX_AGE); String uiLocales = getQueryParamValue(OAuth2Constants.UI_LOCALES_PARAM); url = UriUtils.stripQueryParam(url, OAuth2Constants.UI_LOCALES_PARAM); KeycloakUriBuilder redirectUriBuilder = deployment.getAuthUrl().clone() .queryParam(OAuth2Constants.RESPONSE_TYPE, OAuth2Constants.CODE) .queryParam(OAuth2Constants.CLIENT_ID, deployment.getResourceName()) .queryParam(OAuth2Constants.REDIRECT_URI, rewrittenRedirectUri(url)) .queryParam(OAuth2Constants.STATE, state) .queryParam("login", "true"); if(loginHint != null && loginHint.length() > 0){ redirectUriBuilder.queryParam("login_hint",loginHint); } if (idpHint != null && idpHint.length() > 0) { redirectUriBuilder.queryParam(AdapterConstants.KC_IDP_HINT,idpHint); } if (prompt != null && prompt.length() > 0) { redirectUriBuilder.queryParam(OAuth2Constants.PROMPT, prompt); } if (maxAge != null && maxAge.length() > 0) { redirectUriBuilder.queryParam(OAuth2Constants.MAX_AGE, maxAge); } if (uiLocales != null && uiLocales.length() > 0) { redirectUriBuilder.queryParam(OAuth2Constants.UI_LOCALES_PARAM, uiLocales); } scope = TokenUtil.attachOIDCScope(scope); redirectUriBuilder.queryParam(OAuth2Constants.SCOPE, scope); return redirectUriBuilder.build().toString(); }