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