Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 0 additions & 10 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,16 +987,6 @@ These are bugs, correctness issues, or missing functionality that may affect pro

---

### 93. Manager Session Detail TODO (1 item)

| # | File:Line | Description | Fix Idea | Effort | Difficulty |
|---|-----------|-------------|----------|--------|------------|
| 93.1 | `webapps/manager/WEB-INF/jsp/sessionDetail.jsp:140` | Max Inactive Interval not settable from session detail page | Add a form field and API call to update session max inactive interval. | 1-2 days | Medium |

**Total estimated effort: 1-2 days, Medium difficulty**

---

## Auto-Generated Stub TODOs

These are IDE-generated stub methods with `// TODO Auto-generated method stub` comments. They are low-priority but should eventually be properly implemented.
Expand Down
54 changes: 54 additions & 0 deletions java/org/apache/catalina/manager/HTMLManagerServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,24 @@ protected void doSessions(ContextName cn, HttpServletRequest req, HttpServletRes
req.setAttribute(APPLICATION_MESSAGE, outMessage);
displaySessionDetailPage(req, resp, cn, sessionId, smClient);
return;
} else if ("setMaxInactiveInterval".equals(action)) {
String sessionId = req.getParameter("sessionId");
String intervalParam = req.getParameter("maxInactiveInterval");
try {
int interval = Integer.parseInt(intervalParam);
if (setSessionMaxInactiveInterval(cn, sessionId, interval, smClient)) {
req.setAttribute(APPLICATION_MESSAGE,
smClient.getString("htmlManagerServlet.sessionTimeoutUpdated", sessionId, intervalParam));
} else {
req.setAttribute(APPLICATION_ERROR,
smClient.getString("htmlManagerServlet.sessionTimeoutNotUpdated", sessionId));
}
Comment thread
sainadh777 marked this conversation as resolved.
Resolved
} catch (NumberFormatException nfe) {
req.setAttribute(APPLICATION_ERROR,
smClient.getString("htmlManagerServlet.invalidSessionTimeout", intervalParam));
}
displaySessionDetailPage(req, resp, cn, sessionId, smClient);
return;
} // else
displaySessionsListPage(cn, req, resp, smClient);
}
Expand Down Expand Up @@ -1090,6 +1108,42 @@ protected boolean removeSessionAttribute(ContextName cn, String sessionId, Strin
return wasPresent;
}

/**
* Set the maximum inactive interval for an HTTP session.
*
* @param cn Name of the application hosting the session
* @param sessionId The session id
* @param maxInactiveInterval The maximum inactive interval in seconds
* @param smClient StringManager for the client's locale
*
* @return {@code true} if the interval was updated, otherwise {@code false}
*/
protected boolean setSessionMaxInactiveInterval(ContextName cn, String sessionId, int maxInactiveInterval,
StringManager smClient) {
Session session = getSessionForNameAndId(cn, sessionId, smClient);
if (session == null) {
if (debug >= 1) {
log("Cannot update maximum inactive interval for null session " + sessionId);
}
return false;
}
if (session.getSession() == null) {
if (debug >= 1) {
log("Cannot update maximum inactive interval for session with null HTTP session " + sessionId);
}
return false;
}
try {
session.setMaxInactiveInterval(maxInactiveInterval);
return true;
} catch (IllegalStateException ise) {
if (debug >= 1) {
log("Cannot update maximum inactive interval for invalidated session id " + sessionId);
}
return false;
}
}

