tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [tomcat] branch 7.0.x updated: Add session attribute support to the authentication example
Date Thu, 28 Nov 2019 09:37:04 GMT
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new 4666a36  Add session attribute support to the authentication example
4666a36 is described below

commit 4666a36eb6a443d7d2b56395372f476447cf1755
Author: Mark Thomas <markt@apache.org>
AuthorDate: Thu Nov 28 09:26:55 2019 +0000

    Add session attribute support to the authentication example
    
    Primarily to demonstrate session persistence across restarts for
    authenticated sessions.
---
 webapps/docs/changelog.xml                        |  5 +++
 webapps/examples/jsp/security/protected/index.jsp | 39 ++++++++++++++++++++---
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index fcef51b..fbc5504 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -67,6 +67,11 @@
         <code>TestAsyncContextStateChanges</code> test that caused it
         to hang indefinitely. (markt)
       </fix>
+      <add>
+        Add the ability to set and display session attributes in the JSP FORM
+        authentication example to demonstrate session persistence across
+        restarts for authenticated sessions. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Other">
diff --git a/webapps/examples/jsp/security/protected/index.jsp b/webapps/examples/jsp/security/protected/index.jsp
index 1a80409..31122eb 100644
--- a/webapps/examples/jsp/security/protected/index.jsp
+++ b/webapps/examples/jsp/security/protected/index.jsp
@@ -14,6 +14,7 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 --%>
+<%@ page import="java.util.Enumeration" %>
 <%
   if (request.getParameter("logoff") != null) {
     session.invalidate();
@@ -64,17 +65,47 @@ in session <b><%= session.getId() %></b><br><br>
   }
 %>
 
-To check whether your username has been granted a particular role,
+To check whether your user name has been granted a particular role,
 enter it here:
 <form method="GET" action='<%= response.encodeURL("index.jsp") %>'>
 <input type="text" name="role" value="<%= util.HTMLFilter.filter(role) %>">
+<input type="submit" >
 </form>
 <br><br>
 
-If you have configured this app for form-based authentication, you can log
-off by clicking
+To add some data to the authenticated session, enter it here:
+<form method="GET" action='<%= response.encodeURL("index.jsp") %>'>
+<input type="text" name="dataName">
+<input type="text" name="dataValue">
+<input type="submit" >
+</form>
+<br><br>
+
+<%
+  String dataName = request.getParameter("dataName");
+  if (dataName != null) {
+    session.setAttribute(dataName, request.getParameter("dataValue"));
+  }
+%>
+<p>The authenticated session contains the following attributes:</p>
+<table>
+<tr><th>Name</th><th>Value</th></tr>
+<%
+  Enumeration<String> names = session.getAttributeNames();
+  while (names.hasMoreElements()) {
+    String name = names.nextElement();
+%>
+<tr><td><%= name %></td><td><%= session.getAttribute(name)
%></td>
+<%
+  }
+%>
+</table>
+<br><br>
+
+If you have configured this application for form-based authentication, you can
+log off by clicking
 <a href='<%= response.encodeURL("index.jsp?logoff=true") %>'>here</a>.
-This should cause you to be returned to the logon page after the redirect
+This should cause you to be returned to the login page after the redirect
 that is performed.
 
 </body>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message