Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path for serverTime / sessionExpiry when GeoNetwork runs in / It creates these cookies per each path. #7446

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
package org.geonetwork.http;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
Expand All @@ -40,7 +38,6 @@
import org.apache.commons.lang.StringUtils;

import jeeves.server.UserSession;
import jeeves.server.dispatchers.ServiceManager;
import jeeves.server.sources.http.JeevesServlet;

/**
Expand All @@ -64,26 +61,28 @@ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filte
if (session != null) {
long currTime = System.currentTimeMillis();

String cookiePath = StringUtils.isBlank(httpReq.getContextPath()) ? "/" : httpReq.getContextPath();

Cookie cookie = new Cookie("serverTime", "" + currTime);
cookie.setPath(httpReq.getContextPath());
cookie.setPath(cookiePath);
cookie.setSecure(req.getServletContext().getSessionCookieConfig().isSecure());
httpResp.addCookie(cookie);

UserSession userSession = null;
if (session != null) {
Object tmp = session.getAttribute(JeevesServlet.USER_SESSION_ATTRIBUTE_KEY);
if (tmp instanceof UserSession) {
userSession = (UserSession) tmp;
}

Object tmp = session.getAttribute(JeevesServlet.USER_SESSION_ATTRIBUTE_KEY);
if (tmp instanceof UserSession) {
userSession = (UserSession) tmp;
}

// If user is authenticated, then set expiration time
if (userSession != null && StringUtils.isNotEmpty(userSession.getName())) {
long expiryTime = currTime + session.getMaxInactiveInterval() * 1000;
cookie = new Cookie("sessionExpiry", "" + expiryTime);
} else {
cookie = new Cookie("sessionExpiry", "" + currTime);
}
cookie.setPath(httpReq.getContextPath());
cookie.setPath(cookiePath);
cookie.setSecure(req.getServletContext().getSessionCookieConfig().isSecure());
httpResp.addCookie(cookie);
}
Expand Down