use of org.apache.catalina.Session in project tomcat by apache.
the class HTMLManagerServlet method getSessionsForName.
protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) {
if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) {
String path = null;
if (cn != null) {
path = cn.getPath();
}
throw new IllegalArgumentException(smClient.getString("managerServlet.invalidPath", RequestUtil.filter(path)));
}
Context ctxt = (Context) host.findChild(cn.getName());
if (null == ctxt) {
throw new IllegalArgumentException(smClient.getString("managerServlet.noContext", RequestUtil.filter(cn.getDisplayName())));
}
Manager manager = ctxt.getManager();
List<Session> sessions = new ArrayList<>();
sessions.addAll(Arrays.asList(manager.findSessions()));
if (manager instanceof DistributedManager && showProxySessions) {
// Add dummy proxy sessions
Set<String> sessionIds = ((DistributedManager) manager).getSessionIdsFull();
// Remove active (primary and backup) session IDs from full list
for (Session session : sessions) {
sessionIds.remove(session.getId());
}
// Left with just proxy sessions - add them
for (String sessionId : sessionIds) {
sessions.add(new DummyProxySession(sessionId));
}
}
return sessions;
}
use of org.apache.catalina.Session in project tomcat by apache.
the class HTMLManagerServlet method displaySessionDetailPage.
/**
* Display session details.
*
* @param req The Servlet request
* @param resp The Servlet response
* @param cn Name of the application for which the sessions will be listed
* @param sessionId the session id
* @param smClient StringManager for the client's locale
* @throws ServletException Propagated Servlet error
* @throws IOException An IO error occurred
*/
protected void displaySessionDetailPage(HttpServletRequest req, HttpServletResponse resp, ContextName cn, String sessionId, StringManager smClient) throws ServletException, IOException {
Session session = getSessionForNameAndId(cn, sessionId, smClient);
//strong>NOTE</strong> - This header will be overridden
// automatically if a <code>RequestDispatcher.forward()</code> call is
// ultimately invoked.
// HTTP 1.0
resp.setHeader("Pragma", "No-cache");
// HTTP 1.1
resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
// 0 means now
resp.setDateHeader("Expires", 0);
req.setAttribute("currentSession", session);
getServletContext().getRequestDispatcher(resp.encodeURL(sessionDetailJspPath)).include(req, resp);
}
use of org.apache.catalina.Session in project tomcat by apache.
the class TestPersistentManagerIntegration method backsUpOnce_56698.
@Test
public void backsUpOnce_56698() throws IOException, LifecycleException, InterruptedException {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.setDistributable(true);
Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
ctx.addServletMappingDecoded("/dummy", "DummyServlet");
PersistentManager manager = new PersistentManager();
TesterStore store = new TesterStore();
manager.setStore(store);
manager.setMaxIdleBackup(0);
ctx.setManager(manager);
tomcat.start();
String sessionId = getUrl("http://localhost:" + getPort() + "/dummy").toString();
// Note: PersistenceManager.findSession() silently updates
// session.lastAccessedTime, so call it only once before other work.
Session session = manager.findSession(sessionId);
// Wait until request processing ends, as Request.recycle() updates
// session.lastAccessedTime via session.endAccess().
waitWhileSessionIsActive((StandardSession) session);
long lastAccessedTime = session.getLastAccessedTimeInternal();
// Session should be idle at least for 0 second (maxIdleBackup)
// to be eligible for persistence, thus no need to wait.
// Waiting a bit, to catch changes in last accessed time of a session
waitForClockUpdate();
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId), store.getSavedIds());
Assert.assertEquals(lastAccessedTime, session.getLastAccessedTimeInternal());
// session was not accessed, so no save will be performed
waitForClockUpdate();
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId), store.getSavedIds());
Assert.assertEquals(lastAccessedTime, session.getLastAccessedTimeInternal());
// access session
session.access();
session.endAccess();
// session was accessed, so it will be saved once again
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId, sessionId), store.getSavedIds());
// session was not accessed, so once again no save will happen
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId, sessionId), store.getSavedIds());
}
use of org.apache.catalina.Session in project geode by apache.
the class JvmRouteBinderValve method handlePossibleFailover.
private void handlePossibleFailover(Request request, DeltaSessionManager manager, String localJvmRoute) {
String sessionId = request.getRequestedSessionId();
if (sessionId != null) {
// Get request JVM route
String requestJvmRoute = null;
int index = sessionId.indexOf(".");
if (index > 0) {
requestJvmRoute = sessionId.substring(index + 1, sessionId.length());
}
// If the requested JVM route doesn't equal the session's JVM route, handle failover
if (requestJvmRoute != null && !requestJvmRoute.equals(localJvmRoute)) {
if (manager.getLogger().isDebugEnabled()) {
StringBuilder builder = new StringBuilder();
builder.append(this).append(": Handling failover of session ").append(sessionId).append(" from ").append(requestJvmRoute).append(" to ").append(localJvmRoute);
manager.getLogger().debug(builder.toString());
}
// Get the original session
Session session = null;
try {
session = manager.findSession(sessionId);
} catch (IOException e) {
StringBuilder builder = new StringBuilder();
builder.append(this).append(": Caught exception attempting to find session ").append(sessionId).append(" in ").append(manager);
manager.getLogger().warn(builder.toString(), e);
}
if (session == null) {
StringBuilder builder = new StringBuilder();
builder.append(this).append(": Did not find session ").append(sessionId).append(" to failover in ").append(manager);
manager.getLogger().warn(builder.toString());
} else {
// Change its session id. This removes the previous session and creates the new one.
String baseSessionId = sessionId.substring(0, index);
String newSessionId = baseSessionId + "." + localJvmRoute;
session.setId(newSessionId);
// Change the request's session id
request.changeSessionId(newSessionId);
}
}
}
}
use of org.apache.catalina.Session in project Payara by payara.
the class FormAuthenticator method matchRequest.
/**
* Does this request match the saved one (so that it must be the redirect
* we signaled after successful authentication?
*
* @param request The request to be verified
*/
protected boolean matchRequest(HttpRequest request) {
// Has a session been created?
Session session = getSession(request, false);
if (session == null)
return (false);
// Is there a saved request?
SavedRequest sreq = (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE);
if (sreq == null)
return (false);
// Is there a saved principal?
if (session.getNote(Constants.FORM_PRINCIPAL_NOTE) == null)
return (false);
// Does the request URI match?
HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
String requestURI = hreq.getRequestURI();
if (requestURI == null)
return (false);
return (requestURI.equals(sreq.getRequestURI()));
}
Aggregations