Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 771 | blopes | 1 | <!DOCTYPE html><html><head><meta charset="UTF-8" /><title>Source Code</title></head><body><pre><%-- |
| 2 | Licensed to the Apache Software Foundation (ASF) under one or more |
||
| 3 | contributor license agreements. See the NOTICE file distributed with |
||
| 4 | this work for additional information regarding copyright ownership. |
||
| 5 | The ASF licenses this file to You under the Apache License, Version 2.0 |
||
| 6 | (the "License"); you may not use this file except in compliance with |
||
| 7 | the License. You may obtain a copy of the License at |
||
| 8 | |||
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
||
| 10 | |||
| 11 | Unless required by applicable law or agreed to in writing, software |
||
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
||
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
| 14 | See the License for the specific language governing permissions and |
||
| 15 | limitations under the License. |
||
| 16 | --%> |
||
| 17 | <%@ page import="java.net.URLEncoder" %> |
||
| 18 | <%@ page import="java.security.Principal" %> |
||
| 19 | <%@ page import="java.util.Enumeration" %> |
||
| 20 | <%@ page import="org.apache.catalina.TomcatPrincipal" %> |
||
| 21 | <% |
||
| 22 | if (request.getParameter("logoff") != null) { |
||
| 23 | session.invalidate(); |
||
| 24 | response.sendRedirect("index.jsp"); |
||
| 25 | return; |
||
| 26 | } |
||
| 27 | %> |
||
| 28 | <html> |
||
| 29 | <head> |
||
| 30 | <title>Protected Page for Examples</title> |
||
| 31 | </head> |
||
| 32 | <body bgcolor="white"> |
||
| 33 | |||
| 34 | You are logged in as remote user |
||
| 35 | <b><%= util.HTMLFilter.filter(request.getRemoteUser()) %></b> |
||
| 36 | in session <b><%= session.getId() %></b><br><br> |
||
| 37 | |||
| 38 | <% |
||
| 39 | if (request.getUserPrincipal() != null) { |
||
| 40 | %> |
||
| 41 | Your user principal name is |
||
| 42 | <b><%= util.HTMLFilter.filter(request.getUserPrincipal().getName()) %></b> |
||
| 43 | <br><br> |
||
| 44 | <% |
||
| 45 | } else { |
||
| 46 | %> |
||
| 47 | No user principal could be identified.<br><br> |
||
| 48 | <% |
||
| 49 | } |
||
| 50 | %> |
||
| 51 | |||
| 52 | <% |
||
| 53 | String role = request.getParameter("role"); |
||
| 54 | if (role == null) |
||
| 55 | role = ""; |
||
| 56 | if (role.length() > 0) { |
||
| 57 | if (request.isUserInRole(role)) { |
||
| 58 | %> |
||
| 59 | You have been granted role |
||
| 60 | <b><%= util.HTMLFilter.filter(role) %></b><br><br> |
||
| 61 | <% |
||
| 62 | } else { |
||
| 63 | %> |
||
| 64 | You have <i>not</i> been granted role |
||
| 65 | <b><%= util.HTMLFilter.filter(role) %></b><br><br> |
||
| 66 | <% |
||
| 67 | } |
||
| 68 | } |
||
| 69 | %> |
||
| 70 | |||
| 71 | To check whether your user name has been granted a particular role, |
||
| 72 | enter it here: |
||
| 73 | <form method="GET" action='<%= response.encodeURL("index.jsp") %>'> |
||
| 74 | <input type="text" name="role" value="<%= util.HTMLFilter.filter(role) %>"> |
||
| 75 | <input type="submit" > |
||
| 76 | </form> |
||
| 77 | <br><br> |
||
| 78 | |||
| 79 | <% |
||
| 80 | Principal p = request.getUserPrincipal(); |
||
| 81 | if (!(p instanceof TomcatPrincipal)) { |
||
| 82 | %> |
||
| 83 | <p>The principal does not support attributes.</p> |
||
| 84 | <% |
||
| 85 | } else { |
||
| 86 | TomcatPrincipal principal = (TomcatPrincipal) p; |
||
| 87 | %> |
||
| 88 | <p>The principal contains the following attributes:</p> |
||
| 89 | <table> |
||
| 90 | <tr><th>Name</th><th>Value</th><th>Type</th></tr> |
||
| 91 | <% |
||
| 92 | Enumeration<String> names = principal.getAttributeNames(); |
||
| 93 | while (names.hasMoreElements()) { |
||
| 94 | String name = names.nextElement(); |
||
| 95 | Object value = principal.getAttribute(name); |
||
| 96 | String type = value != null ? value.getClass().getName() : "unknown"; |
||
| 97 | if (value instanceof Object[]) { |
||
| 98 | Object[] values = (Object[]) value; |
||
| 99 | value = ""; |
||
| 100 | for (int i = 0; i < values.length; i++) { |
||
| 101 | value += values[i] + "<br/>"; |
||
| 102 | } |
||
| 103 | if (values.length > 0) { |
||
| 104 | type = values[0].getClass().getName() + "[]"; |
||
| 105 | } else { |
||
| 106 | type = "unknown"; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | type = type.replaceFirst("^java\\.lang\\.", ""); |
||
| 110 | %> |
||
| 111 | <tr> |
||
| 112 | <td><%= util.HTMLFilter.filter(name) %></td> |
||
| 113 | <td><%= util.HTMLFilter.filter(String.valueOf(value)) %></td> |
||
| 114 | <td><%= util.HTMLFilter.filter(type) %></td> |
||
| 115 | </tr> |
||
| 116 | <% |
||
| 117 | } |
||
| 118 | %> |
||
| 119 | </table> |
||
| 120 | <% |
||
| 121 | } |
||
| 122 | %> |
||
| 123 | <br><br> |
||
| 124 | |||
| 125 | <% |
||
| 126 | // Count the existing attributes |
||
| 127 | int sessionAttributeCount = 0; |
||
| 128 | Enumeration<String> names = session.getAttributeNames(); |
||
| 129 | while (names.hasMoreElements()) { |
||
| 130 | names.nextElement(); |
||
| 131 | sessionAttributeCount++; |
||
| 132 | } |
||
| 133 | |||
| 134 | String dataName = request.getParameter("dataName"); |
||
| 135 | String dataValue = request.getParameter("dataValue"); |
||
| 136 | if (dataName != null) { |
||
| 137 | if (dataValue == null) { |
||
| 138 | session.removeAttribute(dataName); |
||
| 139 | sessionAttributeCount--; |
||
| 140 | } else if (sessionAttributeCount < 10) { |
||
| 141 | session.setAttribute(dataName, dataValue); |
||
| 142 | sessionAttributeCount++; |
||
| 143 | } else { |
||
| 144 | %> |
||
| 145 | <p>Session attribute [<%= util.HTMLFilter.filter(dataName) %>] not added as there are already 10 attributes in the |
||
| 146 | session. Delete an attribute before adding another.</p> |
||
| 147 | <% |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | if (sessionAttributeCount < 10) { |
||
| 152 | %> |
||
| 153 | To add some data to the authenticated session, enter it here: |
||
| 154 | <form method="GET" action='<%= response.encodeURL("index.jsp") %>'> |
||
| 155 | <input type="text" name="dataName"> |
||
| 156 | <input type="text" name="dataValue"> |
||
| 157 | <input type="submit" > |
||
| 158 | </form> |
||
| 159 | <% |
||
| 160 | } else { |
||
| 161 | %> |
||
| 162 | <p>You may not add more than 10 attributes to this session.</p> |
||
| 163 | <% |
||
| 164 | } |
||
| 165 | %> |
||
| 166 | <br><br> |
||
| 167 | |||
| 168 | <p>The authenticated session contains the following attributes:</p> |
||
| 169 | <table> |
||
| 170 | <tr><th>Name</th><th>Value</th></tr> |
||
| 171 | <% |
||
| 172 | names = session.getAttributeNames(); |
||
| 173 | while (names.hasMoreElements()) { |
||
| 174 | String name = names.nextElement(); |
||
| 175 | String value = session.getAttribute(name).toString(); |
||
| 176 | %> |
||
| 177 | <tr> |
||
| 178 | <td><%= util.HTMLFilter.filter(name) %></td> |
||
| 179 | <td><%= util.HTMLFilter.filter(value) %></td> |
||
| 180 | <td><a href='<%= response.encodeURL("index.jsp?dataName=" + URLEncoder.encode(name, "UTF-8")) %>'>delete</a></td> |
||
| 181 | </tr> |
||
| 182 | <% |
||
| 183 | } |
||
| 184 | %> |
||
| 185 | </table> |
||
| 186 | <br><br> |
||
| 187 | |||
| 188 | If you have configured this application for form-based authentication, you can |
||
| 189 | log off by clicking |
||
| 190 | <a href='<%= response.encodeURL("index.jsp?logoff=true") %>'>here</a>. |
||
| 191 | This should cause you to be returned to the login page after the redirect |
||
| 192 | that is performed. |
||
| 193 | |||
| 194 | </body> |
||
| 195 | </html> |
||
| 196 | </pre></body></html> |