From 150129566efe7047924c5352ae02d430b8960a5f Mon Sep 17 00:00:00 2001 From: Sean Flanigan Date: Fri, 29 Aug 2014 15:16:28 +1000 Subject: [PATCH] Add workarounds for WildFly bugs: WFLY-3617, WFLY-3744 --- .../servlet/ZanataServletExtension.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/zanata-war/src/main/java/org/zanata/servlet/ZanataServletExtension.java b/zanata-war/src/main/java/org/zanata/servlet/ZanataServletExtension.java index 58d392935d..4333bed1cf 100644 --- a/zanata-war/src/main/java/org/zanata/servlet/ZanataServletExtension.java +++ b/zanata-war/src/main/java/org/zanata/servlet/ZanataServletExtension.java @@ -23,25 +23,57 @@ import io.undertow.servlet.ServletExtension; import io.undertow.servlet.api.DeploymentInfo; import io.undertow.util.ImmediateAuthenticationMechanismFactory; +import lombok.extern.slf4j.Slf4j; import org.zanata.security.DummyAuthenticationMechanism; import javax.servlet.ServletContext; +import javax.servlet.SessionCookieConfig; /** - * This Undertow servlet extension adds a dummy SPNEGO implemention so - * that we can deploy on WildFly. + * This Undertow servlet extension adds a dummy SPNEGO implementation so + * that we can deploy on WildFly, and also provides other workarounds as + * needed. * * @author Sean Flanigan sflaniga@redhat.com */ +@Slf4j public class ZanataServletExtension implements ServletExtension { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { if (!deploymentInfo.getAuthenticationMechanisms().containsKey("SPNEGO")) { + log.debug("Registering dummy SPNEGO authentication mechanism"); deploymentInfo.addAuthenticationMechanism("SPNEGO", new ImmediateAuthenticationMechanismFactory( new DummyAuthenticationMechanism())); } + + String contextPath = servletContext.getContextPath(); + + // workaround for https://issues.jboss.org/browse/WFLY-3744 + if (contextPath == null || contextPath.equals("/")) { + log.warn("ContextPath was \"/\", changing to \"\" (WFLY-3744 workaround)"); + deploymentInfo.setContextPath(""); + } + + // workaround for https://issues.jboss.org/browse/WFLY-3617 + SessionCookieConfig cookieConfig = + servletContext.getSessionCookieConfig(); + String cookiePath = cookieConfig.getPath(); + if (cookiePath == null) { + log.info("Cookie path is null"); + } else if (cookiePath.isEmpty()) { + String newCookiePath; + if (contextPath == null || contextPath.isEmpty()) { + newCookiePath = "/"; + } else { + newCookiePath = contextPath; + } + log.warn("Cookie path was empty, changing to \"{}\" (WFLY-3617 workaround)", newCookiePath); + cookieConfig.setPath(newCookiePath); + } else { + log.info("Cookie path is \"{}\"", cookiePath); + } } }