blob: 67085935dd9fca97b5fc35e77fea7182fe3402e7 [file] [log] [blame]
刘洪青6266f992017-05-15 21:21:03 +08001<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Catalina Functional Specifications (7.0.77) - MemoryRealm</title><meta name="author" content="Craig McClanahan"><style type="text/css" media="print">
2 .noPrint {display: none;}
3 td#mainBody {width: 100%;}
4</style><style type="text/css">
5code {background-color:rgb(224,255,255);padding:0 0.1em;}
6code.attributeName, code.propertyName {background-color:transparent;}
7
8
9table {
10 border-collapse: collapse;
11 text-align: left;
12}
13table *:not(table) {
14 /* Prevent border-collapsing for table child elements like <div> */
15 border-collapse: separate;
16}
17
18th {
19 text-align: left;
20}
21
22
23div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
24 background-color: transparent;
25}
26div.codeBox {
27 overflow: auto;
28 margin: 1em 0;
29}
30div.codeBox pre {
31 margin: 0;
32 padding: 4px;
33 border: 1px solid #999;
34 border-radius: 5px;
35 background-color: #eff8ff;
36 display: table; /* To prevent <pre>s from taking the complete available width. */
37 /*
38 When it is officially supported, use the following CSS instead of display: table
39 to prevent big <pre>s from exceeding the browser window:
40 max-width: available;
41 width: min-content;
42 */
43}
44
45div.codeBox pre.wrap {
46 white-space: pre-wrap;
47}
48
49
50table.defaultTable tr, table.detail-table tr {
51 border: 1px solid #CCC;
52}
53
54table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
55 background-color: #FAFBFF;
56}
57
58table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
59 background-color: #EEEFFF;
60}
61
62table.defaultTable th, table.detail-table th {
63 background-color: #88b;
64 color: #fff;
65}
66
67table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
68 padding: 5px 8px;
69}
70
71
72p.notice {
73 border: 1px solid rgb(255, 0, 0);
74 background-color: rgb(238, 238, 238);
75 color: rgb(0, 51, 102);
76 padding: 0.5em;
77 margin: 1em 2em 1em 1em;
78}
79</style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="../images/tomcat.gif" align="right" alt="
Hongqing Liufd5ee812014-05-10 16:32:51 +080080 Catalina Functional Specifications
刘洪青6266f992017-05-15 21:21:03 +080081 " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.77, Mar 28 2017</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="../images/asf-logo.svg" align="right" alt="Apache Logo" border="0" style="width: 266px;height: 83px;"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><p><strong>Links</strong></p><ul><li><a href="../index.html">Docs Home</a></li><li><a href="index.html">Functional Specs</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul><p><strong>Administrative Apps</strong></p><ul><li><a href="fs-admin-apps.html">Overall Requirements</a></li><li><a href="mbean-names.html">Tomcat MBean Names</a></li><li><a href="fs-admin-objects.html">Administered Objects</a></li><li><a href="fs-admin-opers.html">Supported Operations</a></li></ul><p><strong>Internal Servlets</strong></p><ul><li><a href="fs-default.html">Default Servlet</a></li></ul><p><strong>Realm Implementations</strong></p><ul><li><a href="fs-jdbc-realm.html">JDBC Realm</a></li><li><a href="fs-jndi-realm.html">JNDI Realm</a></li><li><a href="fs-memory-realm.html">Memory Realm</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>MemoryRealm</h1><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
Hongqing Liufd5ee812014-05-10 16:32:51 +080082<ul><li><a href="#Overview">Overview</a><ol><li><a href="#Introduction">Introduction</a></li><li><a href="#External_Specifications">External Specifications</a></li><li><a href="#Implementation_Requirements">Implementation Requirements</a></li></ol></li><li><a href="#Dependencies">Dependencies</a><ol><li><a href="#Environmental_Dependencies">Environmental Dependencies</a></li><li><a href="#Container_Dependencies">Container Dependencies</a></li></ol></li><li><a href="#Functionality">Functionality</a><ol><li><a href="#Overview_of_Operation">Overview of Operation</a></li><li><a href="#Detailed_Functional_Requirements">Detailed Functional Requirements</a></li></ol></li><li><a href="#Testable_Assertions">Testable Assertions</a></li></ul>
83</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Overview"><strong>Overview</strong></a></font></td></tr><tr><td><blockquote>
84
85
86 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
87
88 <p>The purpose of the <strong>MemoryRealm</strong> implementation is to
刘洪青6266f992017-05-15 21:21:03 +080089 provide a mechanism by which Tomcat can acquire information needed
Hongqing Liufd5ee812014-05-10 16:32:51 +080090 to authenticate web application users, and define their security roles,
91 from a simple text-based configuration file in XML format. This is
刘洪青6266f992017-05-15 21:21:03 +080092 intended to simplify the initial installation and operation of Tomcat,
Hongqing Liufd5ee812014-05-10 16:32:51 +080093 without the complexity of configuring a database or directory server
94 based Realm. It is not intended for production use.</p>
95
96 <p>This specification reflects a combination of functionality that is
97 already present in the <code>org.apache.catalina.realm.MemoryRealm</code>
98 class, as well as requirements for enhancements that have been
99 discussed. Where appropriate, requirements statements are marked
100 <em>[Current]</em> and <em>[Requested]</em> to distinguish them.</p>
101
102 <p>The current status of this functional specification is
103 <strong>PROPOSED</strong>. It has not yet been discussed and
104 agreed to on the TOMCAT-DEV mailing list.</p>
105
106 </blockquote></td></tr></table>
107
108
109 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="External Specifications"><!--()--></a><a name="External_Specifications"><strong>External Specifications</strong></a></font></td></tr><tr><td><blockquote>
110
111 <p>The implementation of this functionality depends on the following
112 external specifications:</p>
113 <ul>
114 <li>None</li>
115 </ul>
116
117 </blockquote></td></tr></table>
118
119
120 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Implementation Requirements"><!--()--></a><a name="Implementation_Requirements"><strong>Implementation Requirements</strong></a></font></td></tr><tr><td><blockquote>
121
122 <p>The implementation of this functionality shall conform to the
123 following requirements:</p>
124 <ul>
125 <li>Be realized in one or more implementation classes.</li>
126 <li>Implement the <code>org.apache.catalina.Realm</code> interface.
127 [Current]</li>
128 <li>Implement the <code>org.apache.catalina.Lifecycle</code>
129 interface. [Current]</li>
130 <li>Subclass the <code>org.apache.catalina.realm.RealmBase</code>
131 base class.</li>
132 <li>Live in the <code>org.apache.catalina.realm</code> package.
133 [Current]</li>
134 <li>Support a configurable debugging detail level. [Current]</li>
135 <li>Log debugging and operational messages (suitably internationalized)
136 via the <code>getContainer().log()</code> method. [Current]</li>
137 </ul>
138
139 </blockquote></td></tr></table>
140
141
142</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Dependencies"><strong>Dependencies</strong></a></font></td></tr><tr><td><blockquote>
143
144
145 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Environmental Dependencies"><!--()--></a><a name="Environmental_Dependencies"><strong>Environmental Dependencies</strong></a></font></td></tr><tr><td><blockquote>
146
147 <p>The following environmental dependencies must be met in order for
148 MemoryRealm to operate correctly:</p>
149 <ul>
150 <li>The desire to utilize MemoryRealm must be registered in
151 <code>$CATALINA_BASE/conf/server.xml</code>, in a
152 <code>&lt;Realm&gt;</code> element that is nested inside a
153 corresponding <code>&lt;Engine&gt;</code>, <code>&lt;Host&gt;</code>,
154 or <code>&lt;Context&gt;</code> element. (This is already
155 included in the default <code>server.xml</code> file.)</li>
156 </ul>
157
158 </blockquote></td></tr></table>
159
160
161 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Container Dependencies"><!--()--></a><a name="Container_Dependencies"><strong>Container Dependencies</strong></a></font></td></tr><tr><td><blockquote>
162
163 <p>Correct operation of MemoryRealm depends on the following
164 specific features of the surrounding container:</p>
165 <ul>
166 <li>Interactions with <code>MemoryRealm</code> will be initiated by
167 the appropriate <code>Authenticator</code> implementation, based
168 on the login method that is selected.</li>
169 <li><code>MemoryRealm</code> must have an XML parser compatible with
170 the JAXP/1.1 APIs available to it. This is normally accomplished
171 by placing the corresponding JAR files in directory
172 <code>$CATALINA_HOME/lib</code>.</li>
173 </ul>
174
175 </blockquote></td></tr></table>
176
177
178</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Functionality"><strong>Functionality</strong></a></font></td></tr><tr><td><blockquote>
179
180
181 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Overview of Operation"><!--()--></a><a name="Overview_of_Operation"><strong>Overview of Operation</strong></a></font></td></tr><tr><td><blockquote>
182
183 <p>The main purpose of <code>MemoryRealm</code> is to allow Catalina to
184 authenticate users, and look up the corresponding security roles, from
185 the information found in an XML-format configuration file. The format
186 of this file is described below. When a <code>MemoryRealm</code>
187 instance is started, it will read the contents of this XML file and create
188 an "in memory database" of all the valid users and their associated
189 security roles.</p>
190
191 <p>Each time that Catalina needs to authenticate a user, it will call
192 the <code>authenticate()</code> method of this Realm implementation,
193 passing the username and password that were specified by the user. If
194 we find the user in the database (and match on the password), we accumulate
195 all of the security roles that are defined for this user, and create a
196 new <code>GenericPrincipal</code> object to be returned. If the user
197 is not authenticated, we return <code>null</code> instead. The
198 <code>GenericUser</code> object caches the set of security roles that
199 were owned by this user at the time of authentication, so that calls to
200 <code>isUserInRole()</code> can be answered without going back to the
201 database every time.</p>
202
203 </blockquote></td></tr></table>
204
205
206 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Detailed Functional Requirements"><!--()--></a><a name="Detailed_Functional_Requirements"><strong>Detailed Functional Requirements</strong></a></font></td></tr><tr><td><blockquote>
207
208
209 <h3>Configurable Properties</h3>
210
211 <p>The implementation shall support the following properties
212 that can be configured with JavaBeans property setters:</p>
213 <ul>
214 <li>Configurable debugging detail level.</li>
215 <li>Configurable file pathname (absolute or relative to
216 <code>$CATALINA_BASE</code> of the XML file containing our
217 defined users. [<code>conf/tomcat-users.xml</code>].</li>
218 </ul>
219
220 <h3>Lifecycle Functionality</h3>
221
222 <p>The following processing must be performed when the <code>start()</code>
223 method is called:</p>
224 <ul>
225 <li>Open and parse the specified XML file.</li>
226 <li>Create an in-memory database representation of the XML file
227 contents.</li>
228 <li><strong>NOTE</strong> - There is no requirement to recognize
229 subsequent changes to the contents of the XML file.</li>
230 </ul>
231
232 <p>The following processing must be performed when the <code>stop()</code>
233 method is called:</p>
234 <ul>
235 <li>Release object references to the in-memory database representation.</li>
236 </ul>
237
238
239 <h3>Method authenticate() Functionality</h3>
240
241 <p>When <code>authenticate()</code> is called, the following processing
242 is required:</p>
243 <ul>
244 <li>Select the one and only "user" instance from the in-memory database,
245 based on matching the specified username. If there is no such
246 instance, return <code>null</code>.</li>
247 <li>Authenticate the user by comparing the (possibly encrypted) password
248 value that was received against the password presented by the user.
249 If there is no match, return <code>null</code>.</li>
250 <li>Construct a new instance of class
251 <code>org.apache.catalina.realm.GenericPrincipal</code> (if not
252 already using this as the internal database representation) that
253 contains the authenticated username and a <code>List</code> of the
254 security roles associated with this user.</li>
255 <li>Return the newly constructed <code>GenericPrincipal</code>.</li>
256 </ul>
257
258
259 <h3>Method hasRole() Functionality</h3>
260
261 <p>When <code>hasRole()</code> is called, the following processing
262 is required:</p>
263 <ul>
264 <li>The <code>principal</code> that is passed as an argument SHOULD
265 be one that we returned (instanceof class
266 <code>org.apache.catalina.realm.GenericPrincipal</code>, with a
267 <code>realm</code> property that is equal to our instance.</li>
268 <li>If the passed <code>principal</code> meets these criteria, check
269 the specified role against the list returned by
270 <code>getRoles()</code>, and return <code>true</code> if the
271 specified role is included; otherwise, return <code>false</code>.</li>
272 <li>If the passed <code>principal</code> does not meet these criteria,
273 return <code>false</code>.</li>
274 </ul>
275
276 </blockquote></td></tr></table>
277
278</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Testable Assertions"><!--()--></a><a name="Testable_Assertions"><strong>Testable Assertions</strong></a></font></td></tr><tr><td><blockquote>
279
刘洪青6266f992017-05-15 21:21:03 +0800280 <p>In addition to the assertions implied by the functionality requirements
Hongqing Liufd5ee812014-05-10 16:32:51 +0800281 listed above, the following additional assertions shall be tested to
282 validate the behavior of <code>MemoryRealm</code>:</p>
283 <ul>
284 </ul>
285
刘洪青6266f992017-05-15 21:21:03 +0800286</blockquote></td></tr></table></td></tr><tr class="noPrint"><td width="20%" valign="top" nowrap class="noPrint"></td><td width="80%" valign="top" align="left"><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="comments_section" id="comments_section"><strong>Comments</strong></a></font></td></tr><tr><td><blockquote><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
287 on improving documentation for Apache Tomcat.<br><br>
288 If you have trouble and need help, read
289 <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
290 and ask your question on the tomcat-users
291 <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
292 Do not ask such questions here. This is not a Q&amp;A section.<br><br>
293 The Apache Comments System is explained <a href="../comments.html">here</a>.
294 Comments may be removed by our moderators if they are either
295 implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
296 var comments_shortname = 'tomcat';
297 var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/funcspecs/fs-memory-realm.html';
298 (function(w, d) {
299 if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
300 d.write('<div id="comments_thread"><\/div>');
301 var s = d.createElement('script');
302 s.type = 'text/javascript';
303 s.async = true;
304 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
305 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
306 }
307 else {
308 d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
309 }
310 })(window, document);
311 //--><!]]></script></blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
312 Copyright &copy; 1999-2017, Apache Software Foundation
Hongqing Liufd5ee812014-05-10 16:32:51 +0800313 </em></font></div></td></tr></table></body></html>