From 9416ee7224cfcdd5e205ceb7125d47b0f4e6b138 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Thu, 9 Feb 2017 21:27:28 -0200 Subject: [PATCH] [RHSSO-767] - Wrong implementation of Request.getRelativePath causing failures on Tomcat-like adapters --- .../keycloak/adapters/servlet/ServletHttpFacade.java | 10 +++++++++- .../keycloak/adapters/tomcat/CatalinaHttpFacade.java | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/adapters/spi/servlet-adapter-spi/src/main/java/org/keycloak/adapters/servlet/ServletHttpFacade.java b/adapters/spi/servlet-adapter-spi/src/main/java/org/keycloak/adapters/servlet/ServletHttpFacade.java index 6d99560bfa..11e4f931c0 100755 --- a/adapters/spi/servlet-adapter-spi/src/main/java/org/keycloak/adapters/servlet/ServletHttpFacade.java +++ b/adapters/spi/servlet-adapter-spi/src/main/java/org/keycloak/adapters/servlet/ServletHttpFacade.java @@ -67,7 +67,15 @@ public class ServletHttpFacade implements HttpFacade { @Override public String getRelativePath() { - return request.getServletPath(); + String uri = request.getRequestURI(); + String contextPath = request.getContextPath(); + String servletPath = uri.substring(uri.indexOf(contextPath) + contextPath.length()); + + if ("".equals(servletPath)) { + servletPath = "/"; + } + + return servletPath; } @Override diff --git a/adapters/spi/tomcat-adapter-spi/src/main/java/org/keycloak/adapters/tomcat/CatalinaHttpFacade.java b/adapters/spi/tomcat-adapter-spi/src/main/java/org/keycloak/adapters/tomcat/CatalinaHttpFacade.java index c472564914..631474e7b8 100755 --- a/adapters/spi/tomcat-adapter-spi/src/main/java/org/keycloak/adapters/tomcat/CatalinaHttpFacade.java +++ b/adapters/spi/tomcat-adapter-spi/src/main/java/org/keycloak/adapters/tomcat/CatalinaHttpFacade.java @@ -80,7 +80,15 @@ public class CatalinaHttpFacade implements HttpFacade { @Override public String getRelativePath() { - return request.getServletPath(); + String uri = request.getRequestURI(); + String contextPath = request.getContextPath(); + String servletPath = uri.substring(uri.indexOf(contextPath) + contextPath.length()); + + if ("".equals(servletPath)) { + servletPath = "/"; + } + + return servletPath; } @Override