刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Catalina Functional Specifications (7.0.77) - JDBCRealm</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">
|
| 5 | code {background-color:rgb(224,255,255);padding:0 0.1em;}
|
| 6 | code.attributeName, code.propertyName {background-color:transparent;}
|
| 7 |
|
| 8 |
|
| 9 | table {
|
| 10 | border-collapse: collapse;
|
| 11 | text-align: left;
|
| 12 | }
|
| 13 | table *:not(table) {
|
| 14 | /* Prevent border-collapsing for table child elements like <div> */
|
| 15 | border-collapse: separate;
|
| 16 | }
|
| 17 |
|
| 18 | th {
|
| 19 | text-align: left;
|
| 20 | }
|
| 21 |
|
| 22 |
|
| 23 | div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
|
| 24 | background-color: transparent;
|
| 25 | }
|
| 26 | div.codeBox {
|
| 27 | overflow: auto;
|
| 28 | margin: 1em 0;
|
| 29 | }
|
| 30 | div.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 |
|
| 45 | div.codeBox pre.wrap {
|
| 46 | white-space: pre-wrap;
|
| 47 | }
|
| 48 |
|
| 49 |
|
| 50 | table.defaultTable tr, table.detail-table tr {
|
| 51 | border: 1px solid #CCC;
|
| 52 | }
|
| 53 |
|
| 54 | table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
|
| 55 | background-color: #FAFBFF;
|
| 56 | }
|
| 57 |
|
| 58 | table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
|
| 59 | background-color: #EEEFFF;
|
| 60 | }
|
| 61 |
|
| 62 | table.defaultTable th, table.detail-table th {
|
| 63 | background-color: #88b;
|
| 64 | color: #fff;
|
| 65 | }
|
| 66 |
|
| 67 | table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
|
| 68 | padding: 5px 8px;
|
| 69 | }
|
| 70 |
|
| 71 |
|
| 72 | p.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 Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 80 | Catalina Functional Specifications
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 81 | " 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>JDBCRealm</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 Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 82 | <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>JDBCRealm</strong> implementation is to
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 89 | provide a mechanism by which Tomcat can acquire information needed
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 90 | to authenticate web application users, and define their security roles,
|
| 91 | from a relational database accessed via JDBC APIs. For integration
|
| 92 | with Catalina, the resulting class(es) must implement the
|
| 93 | <code>org.apache.catalina.Realm</code> interface.</p>
|
| 94 |
|
| 95 | <p>This specification reflects a combination of functionality that is
|
| 96 | already present in the <code>org.apache.catalina.realm.JDBCRealm</code>
|
| 97 | class, as well as requirements for enhancements that have been
|
| 98 | discussed. Where appropriate, requirements statements are marked
|
| 99 | <em>[Current]</em> and <em>[Requested]</em> to distinguish them.</p>
|
| 100 |
|
| 101 | <p>The current status of this functional specification is
|
| 102 | <strong>PROPOSED</strong>. It has not yet been discussed and
|
| 103 | agreed to on the TOMCAT-DEV mailing list.</p>
|
| 104 |
|
| 105 | </blockquote></td></tr></table>
|
| 106 |
|
| 107 |
|
| 108 | <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>
|
| 109 |
|
| 110 | <p>The implementation of this functionality depends on the following
|
| 111 | external specifications:</p>
|
| 112 | <ul>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 113 | <li><a href="http://www.oracle.com/technetwork/java/javase/jdbc/index.html">
|
| 114 | Java Database Connectivity</a> (version 2.0 or later)</li>
|
| 115 | <li><a href="http://www.oracle.com/technetwork/java/javase/jdbc/index.html">
|
| 116 | Java Database Connectivity Optional Package</a> (version 2.0 or later)</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 117 | </ul>
|
| 118 |
|
| 119 | </blockquote></td></tr></table>
|
| 120 |
|
| 121 |
|
| 122 | <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>
|
| 123 |
|
| 124 | <p>The implementation of this functionality shall conform to the
|
| 125 | following requirements:</p>
|
| 126 | <ul>
|
| 127 | <li>Be realized in one or more implementation classes.</li>
|
| 128 | <li>Implement the <code>org.apache.catalina.Realm</code> interface.
|
| 129 | [Current]</li>
|
| 130 | <li>Implement the <code>org.apache.catalina.Lifecycle</code>
|
| 131 | interface. [Current]</li>
|
| 132 | <li>Subclass the <code>org.apache.catalina.realm.RealmBase</code>
|
| 133 | base class.</li>
|
| 134 | <li>Live in the <code>org.apache.catalina.realm</code> package.
|
| 135 | [Current]</li>
|
| 136 | <li>Support a configurable debugging detail level. [Current]</li>
|
| 137 | <li>Log debugging and operational messages (suitably internationalized)
|
| 138 | via the <code>getContainer().log()</code> method. [Current]</li>
|
| 139 | </ul>
|
| 140 |
|
| 141 | </blockquote></td></tr></table>
|
| 142 |
|
| 143 |
|
| 144 | </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>
|
| 145 |
|
| 146 |
|
| 147 | <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>
|
| 148 |
|
| 149 | <p>The following environmental dependencies must be met in order for
|
| 150 | JDBCRealm to operate correctly:</p>
|
| 151 | <ul>
|
| 152 | <li>The desire to utilize JDBCRealm must be registered in
|
| 153 | <code>$CATALINA_BASE/conf/server.xml</code>, in a
|
| 154 | <code><Realm></code> element that is nested inside a
|
| 155 | corresponding <code><Engine></code>, <code><Host></code>,
|
| 156 | or <code><Context></code> element.</li>
|
| 157 | </ul>
|
| 158 |
|
| 159 | </blockquote></td></tr></table>
|
| 160 |
|
| 161 |
|
| 162 | <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>
|
| 163 |
|
| 164 | <p>Correct operation of JDBCRealm depends on the following
|
| 165 | specific features of the surrounding container:</p>
|
| 166 | <ul>
|
| 167 | <li>Interactions with <code>JDBCRealm</code> will be initiated by
|
| 168 | the appropriate <code>Authenticator</code> implementation, based
|
| 169 | on the login method that is selected.</li>
|
| 170 | <li><code>JDBCRealm</code> must have the JDBC standard API classes
|
| 171 | available to it. For a JDK 1.2 or later container, these APIs
|
| 172 | are included in the standard platform.</li>
|
| 173 | <li>When connection pooling is implemented, <code>JDBCRealm</code>
|
| 174 | must have the JDBC Optional Package (version 2.0 or later) APIs
|
| 175 | available to it. This library is available as a separate
|
| 176 | download (and will be included in Tomcat binary distributions).</li>
|
| 177 | </ul>
|
| 178 |
|
| 179 | </blockquote></td></tr></table>
|
| 180 |
|
| 181 |
|
| 182 | </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>
|
| 183 |
|
| 184 |
|
| 185 | <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>
|
| 186 |
|
| 187 | <p>The main purpose of <code>JDBCRealm</code> is to allow Catalina to
|
| 188 | authenticate users, and look up the corresponding security roles, from
|
| 189 | the information found in a relational database accessed via JDBC APIs.
|
| 190 | For maximum flexibility, the details of how this is done (for example,
|
| 191 | the names of the required tables and columns) should be configurable.</p>
|
| 192 |
|
| 193 | <p>Each time that Catalina needs to authenticate a user, it will call
|
| 194 | the <code>authenticate()</code> method of this Realm implementation,
|
| 195 | passing the username and password that were specified by the user. If
|
| 196 | we find the user in the database (and match on the password), we accumulate
|
| 197 | all of the security roles that are defined for this user, and create a
|
| 198 | new <code>GenericPrincipal</code> object to be returned. If the user
|
| 199 | is not authenticated, we return <code>null</code> instead. The
|
| 200 | <code>GenericUser</code> object caches the set of security roles that
|
| 201 | were owned by this user at the time of authentication, so that calls to
|
| 202 | <code>isUserInRole()</code> can be answered without going back to the
|
| 203 | database every time.</p>
|
| 204 |
|
| 205 | </blockquote></td></tr></table>
|
| 206 |
|
| 207 |
|
| 208 | <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>
|
| 209 |
|
| 210 |
|
| 211 | <h3>Configurable Properties</h3>
|
| 212 |
|
| 213 | <p>The implementation shall support the following properties
|
| 214 | that can be configured with JavaBeans property setters:</p>
|
| 215 | <ul>
|
| 216 | <li>Configuration parameters defining the JDBC driver to use, the
|
| 217 | database connection URL to be accessed, and the username/password
|
| 218 | to use for logging in. [Current]</li>
|
| 219 | <li>Configuration parameters describing the connection pool to be
|
| 220 | created to support simultaneous authentications. [Requested]</li>
|
| 221 | <li>Name of the tables to be searched for users and roles. [Current]</li>
|
| 222 | <li>Name of the columns to be used for usernames, passwords, and
|
| 223 | role names. [Current]</li>
|
| 224 | </ul>
|
| 225 |
|
| 226 | <h3>Lifecycle Functionality</h3>
|
| 227 |
|
| 228 | <p>The following processing must be performed when the <code>start()</code>
|
| 229 | method is called:</p>
|
| 230 | <ul>
|
| 231 | <li>Establish a connection to the configured database, using the
|
| 232 | configured username and password. [Current]</li>
|
| 233 | <li>Configure and establish a connection pool of connections to the
|
| 234 | database. [Requested]</li>
|
| 235 | </ul>
|
| 236 |
|
| 237 | <p>The following processing must be performed when the <code>stop()</code>
|
| 238 | method is called:</p>
|
| 239 | <ul>
|
| 240 | <li>Close any opened connections to the database.</li>
|
| 241 | </ul>
|
| 242 |
|
| 243 |
|
| 244 | <h3>Method authenticate() Functionality</h3>
|
| 245 |
|
| 246 | <p>When <code>authenticate()</code> is called, the following processing
|
| 247 | is required:</p>
|
| 248 | <ul>
|
| 249 | <li>Acquire the one and only connection [Current] or acquire a connection
|
| 250 | from the connection pool [Requested].</li>
|
| 251 | <li>Select the one and only row from the user's table for this user,
|
| 252 | and retrieve the corresponding password column. If zero rows (or
|
| 253 | more than one row) are found, return <code>null</code>.</li>
|
| 254 | <li>Authenticate the user by comparing the (possibly encrypted) password
|
| 255 | value that was received against the password presented by the user.
|
| 256 | If there is no match, return <code>null</code>.</li>
|
| 257 | <li>Acquire a <code>List</code> of the security roles assigned to the
|
| 258 | authenticated user by selecting from the roles table.</li>
|
| 259 | <li>Construct a new instance of class
|
| 260 | <code>org.apache.catalina.realm.GenericPrincipal</code>, passing as
|
| 261 | constructor arguments: this realm instance, the authenticated
|
| 262 | username, and a <code>List</code> of the security roles associated
|
| 263 | with this user.</li>
|
| 264 | <li><strong>WARNING</strong> - Do not attempt to cache and reuse previous
|
| 265 | <code>GenericPrincipal</code> objects for a particular user, because
|
| 266 | the information in the directory server might have changed since the
|
| 267 | last time this user was authenticated.</li>
|
| 268 | <li>Return the newly constructed <code>GenericPrincipal</code>.</li>
|
| 269 | </ul>
|
| 270 |
|
| 271 |
|
| 272 | <h3>Method hasRole() Functionality</h3>
|
| 273 |
|
| 274 | <p>When <code>hasRole()</code> is called, the following processing
|
| 275 | is required:</p>
|
| 276 | <ul>
|
| 277 | <li>The <code>principal</code> that is passed as an argument SHOULD
|
| 278 | be one that we returned (instanceof class
|
| 279 | <code>org.apache.catalina.realm.GenericPrincipal</code>, with a
|
| 280 | <code>realm</code> property that is equal to our instance.</li>
|
| 281 | <li>If the passed <code>principal</code> meets these criteria, check
|
| 282 | the specified role against the list returned by
|
| 283 | <code>getRoles()</code>, and return <code>true</code> if the
|
| 284 | specified role is included; otherwise, return <code>false</code>.</li>
|
| 285 | <li>If the passed <code>principal</code> does not meet these criteria,
|
| 286 | return <code>false</code>.</li>
|
| 287 | </ul>
|
| 288 |
|
| 289 | </blockquote></td></tr></table>
|
| 290 |
|
| 291 | </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>
|
| 292 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 293 | <p>In addition to the assertions implied by the functionality requirements
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 294 | listed above, the following additional assertions shall be tested to
|
| 295 | validate the behavior of <code>JDBCRealm</code>:</p>
|
| 296 | <ul>
|
| 297 | </ul>
|
| 298 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 299 | </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
|
| 300 | on improving documentation for Apache Tomcat.<br><br>
|
| 301 | If you have trouble and need help, read
|
| 302 | <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
|
| 303 | and ask your question on the tomcat-users
|
| 304 | <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
|
| 305 | Do not ask such questions here. This is not a Q&A section.<br><br>
|
| 306 | The Apache Comments System is explained <a href="../comments.html">here</a>.
|
| 307 | Comments may be removed by our moderators if they are either
|
| 308 | implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
|
| 309 | var comments_shortname = 'tomcat';
|
| 310 | var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/funcspecs/fs-jdbc-realm.html';
|
| 311 | (function(w, d) {
|
| 312 | if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
|
| 313 | d.write('<div id="comments_thread"><\/div>');
|
| 314 | var s = d.createElement('script');
|
| 315 | s.type = 'text/javascript';
|
| 316 | s.async = true;
|
| 317 | s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
|
| 318 | (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
|
| 319 | }
|
| 320 | else {
|
| 321 | d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
|
| 322 | }
|
| 323 | })(window, document);
|
| 324 | //--><!]]></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>
|
| 325 | Copyright © 1999-2017, Apache Software Foundation
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 326 | </em></font></div></td></tr></table></body></html> |