diff --git a/integration/adapter-core/src/main/java/org/keycloak/adapters/OAuthRequestAuthenticator.java b/integration/adapter-core/src/main/java/org/keycloak/adapters/OAuthRequestAuthenticator.java index e39602e01e..a948b03a7c 100755 --- a/integration/adapter-core/src/main/java/org/keycloak/adapters/OAuthRequestAuthenticator.java +++ b/integration/adapter-core/src/main/java/org/keycloak/adapters/OAuthRequestAuthenticator.java @@ -108,7 +108,7 @@ public abstract class OAuthRequestAuthenticator { protected String getRedirectUri(String state) { String url = getRequestUrl(); - log.infof("sending redirect uri: %s", url); + log.infof("callback uri: %s", url); if (!isRequestSecure() && deployment.isSslRequired()) { int port = sslRedirectPort(); if (port < 0) { @@ -147,6 +147,7 @@ public abstract class OAuthRequestAuthenticator { exchange.getResponse().setStatus(403); return true; } + log.info("Sending redirect to login page: " + redirect); exchange.getResponse().setStatus(302); exchange.getResponse().setCookie(deployment.getStateCookieName(), state, /* need to set path? */ null, null, -1, deployment.isSslRequired(), false); exchange.getResponse().setHeader("Location", redirect); diff --git a/integration/undertow/src/main/java/org/keycloak/adapters/undertow/KeycloakServletExtension.java b/integration/undertow/src/main/java/org/keycloak/adapters/undertow/KeycloakServletExtension.java index 4c074807d8..68f53bac08 100755 --- a/integration/undertow/src/main/java/org/keycloak/adapters/undertow/KeycloakServletExtension.java +++ b/integration/undertow/src/main/java/org/keycloak/adapters/undertow/KeycloakServletExtension.java @@ -19,6 +19,8 @@ import org.keycloak.adapters.KeycloakDeployment; import org.keycloak.adapters.KeycloakDeploymentBuilder; import javax.servlet.ServletContext; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; @@ -43,7 +45,7 @@ public class KeycloakServletExtension implements ServletExtension { return false; } - private InputStream getJSONFromServletContext(ServletContext servletContext) { + private static InputStream getJSONFromServletContext(ServletContext servletContext) { String json = servletContext.getInitParameter(AdapterConstants.AUTH_DATA_PARAM_NAME); if (json == null) { return null; @@ -51,6 +53,25 @@ public class KeycloakServletExtension implements ServletExtension { return new ByteArrayInputStream(json.getBytes()); } + private static InputStream getConfigInputStream(ServletContext context) { + InputStream is = getJSONFromServletContext(context); + if (is == null) { + String path = context.getInitParameter("keycloak.config.file"); + if (path == null) { + log.info("**** using /WEB-INF/keycloak.json"); + is = context.getResourceAsStream("/WEB-INF/keycloak.json"); + } else { + try { + is = new FileInputStream(path); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + } + return is; + } + + @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { if (!isAuthenticationMechanismPresent(deploymentInfo, "KEYCLOAK")) { @@ -58,10 +79,7 @@ public class KeycloakServletExtension implements ServletExtension { return; } log.info("KeycloakServletException initialization"); - InputStream is = getJSONFromServletContext(servletContext); - if (is == null) { - is = servletContext.getResourceAsStream("/WEB-INF/keycloak.json"); - } + InputStream is = getConfigInputStream(servletContext); if (is == null) throw new RuntimeException("Unable to find realm config in /WEB-INF/keycloak.json or in keycloak subsystem."); KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(is); UndertowUserSessionManagement userSessionManagement = new UndertowUserSessionManagement(deployment); diff --git a/integration/undertow/src/main/java/org/keycloak/adapters/undertow/ServletKeycloakAuthMech.java b/integration/undertow/src/main/java/org/keycloak/adapters/undertow/ServletKeycloakAuthMech.java index 42b9237170..d72033f752 100755 --- a/integration/undertow/src/main/java/org/keycloak/adapters/undertow/ServletKeycloakAuthMech.java +++ b/integration/undertow/src/main/java/org/keycloak/adapters/undertow/ServletKeycloakAuthMech.java @@ -46,8 +46,10 @@ public class ServletKeycloakAuthMech implements AuthenticationMechanism { } protected ServletRequestAuthenticator createRequestAuthenticator(HttpServerExchange exchange, SecurityContext securityContext, UndertowHttpFacade facade) { + int confidentialPort = 8443; + if (portManager != null) confidentialPort = portManager.getConfidentialPort(exchange); return new ServletRequestAuthenticator(facade, deployment, - portManager.getConfidentialPort(exchange), securityContext, exchange, userSessionManagement); + confidentialPort, securityContext, exchange, userSessionManagement); } @Override diff --git a/testsuite/integration/pom.xml b/testsuite/integration/pom.xml index 7b80860392..ea61388294 100755 --- a/testsuite/integration/pom.xml +++ b/testsuite/integration/pom.xml @@ -66,6 +66,17 @@ keycloak-js-adapter ${project.version} + + org.keycloak + keycloak-undertow-adapter + ${project.version} + + + org.apache.httpcomponents + httpclient + 4.2.1 + +