Subversion Repositories Integrator Subversion

Rev

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>&lt;%--
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
&lt;%@ page import="java.net.URLEncoder" %>
18
&lt;%@ page import="java.security.Principal" %>
19
&lt;%@ page import="java.util.Enumeration" %>
20
&lt;%@ page import="org.apache.catalina.TomcatPrincipal" %>
21
&lt;%
22
  if (request.getParameter("logoff") != null) {
23
    session.invalidate();
24
    response.sendRedirect("index.jsp");
25
    return;
26
  }
27
%>
28
&lt;html>
29
&lt;head>
30
&lt;title>Protected Page for Examples&lt;/title>
31
&lt;/head>
32
&lt;body bgcolor="white">
33
 
34
You are logged in as remote user
35
&lt;b>&lt;%= util.HTMLFilter.filter(request.getRemoteUser()) %>&lt;/b>
36
in session &lt;b>&lt;%= session.getId() %>&lt;/b>&lt;br>&lt;br>
37
 
38
&lt;%
39
  if (request.getUserPrincipal() != null) {
40
%>
41
    Your user principal name is
42
    &lt;b>&lt;%= util.HTMLFilter.filter(request.getUserPrincipal().getName()) %>&lt;/b>
43
    &lt;br>&lt;br>
44
&lt;%
45
  } else {
46
%>
47
    No user principal could be identified.&lt;br>&lt;br>
48
&lt;%
49
  }
50
%>
51
 
52
&lt;%
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
      &lt;b>&lt;%= util.HTMLFilter.filter(role) %>&lt;/b>&lt;br>&lt;br>
61
&lt;%
62
    } else {
63
%>
64
      You have &lt;i>not&lt;/i> been granted role
65
      &lt;b>&lt;%= util.HTMLFilter.filter(role) %>&lt;/b>&lt;br>&lt;br>
66
&lt;%
67
    }
68
  }
69
%>
70
 
71
To check whether your user name has been granted a particular role,
72
enter it here:
73
&lt;form method="GET" action='&lt;%= response.encodeURL("index.jsp") %>'>
74
&lt;input type="text" name="role" value="&lt;%= util.HTMLFilter.filter(role) %>">
75
&lt;input type="submit" >
76
&lt;/form>
77
&lt;br>&lt;br>
78
 
79
&lt;%
80
  Principal p = request.getUserPrincipal();
81
  if (!(p instanceof TomcatPrincipal)) {
82
%>
83
&lt;p>The principal does not support attributes.&lt;/p>
84
&lt;%
85
  } else {
86
    TomcatPrincipal principal = (TomcatPrincipal) p;
87
%>
88
&lt;p>The principal contains the following attributes:&lt;/p>
89
&lt;table>
90
&lt;tr>&lt;th>Name&lt;/th>&lt;th>Value&lt;/th>&lt;th>Type&lt;/th>&lt;/tr>
91
&lt;%
92
    Enumeration&lt;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 &lt; values.length; i++) {
101
          value += values[i] + "&lt;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
&lt;tr>
112
  &lt;td>&lt;%= util.HTMLFilter.filter(name) %>&lt;/td>
113
  &lt;td>&lt;%= util.HTMLFilter.filter(String.valueOf(value)) %>&lt;/td>
114
  &lt;td>&lt;%= util.HTMLFilter.filter(type) %>&lt;/td>
115
&lt;/tr>
116
&lt;%
117
    }
118
%>
119
&lt;/table>
120
&lt;%
121
  }
122
%>
123
&lt;br>&lt;br>
124
 
125
&lt;%
126
  // Count the existing attributes
127
  int sessionAttributeCount = 0;
128
  Enumeration&lt;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 &lt; 10) {
141
      session.setAttribute(dataName, dataValue);
142
      sessionAttributeCount++;
143
    } else {
144
%>
145
&lt;p>Session attribute [&lt;%= util.HTMLFilter.filter(dataName) %>] not added as there are already 10 attributes in the
146
session. Delete an attribute before adding another.&lt;/p>
147
&lt;%
148
    }
149
  }
150
 
151
  if (sessionAttributeCount &lt; 10) {
152
%>
153
To add some data to the authenticated session, enter it here:
154
&lt;form method="GET" action='&lt;%= response.encodeURL("index.jsp") %>'>
155
&lt;input type="text" name="dataName">
156
&lt;input type="text" name="dataValue">
157
&lt;input type="submit" >
158
&lt;/form>
159
&lt;%
160
  } else {
161
%>
162
&lt;p>You may not add more than 10 attributes to this session.&lt;/p>
163
&lt;%
164
  }
165
%>
166
&lt;br>&lt;br>
167
 
168
&lt;p>The authenticated session contains the following attributes:&lt;/p>
169
&lt;table>
170
&lt;tr>&lt;th>Name&lt;/th>&lt;th>Value&lt;/th>&lt;/tr>
171
&lt;%
172
  names = session.getAttributeNames();
173
  while (names.hasMoreElements()) {
174
    String name = names.nextElement();
175
    String value = session.getAttribute(name).toString();
176
%>
177
&lt;tr>
178
  &lt;td>&lt;%= util.HTMLFilter.filter(name) %>&lt;/td>
179
  &lt;td>&lt;%= util.HTMLFilter.filter(value) %>&lt;/td>
180
  &lt;td>&lt;a href='&lt;%= response.encodeURL("index.jsp?dataName=" + URLEncoder.encode(name, "UTF-8")) %>'>delete&lt;/a>&lt;/td>
181
&lt;/tr>
182
&lt;%
183
  }
184
%>
185
&lt;/table>
186
&lt;br>&lt;br>
187
 
188
If you have configured this application for form-based authentication, you can
189
log off by clicking
190
&lt;a href='&lt;%= response.encodeURL("index.jsp?logoff=true") %>'>here&lt;/a>.
191
This should cause you to be returned to the login page after the redirect
192
that is performed.
193
 
194
&lt;/body>
195
&lt;/html>
196
</pre></body></html>