Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Nov 3, 2020
2 parents ebea687 + a4f754d commit 0bb5e8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.Syntax;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SessionIdManager;
Expand Down Expand Up @@ -645,7 +646,7 @@ public HttpCookie getSessionCookie(HttpSession session, String contextPath, bool
HttpCookie cookie = null;

cookie = new HttpCookie(
_cookieConfig.getName(),
getSessionCookieName(_cookieConfig),
id,
_cookieConfig.getDomain(),
sessionPath,
Expand Down Expand Up @@ -1334,6 +1335,13 @@ public interface SessionIf extends HttpSession
public Session getSession();
}

public static String getSessionCookieName(SessionCookieConfig config)
{
if (config == null || config.getName() == null)
return __DefaultSessionCookie;
return config.getName();
}

/**
* CookieConfig
*
Expand Down Expand Up @@ -1423,6 +1431,10 @@ public void setName(String name)
{
if (_context != null && _context.getContextHandler().isAvailable())
throw new IllegalStateException("CookieConfig cannot be set after ServletContext is started");
if ("".equals(name))
throw new IllegalArgumentException("Blank cookie name");
if (name != null)
Syntax.requireValidRFC2616Token(name, "Bad Session cookie name");
_sessionCookie = name;
}

Expand Down Expand Up @@ -1596,12 +1608,12 @@ else if (!DispatcherType.REQUEST.equals(baseRequest.getDispatcherType()))
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0)
{
final String sessionCookie = getSessionCookieConfig().getName();
for (int i = 0; i < cookies.length; i++)
final String sessionCookie = getSessionCookieName(getSessionCookieConfig());
for (Cookie cookie : cookies)
{
if (sessionCookie.equalsIgnoreCase(cookies[i].getName()))
if (sessionCookie.equalsIgnoreCase(cookie.getName()))
{
String id = cookies[i].getValue();
String id = cookie.getValue();
requestedSessionIdFromCookie = true;
if (LOG.isDebugEnabled())
LOG.debug("Got Session ID {} from cookie {}", id, sessionCookie);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.jetty.security.ConstraintAware;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.authentication.FormAuthenticator;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.FilterMapping;
Expand Down Expand Up @@ -745,7 +746,7 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (!context.getSessionHandler().getSessionCookieConfig().getName().equals(name))
if (!name.equals(SessionHandler.getSessionCookieName(context.getSessionHandler().getSessionCookieConfig())))
throw new IllegalStateException("Conflicting cookie-config name " + name + " in " + descriptor.getResource());
break;
}
Expand Down Expand Up @@ -821,7 +822,7 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (!context.getSessionHandler().getSessionCookieConfig().getPath().equals(path))
if (!path.equals(context.getSessionHandler().getSessionCookieConfig().getPath()))
throw new IllegalStateException("Conflicting cookie-config path " + path + " in " + descriptor.getResource());
break;
}
Expand Down

0 comments on commit 0bb5e8c

Please sign in to comment.