use of org.apache.catalina.Session in project tomcat by apache.
the class TestSSOnonLoginAndBasicAuthenticator method doImminentSessionTimeout.
/*
* Force faster timeout for an active Container than can
* be defined in web.xml. By getting to the active Session we
* can choose seconds instead of minutes.
* Note: shamelessly cloned from ManagerBase - beware of synch issues
* on the underlying sessions.
*/
private void doImminentSessionTimeout(Context activeContext) {
ManagerBase manager = (ManagerBase) activeContext.getManager();
Session[] sessions = manager.findSessions();
for (Session session : sessions) {
if (session != null && session.isValid()) {
session.setMaxInactiveInterval(EXTRA_DELAY_SECS);
// leave it to be expired by the manager
}
}
try {
Thread.sleep(EXTRA_DELAY_SECS * 1000);
} catch (InterruptedException ie) {
// ignored
}
// Paranoid verification that active sessions have now gone
int count = 0;
sessions = manager.findSessions();
while (sessions.length != 0 && count < TIMEOUT_WAIT_SECS) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Ignore
}
sessions = manager.findSessions();
count++;
}
sessions = manager.findSessions();
Assert.assertTrue(sessions.length == 0);
}
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", Escape.htmlElementContent(path)));
}
Context ctxt = (Context) host.findChild(cn.getName());
if (null == ctxt) {
throw new IllegalArgumentException(smClient.getString("managerServlet.noContext", Escape.htmlElementContent(cn.getDisplayName())));
}
Manager manager = ctxt.getManager();
List<Session> sessions = new ArrayList<>(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 DeltaManager method expireAllLocalSessions.
/**
* Expire all find sessions.
*/
public void expireAllLocalSessions() {
long timeNow = System.currentTimeMillis();
Session[] sessions = findSessions();
int expireDirect = 0;
int expireIndirect = 0;
if (log.isDebugEnabled()) {
log.debug("Start expire all sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length);
}
for (Session value : sessions) {
if (value instanceof DeltaSession) {
DeltaSession session = (DeltaSession) value;
if (session.isPrimarySession()) {
if (session.isValid()) {
session.expire();
expireDirect++;
} else {
expireIndirect++;
}
// end if
}
// end if
}
// end if
}
// for
long timeEnd = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("End expire sessions " + getName() + " expire processingTime " + (timeEnd - timeNow) + " expired direct sessions: " + expireDirect + " expired direct sessions: " + expireIndirect);
}
}
use of org.apache.catalina.Session in project tomcat by apache.
the class DeltaManager method stopInternal.
/**
* Stop this component and implement the requirements
* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
if (log.isDebugEnabled()) {
log.debug(sm.getString("deltaManager.stopped", getName()));
}
setState(LifecycleState.STOPPING);
// Expire all active sessions
if (log.isInfoEnabled()) {
log.info(sm.getString("deltaManager.expireSessions", getName()));
}
Session[] sessions = findSessions();
for (Session value : sessions) {
DeltaSession session = (DeltaSession) value;
if (!session.isValid()) {
continue;
}
try {
session.expire(true, isExpireSessionsOnShutdown());
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
}
}
// Require a new random number generator if we are restarted
super.stopInternal();
}
Aggregations