/**
* Get a comparator for sessions based on the specified sort criteria.
*
Expand Down
3 changes: 3 additions & 0 deletions java/org/apache/catalina/manager/LocalStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ htmlManagerServlet.helpHtmlManager=HTML Manager Help
htmlManagerServlet.helpHtmlManagerFile=../docs/html-manager-howto.html
htmlManagerServlet.helpManager=Manager Help
htmlManagerServlet.helpManagerFile=../docs/manager-howto.html
htmlManagerServlet.invalidSessionTimeout=Invalid maximum inactive interval [{0}]
htmlManagerServlet.jvmFreeMemory=Free Memory:
htmlManagerServlet.jvmMaxMemory=Max Memory:
htmlManagerServlet.jvmTableTitleInitial=Initial
Expand Down Expand Up @@ -116,6 +117,8 @@ htmlManagerServlet.serverOSVersion=OS Version
htmlManagerServlet.serverTitle=Server Information
htmlManagerServlet.serverVersion=Tomcat Version
htmlManagerServlet.sessionNotFound=Session not found [{0}]
htmlManagerServlet.sessionTimeoutNotUpdated=Unable to update maximum inactive interval for session [{0}]
htmlManagerServlet.sessionTimeoutUpdated=Maximum inactive interval for session [{0}] set to [{1}] seconds
htmlManagerServlet.title=Tomcat Web Application Manager

jmxProxyServlet.noBeanFound=Cannot find MBean with object name [{0}]
Expand Down
38 changes: 38 additions & 0 deletions test/org/apache/catalina/manager/TestManagerWebapp.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ public void testJsps() throws Exception {

tomcat.start();

ManagerBase manager = (ManagerBase) ctx.getManager();
Session session = manager.createSession(null);
manager.add(session);

SimpleHttpClient client = new SimpleHttpClient() {
@Override
public boolean isResponseBodyOK() {
Expand Down Expand Up @@ -789,6 +793,40 @@ public boolean isResponseBodyOK() {
Assert.assertTrue(client.getResponseBody().contains("Sessions Administration"));
Assert.assertTrue(client.getResponseBody().contains("active Sessions"));

m = noncePattern.matcher(client.getResponseBody());
Assert.assertTrue("CSRF nonce not found in sessions response", m.find());
nonce = m.group(1);

String requestBody = "action=setMaxInactiveInterval&sessionId=" + session.getId() +
"&sessionType=Primary&maxInactiveInterval=123";

// Update the maximum inactive interval from the session detail page
// Authentication may have changed the session ID, so use the latest cookie for the POST.
// @formatter:off
client.setRequestPause(0);
client.setRequest(new String[] {
"POST /manager/html/sessions?path=/testapp&" +
Constants.CSRF_NONCE_REQUEST_PARAM + "=" + nonce +
" HTTP/1.1" + CRLF,
"Host: localhost" + CRLF,
"Authorization: " + basicHeader + CRLF,
"Cookie: JSESSIONID=" + client.getSessionId() + CRLF,
"Content-Type: application/x-www-form-urlencoded" + CRLF,
"Content-Length: " + requestBody.getBytes(StandardCharsets.UTF_8).length + CRLF,
"Connection: Close" + CRLF,
CRLF,
requestBody
});
// @formatter:on
client.connect();
client.processRequest(true);
Assert.assertEquals(HttpServletResponse.SC_OK, client.getStatusCode());
Assert.assertEquals(123, session.getMaxInactiveInterval());
Assert.assertTrue(client.getResponseBody().contains("name=\"maxInactiveInterval\""));
Assert.assertTrue(client.getResponseBody().contains("value=\"123\""));
Assert.assertTrue(client.getResponseBody().contains(
"Maximum inactive interval for session [" + session.getId() + "] set to [123] seconds"));

tomcat.stop();
}

Expand Down
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@
</subsection>
<subsection name="Web applications">
<changelog>
<add>
Add support for updating a primary session's maximum inactive interval
from the session detail page in the HTML Manager. (sainadh777)
</add>
<add>
Add Manager 2.0 webapp with a modern reactive design. Provided as a
module in the <code>modules/manager2</code> folder in the source
Expand Down
24 changes: 21 additions & 3 deletions webapps/manager/WEB-INF/jsp/sessionDetail.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,31 @@
<th>Attribute value</th>
</tr>
</thead>
<%--tfoot>
<tfoot>
<tr>
<td colspan="3" style="text-align: center;">
TODO: set Max Inactive Interval on sessions
<%
if ("Primary".equals(request.getParameter("sessionType"))) {
%>
<form method="POST" action="<%= submitUrl %>">
<div>
<input type="hidden" name="action" value="setMaxInactiveInterval" />
<input type="hidden" name="sessionId" value="<%= currentSessionId %>" />
<input type="hidden" name="sessionType" value="Primary" />
<label for="maxInactiveInterval">Maximum inactive interval (seconds):</label>
<input type="text" id="maxInactiveInterval" name="maxInactiveInterval"
value="<%= currentSession.getMaxInactiveInterval() %>" />
<input type="submit" value="Update" />
</div>
</form>
<%
} else {
out.print("Primary sessions only");
}
%>
</td>
</tr>
</tfoot--%>
</tfoot>
<tbody>
<% attributeNamesEnumeration = currentHttpSession.getAttributeNames();
while (attributeNamesEnumeration.hasMoreElements()) {
Expand Down