リンク ユーザガイド リファレンス Tomcat開発 | Tomcat5 サーブレット/JSP コンテナRealm Configuration HOW-TOレルム設定方法 |  印刷用 バージョン
|
| Quick Start |
This document describes how to configure Tomcat to support container
managed security, by connecting to an existing "database" of usernames,
passwords, and user roles. You only need to care about this if you are using
a web application that includes one or more
<security-constraint> elements, and a
<login-config> element defining how users are required
to authenticate themselves. If you are not utilizing these features, you can
safely skip this document.
For fundamental background information about container managed security,
see the Servlet
Specification (Version 2.3), Section 12. For a more introductory level
document for web application developers as well as administrators, see
( FIXME - link to backgrounder on container managed security
to be provided).
For information about utilizing the Single Sign On feature of
Tomcat 5 (allowing a user to authenticate themselves once across the entire
set of web applications associated with a virtual host), see
here.
|
| クイックスタート |
この文書は、ユーザ名、パスワード、ユーザロールが登録されている"データベース"へ接続して動作する、
Tomcatにおけるコンテナ管理のセキュリティを利用するための設定方法について説明しています。
<security-constraint> 要素や<login-config> 要素といった、
ユーザがどのように認証されるかを設定する要素を1つ以上含むWebアプリケーションを使う方だけが気をつけて読んで下さい。
これらの機能を利用しないのであれば、この文書を読み飛ばしても大丈夫です。
コンテナ管理のセキュリティに関する基本的な情報については、
Servlet 仕様書(バージョン2.3)
の第12節を参照してください。
管理者やWebアプリケーション開発者のための入門レベルの文書は、
(未解決 -コンテナ管理のセキュリティに関する情報へのリンクを提供すること)
を参照してください。
Tomcat 5 における統一ログイン[Single Sign On]
(バーチャルホスト内で連携するWebアプリケーション全体を一度の認証でユーザが利用できるようになる)機能の使用方法に関する情報については、
こちらを参照してください。
|
| Overview |
| What is a Realm? |
A Realm is a "database" of usernames and passwords that
identify valid users of a web application (or set of web applications), plus
an enumeration of the list of roles associated with each valid user.
You can think of roles as similar to groups in Unix-like operating
systems, because access to specific web application resources is granted to
all users possessing a particular role (rather than enumerating the list of
associated usernames). A particular user can have any number of roles
associated with their username.
Although the Servlet Specification describes a portable mechanism for
applications to declare their security requirements (in the
web.xml deployment descriptor), there is no portable API
defining the interface between a servlet container and the associated user
and role information. In many cases, however, it is desireable to "connect"
a servlet container to some existing authentication database or mechanism
that already exists in the production environment. Therefore, Tomcat 5
defines a Java interface (org.apache.catalina.Realm) that
can be implemented by "plug in" components to establish this connection.
Three standard plug-ins are provided, supporting connection to three different
sources of authentication information:
- DataSourceRealm - Accesses authentication
information stored in a relational database, accessed via a named JNDI
JDBC DataSource.
- JDBCRealm - Accesses authentication information
stored in a relational database, accessed via a JDBC driver.
- JNDIRealm - Accesses authentication information
stored in an LDAP based directory server, accessed via a JNDI provider.
- MemoryRealm - Accesses authentication
information stored in an in-memory object collection, which is initialized
from an XML document (
conf/tomcat-users.xml).
It is also possible to write your own Realm implementation,
and integrate it with Tomcat 5. However, doing this is beyond the scope of
this document. See (FIXME - reference to developer stuff)
for more information.
|
|
| 概要 |
| レルムとは? |
レルムとは、ユーザ名とパスワードの組み合わせのように、
Webアプリケーション(複数のWebアプリケーションのまとまりの場合もあります)
のユーザを一意に定めるための"データベース"と、
認証された各ユーザに付与されているロールの一覧を列挙するものの両方を合わせたものを指します。
ロールは、Unix系のオペレーティングシステムにおけるグループ
のようなものだと考えてもらってもいいでしょう。
特定のWebアプリケーションリソースへのアクセスは、
(リソースへ関連づけられたユーザ名の一覧を列挙することによってではなく)
ある特別なロールを持つユーザ全員に与えられます。
場合によってユーザは、ユーザ名に紐付くロールをいくつでも持つことができます。
(web.xml、つまり配備記述子に)
セキュリティ要件を宣言することによるアプリケーションのための可搬性の高い機構をサーブレット仕様書では説明していますが、
サーブレットコンテナと関連付けられたユーザとロール情報との間のインタフェースを定義する可搬性の高いAPIはありません。
しかしながら多くの場合、認証用データベースまたは製品環境に付属する認証機構とサーブレットコンテナとの"接続"が必要となります。
そのためTomcat 5では、Javaのインタフェース(org.apache.catalina.Realm)を定義しています。
このインタフェースは、こういった接続を確立するための"プラグイン"コンポーネントに実装されれば良く、
異なる認証情報ソースへの接続をサポートする以下の4つの標準プラグインが現在提供されています:
- DataSourceRealm -
リレーショナルデータベースに保存されている認証情報へアクセスします。
名前付けされた JNDI JDBCデータソースを使ってアクセスします。
- JDBCRealm -
リレーショナルデータベースに保存されている認証情報へアクセスします。
JDBCドライバを使ってアクセスします。
- JNDIRealm -
LDAPベースのディレクトリサーバに保存されている認証情報へアクセスします。
JNDIプロバイダを使ってアクセスします。
- MemoryRealm -
メモリ内のオブジェクト集合に保存されている認証情報へアクセスします。
このオブジェクト集合は、XML文書ファイル (
conf/tomcat-users.xml)を使って初期化されます。
もちろん、開発者は独自にRealm を実装することができますし、
それをTomcat 5 と統合することもできます。
しかしながらその方法を説明することはこの文書の範疇を越えています。
詳細については、(未解決 - 開発スタッフ用リファレンス)を参照してください。
|
|
| Standard Realm Implementations |
| JDBCRealm |
Introduction
JDBCRealm is an implementation of the Tomcat 5
Realm interface that looks up users in a relational database
accessed via a JDBC driver. There is substantial configuration flexibility
that lets you adapt to existing table and column names, as long as your
database structure conforms to the following requirements:
- There must be a table, referenced below as the users table,
that contains one row for every valid user that this
Realm
should recognize.
- The users table must contain at least two columns (it may
contain more if your existing applications required it):
- Username to be recognized by Tomcat when the user logs in.
- Password to be recognized by Tomcat when the user logs in.
This value may in cleartext or digested - see below for more
information.
- There must be a table, referenced below as the user roles table,
that contains one row for every valid role that is assigned to a
particular user. It is legal for a user to have zero, one, or more than
one valid role.
- The user roles table must contain at least two columns (it may
contain more if your existing applications required it):
- Username to be recognized by Tomcat (same value as is specified
in the users table).
- Role name of a valid role associated with this user.
Quick Start
To set up Tomcat to use JDBCRealm, you will need to follow these steps:
- If you have not yet done so, create tables and columns in your database
that conform to the requirements described above.
- Configure a database username and password for use by Tomcat, that has
at least read only access to the tables described above. (Tomcat will
never attempt to write to these tables.)
- Place a copy of the JDBC driver you will be using inside the
$CATALINA_HOME/server/lib directory (if you do not need it
visible to web applications) or $CATALINA_HOME/common/lib
(if it will be used both by Tomcat 5 and by your apps).
Note that only JAR files are recognized!
- Set up a
<Realm> element, as described below, in your
$CATALINA_HOME/conf/server.xml file.
- Restart Tomcat 5 if it is already running.
Realm Element Attributes
To configure JDBCRealm, you will create a <Realm>
element and nest it in your $CATALINA_HOME/conf/server.xml file,
as described above. The following
attributes are supported by this implementation:
| Attribute | Description |
|---|
className |
The fully qualified Java class name of this Realm implementation.
You MUST specify the value
"org.apache.catalina.realm.JDBCRealm" here.
| connectionName |
The database username used to establish a JDBC connection.
| connectionPassword |
The database password used to establish a JDBC connection.
| connectionURL |
The database URL used to establish a JDBC connection.
| debug |
The level of debugging detail logged by this Realm
to the associated Logger. Higher numbers
generate more detailed output. If not specified, the default
debugging detail level is zero (0).
| digest |
The digest algorithm used to store passwords in non-plaintext formats.
Valid values are those accepted for the algorithm name by the
java.security.MessageDigest class. See
Digested Passwords for more
information. If not specified, passwords are stored in clear text.
| driverName |
The fully qualified Java class name of the JDBC driver to be used.
Consult the documentation for your JDBC driver for the appropriate
value.
| roleNameCol |
The name of the column, in the user roles table, that
contains the name of a role assigned to this user.
| userCredCol |
The name of the column, in the users table, that contains
the password for this user (either in clear text, or digested if the
digest attribute is set).
| userNameCol |
The name of the column, in the users and user roles
tables, that contains the username of this user.
| userRoleTable |
The name of the table that contains one row for each role
assigned to a particular username. This table must include at
least the columns named by the userNameCol and
roleNameCol attributes.
| userTable |
The name of the table that contains one row for each username
to be recognized by Tomcat. This table must include at least the columns
named by the userNameCol and userCredCol
attributes.
|
Example
An example SQL script to create the needed tables might look something
like this (adapt the syntax as required for your particular database):
 |  |  |  |
create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);
create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);
|  |  |  |  |
Example Realm elements are included (commented out) in the
default $CATALINA_HOME/conf/server.xml file. Here's an example
for using a MySQL database called "authority", configured with the tables
described above, and accessed with username "dbuser" and password "dbpass":
 |  |  |  |
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority?user=dbuser&password=dbpass"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/>
|  |  |  |  |
Additional Notes
JDBCRealm operates according to the following rules:
- When a user attempts to access a protected resource for the first time,
Tomcat 5 will call the
authenticate() method of this
Realm. Thus, any changes you have made to the database
directly (new users, changed passwords or roles, etc.) will be immediately
reflected.
- Once a user has been authenticated, the user (and his or her associated
roles) are cached within Tomcat for the duration of the user's login.
(For FORM-based authentication, that means until the session times out or
is invalidated; for BASIC authentication, that means until the user
closes their browser). Any changes to the database information for an
already authenticated user will not be reflected until
the next time that user logs on again.
- Administering the information in the users and user roles
table is the responsibility of your own applications. Tomcat does not
provide any built-in capabilities to maintain users and roles.
- Debugging and exception messages logged by this
Realm will
be recorded by the Logger that is associated with our
surrounding Context, Host, or
Engine. By default, the corresponding Logger will create a
log file in the $CATALINA_HOME/logs directory.
|
| DataSourceRealm |
Introduction
DataSourceRealm is an implementation of the Tomcat 4
Realm interface that looks up users in a relational database
accessed via a JNDI named JDBC DataSource. There is substantial configuration
flexibility that lets you adapt to existing table and column names, as long
as your database structure conforms to the following requirements:
- There must be a table, referenced below as the users table,
that contains one row for every valid user that this
Realm
should recognize.
- The users table must contain at least two columns (it may
contain more if your existing applications required it):
- Username to be recognized by Tomcat when the user logs in.
- Password to be recognized by Tomcat when the user logs in.
This value may in cleartext or digested - see below for more
information.
- There must be a table, referenced below as the user roles table,
that contains one row for every valid role that is assigned to a
particular user. It is legal for a user to have zero, one, or more than
one valid role.
- The user roles table must contain at least two columns (it may
contain more if your existing applications required it):
- Username to be recognized by Tomcat (same value as is specified
in the users table).
- Role name of a valid role associated with this user.
Quick Start
To set up Tomcat to use DataSourceRealm, you will need to follow these steps:
- If you have not yet done so, create tables and columns in your database
that conform to the requirements described above.
- Configure a database username and password for use by Tomcat, that has
at least read only access to the tables described above. (Tomcat will
never attempt to write to these tables.)
- Configure a JNDI named JDBC DataSource for your database. Refer to the
JNDI DataSource Example HOW-TO
for information on how to configure a JNDI named JDBC DataSource.
- Set up a
<Realm> element, as described below, in your
$CATALINA_HOME/conf/server.xml file.
- Restart Tomcat 4 if it is already running.
Realm Element Attributes
To configure DataSourceRealm, you will create a <Realm>
element and nest it in your $CATALINA_HOME/conf/server.xml file,
as described above. The following
attributes are supported by this implementation:
| Attribute | Description |
|---|
className |
The fully qualified Java class name of this Realm implementation.
You MUST specify the value
"org.apache.catalina.realm.DataSourceRealm" here.
| dataSourceName |
The JNDI named JDBC DataSource for your database.
| debug |
The level of debugging detail logged by this Realm
to the associated Logger. Higher numbers
generate more detailed output. If not specified, the default
debugging detail level is zero (0).
| digest |
The digest algorithm used to store passwords in non-plaintext formats.
Valid values are those accepted for the algorithm name by the
java.security.MessageDigest class. See
Digested Passwords for more
information. If not specified, passwords are stored in clear text.
| roleNameCol |
The name of the column, in the user roles table, that
contains the name of a role assigned to this user.
| userCredCol |
The name of the column, in the users table, that contains
the password for this user (either in clear text, or digested if the
digest attribute is set).
| userNameCol |
The name of the column, in the users and user roles
tables, that contains the username of this user.
| userRoleTable |
The name of the table that contains one row for each role
assigned to a particular username. This table must include at
least the columns named by the userNameCol and
roleNameCol attributes.
| userTable |
The name of the table that contains one row for each username
to be recognized by Tomcat. This table must include at least the columns
named by the userNameCol and userCredCol
attributes.
|
Example
An example SQL script to create the needed tables might look something
like this (adapt the syntax as required for your particular database):
 |  |  |  |
create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);
create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);
|  |  |  |  |
Here is an example for using a MySQL database called "authority", configured
with the tables described above, and accessed with the JNDI JDBC DataSource with
name "java:/comp/env/jdbc/authority".
 |  |  |  |
<Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"
dataSourceName="java:/comp/env/jdbc/authority"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/>
|  |  |  |  |
Additional Notes
DataSourceRealm operates according to the following rules:
- When a user attempts to access a protected resource for the first time,
Tomcat 4 will call the
authenticate() method of this
Realm. Thus, any changes you have made to the database
directly (new users, changed passwords or roles, etc.) will be immediately
reflected.
- Once a user has been authenticated, the user (and his or her associated
roles) are cached within Tomcat for the duration of the user's login.
(For FORM-based authentication, that means until the session times out or
is invalidated; for BASIC authentication, that means until the user
closes their browser). Any changes to the database information for an
already authenticated user will not be reflected until
the next time that user logs on again.
- Administering the information in the users and user roles
table is the responsibility of your own applications. Tomcat does not
provide any built-in capabilities to maintain users and roles.
- Debugging and exception messages logged by this
Realm will
be recorded by the Logger that is associated with our
surrounding Context, Host, or
Engine. By default, the corresponding Logger will create a
log file in the $CATALINA_HOME/logs directory.
|
| JNDIRealm |
Introduction
JNDIRealm is an implementation of the Tomcat 5
Realm interface that looks up users in an LDAP directory
server accessed by a JNDI provider (typically, the standard LDAP
provider that is available with the JNDI API classes). The realm
supports a variety of approaches to using a directory for
authentication.
Connecting to the directory
The realm's connection to the directory is defined by the
connectionURL configuration attribute. This is a URL
whose format is defined by the JNDI provider. It is usually an LDAP
URL that specifies the domain name of the directory server to connect
to, and optionally the port number and distinguished name (DN) of the
required root naming context.
If you have more than one provider you can configure an
alternateURL. If a socket connection can not be
made to the provider at the connectionURL an
attempt will be made to use the alternateURL.
When making a connection in order to search the directory and
retrieve user and role information, the realm authenticates itself to
the directory with the username and password specified by the
connectionName and
connectionPassword properties. If these properties
are not specified the connection is anonymous. This is sufficient in
many cases.
Selecting the user's directory entry
Each user that can be authenticated must be represented in the
directory by an individual entry that corresponds to an element in the
initial DirContext defined by the
connectionURL attribute. This user entry must have an
attribute containing the username that is presented for
authentication.
Often the distinguished name of the user's entry contains the
username presented for authentication but is otherwise the same for
all users. In this case the userPattern attribute may
be used to specify the DN, with "{0}" marking where
the username should be substituted.
Otherwise the realm must search the directory to find a unique entry
containing the username. The following attributes configure this
search:
- userBase - the entry that is the base of
the subtree containing users. If not specified, the search
base is the top-level context.
- userSubtree - the search scope. Set to
true if you wish to search the entire subtree
rooted at the userBase entry. The default value
of false requests a single-level search
including only the top level.
- userSearch - pattern specifying the LDAP
search filter to use after substitution of the username.
Authenticating the user
-
Bind mode
By default the realm authenticates a user by binding to
the directory with the DN of the entry for that user and the password
presented by the user. If this simple bind succeeds the user is considered to
be authenticated.
For security reasons a directory may store a digest of the user's
password rather than the clear text version (see Digested Passwords for more information). In that case,
as part of the simple bind operation the directory automatically
computes the correct digest of the plaintext password presented by the
user before validating it against the stored value. In bind mode,
therefore, the realm is not involved in digest processing. The
digest attribute is not used, and will be ignored if
set.
-
Comparison mode
Alternatively, the realm may retrieve the stored
password from the directory and compare it explicitly with the value
presented by the user. This mode is configured by setting the
userPassword attribute to the name of a directory
attribute in the user's entry that contains the password.
Comparison mode has some disadvantages. First, the
connectionName and
connectionPassword attributes must be configured to
allow the realm to read users' passwords in the directory. For
security reasons this is generally undesirable; indeed many directory
implementations will not allow even the directory manager to read
these passwords. In addition, the realm must handle password digests
itself, including variations in the algorithms used and ways of
representing password hashes in the directory. However, the realm may
sometimes need access to the stored password, for example to support
HTTP Digest Access Authentication (RFC 2069). (Note that HTTP digest
authentication is different from the storage of password digests in
the repository for user information as discussed above).
Assigning roles to the user
The directory realm supports two approaches to the representation
of roles in the directory:
-
Roles as explicit directory entries
Roles may be represented by explicit directory entries. A role
entry is usually an LDAP group entry with one attribute
containing the name of the role and another whose values are the
distinguished names or usernames of the users in that role. The
following attributes configure a directory search to
find the names of roles associated with the authenticated user:
- roleBase - the base entry for the role search.
If not specified, the search base is the top-level directory
context.
- roleSubtree - the search
scope. Set to
true if you wish to search the entire
subtree rooted at the roleBase entry. The default
value of false requests a single-level search
including the top level only.
- roleSearch - the LDAP search filter for
selecting role entries. It optionally includes pattern
replacements "{0}" for the distinguished name and/or "{1}" for the
username of the authenticated user.
- roleName - the attribute in a role entry
containing the name of that role.
A combination of both approaches to role representation may be used.
Quick Start
To set up Tomcat to use JNDIRealm, you will need to follow these steps:
- Make sure your directory server is configured with a schema that matches
the requirements listed above.
- If required, configure a username and password for use by Tomcat, that has
read only access to the information described above. (Tomcat will
never attempt to modify this information.)
- Place a copy of the JNDI driver you will be using (typically
ldap.jar available with JNDI) inside the
$CATALINA_HOME/server/lib directory (if you do not need it
visible to web applications) or $CATALINA_HOME/common/lib
(if it will be used both by Tomcat 5 and by your apps).
- Set up a
<Realm> element, as described below, in your
$CATALINA_HOME/conf/server.xml file.
- Restart Tomcat 5 if it is already running.
Realm Element Attributes
To configure JNDIRealm, you will create a <Realm>
element and nest it in your $CATALINA_HOME/conf/server.xml file,
as described above. The following
attributes are supported by this implementation:
| Attribute | Description |
|---|
className |
The fully qualified Java class name of this Realm implementation.
You MUST specify the value
"org.apache.catalina.realm.JNDIRealm" here.
| connectionName |
The directory username to use when establishing a
connection to the directory for LDAP search operations. If not
specified an anonymous connection is made, which is often
sufficient unless you specify the userPassword
property.
| connectionPassword |
The directory password to use when establishing a
connection to the directory for LDAP search operations. If not
specified an anonymous connection is made, which is often
sufficient unless you specify the userPassword
property.
| connectionURL |
The connection URL to be passed to the JNDI driver when
establishing a connection to the directory.
| contextFactory |
The fully qualified Java class name of the JNDI context
factory to be used for this connection. By default, the standard
JNDI LDAP provider is used
(com.sun.jndi.ldap.LdapCtxFactory).
| debug |
The level of debugging detail logged by this Realm to the
associated Logger. Higher
numbers generate more detailed output. If not specified, the
default debugging detail level is zero (0).
| digest |
The digest algorithm to apply to the plaintext password offered
by the user before comparing it with the value retrieved from the
directory. Valid values are those accepted for the algorithm name
by the java.security.MessageDigest class. See Digested Passwords for more
information. If not specified the plaintext password is assumed to
be retrieved. Not required unless userPassword is
specified
| roleBase |
The base directory entry for performing role searches. If
not specified, the top level element in the directory context
will be used.
| roleName |
The name of the attribute that contains role names in the
directory entries found by a role search. In addition you can
use the userRoleName property to specify the name
of an attribute, in the user's entry, containing additional
role names. If roleName is not specified a role
search does not take place, and roles are taken only from the
user's entry.
| roleSearch |
The LDAP filter expression used for performing role
searches, following the syntax supported by the
java.text.MessageFormat class. Use
{0} to substitute the distinguished name (DN) of
the user, and/or {1} to substitute the
username. If not specified a role search does not take place
and roles are taken only from the attribute in the user's
entry specified by the userRoleName property.
| roleSubtree |
Set to true if you want to search the entire
subtree of the element specified by the roleBase
property for role entries associated with the user. The
default value of false causes only the top level
to be searched.
| userBase |
The base element for user searches performed using the
userSearch expression. If not specified, the top
level element in the directory context will be used. Not used
if you are using the userPattern expression.
| userPassword |
Name of the attribute in the user's entry containing the
user's password. If you specify this value, JNDIRealm will
bind to the directory using the values specified by
connectionName and
connectionPassword properties, and retrieve the
corresponding attribute for comparison to the value specified
by the user being authenticated. If the digest
attribute is set, the specified digest algorithm is applied to
the password offered by the user before comparing it with the
value retrieved from the directory. If you do
not specify this value, JNDIRealm will
attempt a simple bind to the directory using the DN of the
user's entry and password specified by the user, with a
successful bind being interpreted as an authenticated
user.
| userPattern |
A pattern for the distinguished name (DN) of the user's
directory entry, following the syntax supported by the
java.text.MessageFormat class with
{0} marking where the actual username should be
inserted. You can use this property instead of
userSearch, userSubtree and
userBase when the distinguished name contains the
username and is otherwise the same for all users.
| userRoleName |
The name of an attribute in the user's directory entry
containing zero or more values for the names of roles assigned
to this user. In addition you can use the
roleName property to specify the name of an
attribute to be retrieved from individual role entries found
by searching the directory. If userRoleName is
not specified all the roles for a user derive from the role
search.
| userSearch |
The LDAP filter expression to use when searching for a
user's directory entry, with {0} marking where
the actual username should be inserted. Use this property
(along with the userBase and
userSubtree properties) instead of
userPattern to search the directory for the
user's entry.
| userSubtree |
Set to true if you want to search the entire
subtree of the element specified by the userBase
property for the user's entry. The default value of
false causes only the top level to be searched.
Not used if you are using the userPattern
expression.
|
Example
Creation of the appropriate schema in your directory server is beyond the
scope of this document, because it is unique to each directory server
implementation. In the examples below, we will assume that you are using a
distribution of the OpenLDAP directory server (version 2.0.11 or later), which
can be downloaded from
http://www.openldap.org. Assume that
your slapd.conf file contains the following settings
(among others):
 |  |  |  |
database ldbm
suffix dc="mycompany",dc="com"
rootdn "cn=Manager,dc=mycompany,dc=com"
rootpw secret
|  |  |  |  |
We will assume for connectionURL that the directory
server runs on the same machine as Tomcat. See http://java.sun.com/products/jndi/docs.html
for more information about configuring and using the JNDI LDAP
provider.
Next, assume that this directory server has been populated with elements
as shown below (in LDIF format):
 |  |  |  |
# Define top-level entry
dn: dc=mycompany,dc=com
objectClass: dcObject
dc:mycompany
# Define an entry to contain people
# searches for users are based on this entry
dn: ou=people,dc=mycompany,dc=com
objectClass: organizationalUnit
ou: people
# Define a user entry for Janet Jones
dn: uid=jjones,ou=people,dc=mycompany,dc=com
objectClass: inetOrgPerson
uid: jjones
sn: jones
cn: janet jones
mail: j.jones@mycompany.com
userPassword: janet
# Define a user entry for Fred Bloggs
dn: uid=fbloggs,ou=people,dc=mycompany,dc=com
objectClass: inetOrgPerson
uid: fbloggs
sn: bloggs
cn: fred bloggs
mail: f.bloggs@mycompany.com
userPassword: fred
# Define an entry to contain LDAP groups
# searches for roles are based on this entry
dn: ou=groups,dc=mycompany,dc=com
objectClass: organizationalUnit
ou: groups
# Define an entry for the "tomcat" role
dn: cn=tomcat,ou=groups,dc=mycompany,dc=com
objectClass: groupOfUniqueNames
cn: tomcat
uniqueMember: uid=jjones,ou=people,dc=mycompany,dc=com
uniqueMember: uid=fbloggs,ou=people,dc=mycompany,dc=com
# Define an entry for the "role1" role
dn: cn=role1,ou=groups,dc=mycompany,dc=com
objectClass: groupOfUniqueNames
cn: role1
uniqueMember: uid=fbloggs,ou=people,dc=mycompany,dc=com
|  |  |  |  |
An example Realm element for the OpenLDAP directory
server configured as described above might look like this, assuming
that users use their uid (e.g. jjones) to login to the
application and that an anonymous connection is sufficient to search
the directory and retrieve role information:
 |  |  |  |
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"
connectionURL="ldap://localhost:389"
userPattern="uid={0},ou=people,dc=mycompany,dc=com"
roleBase="ou=groups,dc=mycompany,dc=com"
roleName="cn"
roleSearch="(uniqueMember={0})"
/>
|  |  |  |  |
With this configuration, the realm will determine the user's
distinguished name by substituting the username into the
userPattern, authenticate by binding to the directory
with this DN and the password received from the user, and search the
directory to find the user's roles.
Now suppose that users are expected to enter their email address
rather than their userid when logging in. In this case the realm must
search the directory for the user's entry. (A search is also necessary
when user entries are held in multiple subtrees corresponding perhaps
to different organizational units or company locations).
Further, suppose that in addition to the group entries you want to
use an attribute of the user's entry to hold roles. Now the entry for
Janet Jones might read as follows:
 |  |  |  |
dn: uid=jjones,ou=people,dc=mycompany,dc=com
objectClass: inetOrgPerson
uid: jjones
sn: jones
cn: janet jones
mail: j.jones@mycompany.com
memberOf: role2
memberOf: role3
userPassword: janet
|  |  |  |  |
This realm configuration would satisfy the new requirements:
 |  |  |  |
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"
connectionURL="ldap://localhost:389"
userBase="ou=people,dc=mycompany,dc=com"
userSearch="(mail={0})"
userRoleName="memberOf"
roleBase="ou=groups,dc=mycompany,dc=com"
roleName="cn"
roleSearch="(uniqueMember={0})"
/>
|  |  |  |  |
Now when Janet Jones logs in as "j.jones@mycompany.com", the realm
searches the directory for a unique entry with that value as its mail
attribute and attempts to bind to the directory as
uid=jjones,ou=people,dc=mycompany,dc=com with the given
password. If authentication succeeds, she is assigned three roles:
"role2" and "role3", the values of the "memberOf" attribute in her
directory entry, and "tomcat", the value of the "cn" attribute in the
only group entry of which she is a member.
Finally, to authenticate the user by retrieving
the password from the directory and making a local comparison in the
realm, you might use a realm configuration like this:
 |  |  |  |
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"
connectionName="cn=Manager,dc=mycompany,dc=com"
connectionPassword="secret"
connectionURL="ldap://localhost:389"
userPassword="userPassword"
userPattern="uid={0},ou=people,dc=mycompany,dc=com"
roleBase="ou=groups,dc=mycompany,dc=com"
roleName="cn"
roleSearch="(uniqueMember={0})"
/>
|  |  |  |  |
However, as discussed above, the default bind mode for
authentication is usually to be preferred.
Additional Notes
JNDIRealm operates according to the following rules:
- When a user attempts to access a protected resource for the first time,
Tomcat 5 will call the
authenticate() method of this
Realm. Thus, any changes you have made to the directory
(new users, changed passwords or roles, etc.) will be immediately
reflected.
- Once a user has been authenticated, the user (and his or her associated
roles) are cached within Tomcat for the duration of the user's login.
(For FORM-based authentication, that means until the session times out or
is invalidated; for BASIC authentication, that means until the user
closes their browser). Any changes to the directory information for an
already authenticated user will not be reflected until
the next time that user logs on again.
- Administering the information in the directory server
is the responsibility of your own applications. Tomcat does not
provide any built-in capabilities to maintain users and roles.
- Debugging and exception messages logged by this
Realm will
be recorded by the Logger that is associated with our
surrounding Context, Host, or
Engine. By default, the corresponding Logger will create a
log file in the $CATALINA_HOME/logs directory.
|
| MemoryRealm |
Introduction
MemoryRealm is a simple demonstration implementation of the
Tomcat 5 Realm interface. It is not designed for production use.
At startup time, MemoryRealm loads information about all users, and their
corresponding roles, from an XML document (by default, this document is loaded from $CATALINA_HOME/conf/tomcat-users.xml). Changes to the data
in this file are not recognized until Tomcat is restarted.
Realm Element Attributes
To configure MemoryRealm, you will create a <Realm>
element and nest it in your $CATALINA_HOME/conf/server.xml file,
as described above. The following
attributes are supported by this implementation:
| Attribute | Description |
|---|
className |
The fully qualified Java class name of this Realm implementation.
You MUST specify the value
"org.apache.catalina.realm.MemoryRealm" here.
| debug |
The level of debugging detail logged by this Realm
to the associated Logger. Higher numbers
generate more detailed output. If not specified, the default
debugging detail level is zero (0).
| digest |
The digest algorithm used to store passwords in non-plaintext formats.
Valid values are those accepted for the algorithm name by the
java.security.MessageDigest class. See
Digested Passwords for more
information. If not specified, passwords are stored in clear text.
| pathname |
Absolute or relative (to $CATALINA_HOME) pathname of the XML document
containing our valid usernames, passwords, and roles. See below for more
information on the format of this file. If not specified, the value
conf/tomcat-users.xml is used.
|
User File Format
The users file (by default, conf/tomcat-users.xml must be an
XML document, with a root element <tomcat-users>. Nested
inside the root element will be a <user> element for each
valid user, consisting of the following attributes:
- name - Username this user must log on with.
- password - Password this user must log on with (in
clear text if the
digest attribute was not set on the
<Realm> element, or digested appropriately as
described here otherwise).
- roles - Comma-delimited list of the role names
associated with this user.
Example
The default installation of Tomcat 5 is configured with a MemoryRealm
nested inside the <Engine> element, so that it applies
to all virtual hosts and web applications. The default contents of the
conf/tomcat-users.xml file is:
 |  |  |  |
<tomcat-users>
<user name="tomcat" password="tomcat" roles="tomcat" />
<user name="role1" password="tomcat" roles="role1" />
<user name="both" password="tomcat" roles="tomcat,role1" />
</tomcat-users>
|  |  |  |  |
Additional Notes
MemoryRealm operates according to the following rules:
- When Tomcat first starts up, it loads all defined users and their
associated information from the users file. Changes to the data in
this file will not be recognized until Tomcat is
restarted.
- When a user attempts to access a protected resource for the first time,
Tomcat 5 will call the
authenticate() method of this
Realm.
- Once a user has been authenticated, the user (and his or her associated
roles) are cached within Tomcat for the duration of the user's login.
(For FORM-based authentication, that means until the session times out or
is invalidated; for BASIC authentication, that means until the user
closes their browser).
- Administering the information in the users file is the responsibility
of your application. Tomcat does not
provide any built-in capabilities to maintain users and roles.
- Debugging and exception messages logged by this
Realm will
be recorded by the Logger that is associated with our
surrounding Context, Host, or
Engine. By default, the corresponding Logger will create a
log file in the $CATALINA_HOME/logs directory.
|
|
| 標準レルム実装 |
| JDBCレルム |
はじめに
JDBCレルム は、Tomcat 5 の
Realm インタフェースの実装のうちの1つです。
この実装は、JDBCドライバがアクセスするリレーショナルデータベースからユーザを見つけ出します。
データベース構造が次のような要件を満足しさえすれば、
既存の表の列名との対応づけにより、
十分柔軟な設定をすることができます:
- 以下のユーザ表のように参照可能な表が必要です。
この表には、この
Realmが認識すべき有効な各ユーザに対して1つの行を持ちます。
- ユーザ表は少なくとも2つの列を持たなければなりません。
(アプリケーションに必要な他の列があってもかまいません):
- ユーザログイン時にTomcatがユーザ名として認識する列
- ユーザログイン時にTomcatがパスワードとして認識する列。
この値は、平文あるいはダイジェスト暗号化されたものを指定してください。 - 後述の情報を参考にしてください
- ユーザロール表として参照可能な表が必要です。
この表は、特定のユーザに割り当てられる有効な各ロールに対して1つの行を持ちます。
あるユーザが有効なロールを持たなくても、1つだけ持っても、1つ以上持ってもかまいません。
- ユーザロール表は少なくとも2つの列を持たなければなりません。
(アプリケーションに必要な他の列があってもかまいません):
- Tomcatがユーザ名と認識する列 (
ユーザ 表の対応する列と同じ値を持つ)。
- ユーザに付与された有効なロール名を持つ列
クイックスタート
JDBCレルムを使用するようにTomcatを設定するためには次の手順に従ってください:
- データベースに表をまだ作成していない場合は、前述した条件を満たす列を持つ表を作成します。
- Tomcatが利用するデータベースのユーザ名とパスワードを設定します。
少なくとも、前述した表への検索アクセスが可能でなければなりません。
(これらの表の更新をTomcatがすることはありません。)
- JDBCドライバのコピーを
$CATALINA_HOME/server/libディレクトリ内へ置きます
(もしWebアプリケーションへ見せる必要がない場合)。
あるいは$CATALINA_HOME/common/libへ置きます
(Tomcat 5 と自作アプリケーションの両方によって使用したい場合)。
JARファイルだけが有効となることに注意してください。
$CATALINA_HOME/conf/server.xmlファイルに<Realm>
要素を追加してください。内容は、以下の記述に従ってください。
- Tomcat 5 が既に動作している場合はTomcat 5 の再起動をしてください。
Realm 要素の属性
JDBCレルムを設定するためには、前述の通りに
$CATALINA_HOME/conf/server.xmlファイルへ
<Realm>要素を記述します。この実装では次の属性がサポートされています:
| 属性 | 説明 |
|---|
className |
このレルムを実装するJavaの完全修飾クラス名。
ここには、"org.apache.catalina.realm.JDBCRealm"
を指定しなければなりません。
| connectionName |
JDBC接続をするために使用するデータベースユーザ名
| connectionPassword |
JDBC接続をするために使用するデータベースパスワード
| connectionURL |
JDBC接続をするために使用するデータベースのURL
| debug |
関連するロガーによってこのレルムで記録される詳細デバッグレベル。
数値が高いほどより詳細な出力を生成します。
指定がない場合の詳細デバッグレベルの初期値は零(0)です。
| digest |
平文でないパスワードを保存するために使用するダイジェストアルゴリズム。
java.security.MessageDigestクラスが受け付けるアルゴリズム名が有効です。
詳細については、
ダイジェストパスワード を参照してください。
指定されない場合、パスワードは平文で保存されているとみなします。
| driverName |
使用されるJDBCドライバの完全修飾クラス名。
JDBCドライバによって特有の値なので、そのマニュアルをよく調べてください。
| roleNameCol |
ユーザロール表の列名。
この列には、ユーザに付与されているロール名が入っている必要があります。
| userCredCol |
ユーザ表の列名。この列には、
対応するユーザのパスワードが入っている必要があります(平文、
もしくはdigest 属性が設定されている場合はダイジェストされた値)。
| userNameCol |
ユーザ表とユーザロール表の列名。
このユーザのユーザ名が入っている必要があります。
| userRoleTable |
特定のユーザ名と対応するロールを各行に保持する表の名前。
この表は少なくとも、
userNameCol とroleNameCol 属性で指定された列を持っている必要があります。
| userTable |
Tomcatによって認証されるユーザ名を各行に含む表名。
この表は少なくとも、userNameCol とuserCredCol属性で指定された列を持っている必要があります。
|
例
必要な表を作成するSQL スクリプトの例はここで示すようなものになります。
(使用するデータベースによって文法が若干異なります):
 |  |  |  |
create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);
create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);
|  |  |  |  |
デフォルトの$CATALINA_HOME/conf/server.xml ファイルに、
(コメントアウトされていますが)Realm要素の例が記述されています。
ここでは、"authority"というMySQLのデータベースを使った一例を示します。
前述の通りに設定した表を用意し、ユーザ名"dbuser" とパスワード"dbpass"でアクセスしています:
 |  |  |  |
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority?user=dbuser&password=dbpass"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/>
|  |  |  |  |
さらなる注意点
JDBCレルムは次の規則に従って処理をします:
- 保護されたリソースへのアクセスをユーザが初めて試みたときに、
Tomcat 5 はこの
Realmのauthenticate() メソッドを呼び出します。
従って、データベースディレクトリに対する変更(新しいユーザを追加したりパスワードやロールを変更するなど)は、
どんなものでも即座に反映されます。
- ユーザログインの持続のためユーザ(個人だけでなく付与されているロールも含めて)情報は、
一度認証されるとTomcatにキャッシュされます。
(FORM-based 認証においては、セッションの期限切れや無効化されるまでを意味します。
BASIC 認証においては、ユーザがブラウザを閉じるまでを意味します。)
すでに認証されたユーザに関するデータベースの情報に対するいかなる変更も、
ユーザが再度ログインするときまで反映されません。
- ユーザ表とユーザロール表に関する情報の管理については、
使用しているアプリケーションの責務になります。
ユーザとロールの保守をするための組み込み機能をTomcat は一切提供しません。
- この
Realm によって記録されるデバッグ用途と例外のメッセージは、
Context, Host, やEngineで囲まれて関連づけられた
Loggerによって行われます。
デフォルトでは、連携しているロガーは$CATALINA_HOME/logs
ディレクトリにログファイルを作成します。
|
| データソースレルム |
はじめに
データソースレルム はTomcat 5 の
Realm インタフェースの実装のうちの1つです。
この実装は、JNDI名を持つJDBCデータソースへのアクセスによって
リレーショナルデータベースからユーザを見つけ出します。
データベース構造が次のような要件を満足しさえすれば、
既存表の列名との対応づけにより十分柔軟な設定をすることができます:
- ユーザ表として参照可能な表が必要です。
この表には、この
Realmが認識可能で有効な各ユーザに対して1つの行を持ちます。
- ユーザ 表は少なくとも2つの列を持たなければなりません。
(アプリケーションに必要な他の列があってもかまいません):
- ユーザログイン時にTomcatがユーザ名として認識する列
- ユーザログイン時にTomcatがパスワードとして認識する列。
この値は、平文かダイジェスト暗号化されたものを指定してください。 - 後述の情報を参照にしてください
- ユーザロール 表として参照可能な表が必要です。
この表は、特定のユーザに割り当てられる有効な各ロールに対して1つの行を持ちます。
あるユーザが有効なロールを持たなくても、1つだけ持っても、1つ以上持ってもかまいません。
- ユーザロール 表は少なくとも2つの列を持たなければなりません。
(アプリケーションに必要な他の列があってもかまいません):
- Tomcatがユーザ名と認識する列 (
ユーザ 表の対応する列と同じ値を持つ)。
- ユーザに付与された有効なロール名を持つ列
クイックスタート
データソースレルムを使用するようにTomcatを設定するためには、次のステップに従ってください:
- まだデータベースに表を作成していない場合は、前述した条件を満たす列を持つ表を作成します。
- Tomcatが利用するデータベースのユーザ名とパスワードを設定します。
少なくとも、前述した表への検索アクセスが可能でなければなりません。
(これらの表の更新をTomcatがすることはありません。)
- JNDI名を持つJDBCデータソースとして対象のデータベースを設定します。
設定に関する詳細については、
JDBCデータソースを参照してください。
$CATALINA_HOME/conf/server.xmlファイルに
<Realm>要素を追加してください。
内容は、以下に記述するようにしてください。
- Tomcat 5 が既に動作している場合は再起動をしてください。
Realm 要素の属性
データソースレルムを設定するためには、前述の通りに
$CATALINA_HOME/conf/server.xmlファイルへ
<Realm>要素を記述します。この実装では次の属性がサポートされています:
| 属性 | 説明 |
|---|
className |
このレルムを実装するJavaの完全修飾クラス名。
ここには、"org.apache.catalina.realm.DataSourceRealm"
を指定しなければなりません。
| dataSourceName |
使用するデータベースに対するJNDIのJDBCデータソース名。
| debug |
関連するロガーによってこのレルムで記録される詳細デバッグレベル。
数値が高いほどより詳細な出力を生成します。
指定がない場合の詳細デバッグレベルの初期値は零(0)です。
| digest |
平文でないパスワードを保存するために使用するダイジェストアルゴリズム。
java.security.MessageDigestクラスが受け付けるアルゴリズム名が有効です。
詳細については、
ダイジェストパスワード を参照してください。
指定されない場合、パスワードは平文で保存されているとみなします。
| roleNameCol |
ユーザロール表の列名。
この列には、ユーザに付与されているロール名が入っている必要があります。
| userCredCol |
ユーザ表の列名。この列には、
対応するユーザのパスワードが入っている必要があります(平文、
もしくはdigest 属性が設定されている場合はダイジェストされた値)。
| userNameCol |
ユーザ表とユーザロール表の列名。
このユーザのユーザ名が入っている必要があります。
| userRoleTable |
特定のユーザ名と対応するロールを各行に保持する表名。
この表は少なくとも、
userNameCol とroleNameCol 属性で指定された列を持っている必要があります。
| userTable |
Tomcatによって認証されるユーザ名を各行に含む表名。
この表は少なくともuserNameCol とuserCredCol属性で指定された列を持っている必要があります。
|
例
必要な表を作成するSQL スクリプトの例はここで示すようなものになります。
(使用するデータベースによって文法が若干異なります):
 |  |  |  |
create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);
create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);
|  |  |  |  |
ここでは、"authority"というMySQLのデータベースを使った一例を示します。
前述の通りに設定した表を用意して、
JNDI JDBC データソース名が"java:/comp/env/jdbc/authority"でアクセスしています:
 |  |  |  |
<Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"
dataSourceName="java:/comp/env/jdbc/authority"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/>
|  |  |  |  |
さらなる注意点
データソースレルムは次の規則に従って処理をします:
- 保護されたリソースへのアクセスをユーザが初めて試みたときに、
Tomcat 5 はこの
Realmのauthenticate() メソッドを呼び出します。
従って、データベースディレクトリに対する変更(新しいユーザを追加したりパスワードやロールを変更するなど)は、
どんなものでも即座に反映されます。
- ユーザログインの持続のためユーザ(個人だけでなく付与されているロールも含めて)情報は、
一度認証されるとTomcatにキャッシュされます。
(FORM-based 認証においては、セッションの期限切れや無効化されるまでを意味します。
BASIC 認証においては、ユーザがブラウザを閉じるまでを意味します。)
すでに認証されたユーザに関するデータベースの情報に対するいかなる変更も、
ユーザが再度ログインするときまで反映されません。
- ユーザ表とユーザロール表に関する情報の管理については、
使用しているアプリケーションの責務になります。
ユーザとロールの保守をするための組み込み機能をTomcat は一切提供しません。
- この
Realm によって記録されるデバッグ用途と例外のメッセージは、
Context, Host, やEngineで囲まれて関連づけられた
Loggerによって行われます。
デフォルトでは、連携しているロガーは$CATALINA_HOME/logs
ディレクトリにログファイルを作成します。
|
| JNDIレルム |
はじめに
JNDIレルム はTomcat 5 の
Realm インタフェースの実装のうちの1つです。
この実装は、JNDIプロバイダ(典型的には、
JNDI API クラスで有効な標準LDAPプロバイダ)
によるアクセスによって、
LDAPディレクトリサーバからユーザを見つけ出します。
認証でディレクトリを利用するために、
このレルムは様々なアプローチをサポートします:
ディレクトリへの接続
レルムのディレクトリ接続はconnectionURL 設定属性によって定義されます。
JNDIプロバイダによって定義されるフォーマットのURLをここに指定します。
これは、ディレクトリサーバへ接続するためのドメイン名指定に通常使われるLDAP URL です。
ポート番号と、コンテキスト名となるルートの識別名(DN)もオプションで指定できます。
1つ以上のプロバイダがある場合はalternateURLを設定します。
connectionURLで指定されたプロバイダへのソケット接続ができない場合は、
alternateURLを使っての接続を試みます。
ディレクトリを検索してユーザとロールを取り出すための接続ができたら、
connectionNameとconnectionPassword
属性で指定されたユーザ名とパスワードを使ってディレクトリの認証をレルムは受けます。
これらの属性が指定されていない場合は匿名(anonymous)で接続が行われます。
ほとんどの場合、匿名接続で十分です。
ユーザのディレクトリエントリの選択
認証され得るそれぞれのユーザは、
個々のエントリによってディレクトリ内で表されなければなりません。
このエントリは、connectionURL
属性によって定義された初期DirContextの要素と一致します。
このユーザエントリは、
認証のために使われるユーザ名を含む属性を持っていなければなりません。
ユーザのエントリに対応する識別名(DN)は認証のために使われるユーザ名を含んでいますが、
すべてのユーザにとってユーザ名以外は同じである場合がほとんどです。
こういった場合は、
ユーザ名を表す部分を"{0}"とする特別な識別名(DN)をuserPattern属性に指定できます。
その他の場合レルムはディレクトリを検索し、
ユーザ名を持った唯一のエントリを見つけなければなりません。
次の属性はこの検索を制御します:
- userBase -
ユーザを含む部分木の開始点となるエントリ。
指定されなかった場合、
検索の出発点は最上位のコンテキストとなります。
- userSubtree - 検索範囲。
userBaseエントリを根とする部分木に対して検索したい場合に
trueを指定します。初期値はfalseで、
この場合は最上位のみを対象とする単一階層の検索を要求したことになります。
- userSearch -
LDAP検索フィルターのパターンを指定します。
このフィルターはユーザ名の後方一致で使用されます。
ユーザの認証
-
バインドモード
初期設定では、ユーザに対応するエントリーの識別名(DN)のディレクトリと、
ユーザが入力したパスワードとをバインドすることによってレルムはユーザを認証します。
この単純なバインドが成功した場合ユーザは認証されたとみなされます。
セキュリティ確保のため、平文よりも、
ダイジェスト化されたユーザパスワードをディレクトリへ保存するようにして下さい
(詳細はダイジェストパスワードを参照のこと)。
この場合、ユーザが入力した平文パスワードの正しいダイジェストを、
単純なバインド操作の一部としてディレクトリは自動的に計算します。
保存された値に対して検査をする前にこの計算は行われます。
このためバインドモードでは、レルムはダイジェスト処理に含まれません。
ダイジェスト 属性は使われず、設定しても無視されます。
-
比較モード
他の手段として、保存されたパスワードをディレクトリからレルムが検索し、
それとユーザが入力した値とを比較する方法があります。このモードは、
userPassword属性を指定することによって制御できます。
userPassword属性には、
パスワードを入れておくユーザエントリのディレクトリ属性の名前を指定します。
比較モードにはいくつか不便な点があります。
1つめは、ユーザのパスワードをディレクトリにおいてレルムが読み取るれように、
connectionName属性とconnectionPassword
属性を設定する必要があることです。
セキュリティ確保のため、通常はこの指定をしません。代わりに多くのディレクトリ実装は、
ディレクトリ管理者であってもこれらのパスワードを読み込めないようにしています。
さらにレルムは、使用される様々なアルゴリズムとパスワードをハッシュする方法をディレクトリ内部に用意し、
パスワードダイジェスト化を自前で行わなければなりません。
しかしながら、保存されたパスワードへのアクセスが必要なときもレルムにはあるでしょう。
例えば、HTTPダイジェストアクセス認証(RFC 2069)のサポートのためといった場合です。
(ダイジェスト化されたパスワードをユーザ情報向けのリポジトリに保存しておく上述の方式とHTTPダイジェスト認証とは異なることに注意)
ユーザへのロールの割り当て
ディレクトリ内でロールを表す2つの方法をディレクトリレルムはサポートします:
ロールを指定する方式は両方とも組み合わせて使われます。
クイックスタート
JNDIレルムを使用するようにTomcatを設定するためには次のステップに従ってください:
- 上述した要件に合致する内容でディレクトリサーバが設定されているかを確認してください。
- 必要なら、Tomcatが使うユーザ名とパスワードを設定します。
前述したように読み込むためだけにその情報へアクセスします。
(Tomcat はこの情報を決して変更しようとしません。)
- 使用するJNDIドライバ(典型的にはJNDIを有効にする
ldap.jar)のコピーを、
(もしWebアプリケーションへ見せる必要がない場合は)
$CATALINA_HOME/server/lib ディレクトリ内へ置きます。
または、(Tomcat 5 と自作アプリケーションの両方によって使用したい場合は)
$CATALINA_HOME/common/lib ディレクトリ内へ置きます。
$CATALINA_HOME/conf/server.xmlファイルへ、
<Realm>要素を追加してください。
内容は、以下に記述されたように設定してください。
- Tomcat 5 が既に動作している場合は再起動をしてください。
Realm 要素の属性
JNDIレルムを設定するためには、前述の通りに
$CATALINA_HOME/conf/server.xmlファイルへ
<Realm>要素を記述します。
この実装では次の属性がサポートされています:
| 属性 | 説明 |
|---|
className |
このレルムを実装するJavaの完全修飾クラス名。
ここには、"org.apache.catalina.realm.JNDIRealm"
を指定しなければなりません。
| connectionName |
LDAP検索操作のためのディレクトリ接続を確立するときに使うディレクトリユーザ名。
指定されていない場合は匿名接続になります。
userPassword属性を指定しない限りは匿名接続で十分です。
| connectionPassword |
LDAP検索操作のためのディレクトリ接続を確立するときに使うディレクトリパスワード。
指定されていない場合は、匿名接続になります。
userPassword属性を指定しない限りは匿名接続で十分です。
| connectionURL |
ディレクトリへの接続を確立するときにJNDIドライバに渡される接続URL
| contextFactory |
この接続で使用されるJNDIコンテキストファクトリのJavaの完全修飾クラス名。
初期設定では、標準のJNDI LDAP プロバイダ
(com.sun.jndi.ldap.LdapCtxFactory)が使われます。
| debug |
関連するロガーによってこのレルムで記録される詳細デバッグレベル。
数値が高いほどより詳細な出力を生成します。
指定がない場合の詳細デバッグレベルの初期値は零(0)です。
| digest |
ユーザによって示された平文のパスワードへ適用されるダイジェストアルゴリズム。
ディレクトリから検索される値との比較より前に適用されます。
java.security.MessageDigestクラスが受け付けるアルゴリズム名が有効です。
詳細については、ダイジェストパスワード を参照してください。
指定されない場合は平文パスワードを検索するものとみなします。
userPassword が指定されない限り必要ありません。
| roleBase |
ロール検索実行の出発点となるディレクトリエントリです。
指定されない場合は、ディレクトリコンテキストの最上位の要素が使われます。
| roleName |
ロール検索によって見つけらるディレクトリエントリ内のロール名を持つ属性名です。
加えて、userRoleName プロパティも使えます。このプロパティは、
追加のロール名を持ったユーザエントリ内の属性名を指定します。
roleNameが指定されない場合ロール検索は行われず、
ユーザエントリからのみロールを取得することになります。
| roleSearch |
ロール検索の実行で使われるLDAPフィルタの式です。
java.text.MessageFormatクラスによってサポートされる構文に従います。
ユーザの識別子名(DN)を置き換えるには{0}を、
ユーザ名を置き換えるには{1}を使います。
指定されなかった場合ロール検索は行われず、
userRoleName属性によって指定されたユーザエントリにある属性からのみロールを取得します。
| roleSubtree |
ユーザに割り当てられたロールエントリをroleBase
属性によって指定された要素の部分木から検索したい場合は
trueを指定します。
初期設定値であるfalseは最上位からしか検索しないことになります。
| userBase |
userSearch式を使って実行されるユーザ検索のための出発点です。
指定されない場合は、ディレクトリコンテキストの最上位の要素が使われます。
userPattern式を使っている場合は指定しないでください。
| userPassword |
ユーザのパスワードを保存するユーザエントリの属性名。
この値が指定されない場合は、connectionNameとconnectionPassword
属性によって指定された値を使ってJNDIレルムはディレクトリをバインドします。
そして、認証中のユーザが指定したパスワード値と比較するため、
対応する属性を検索します。
digest属性が設定されている場合は、
指定されたダイジェストアルゴリズがユーザの入力したパスワードに適用されます。
これは、入力されたパスワードとディレクトリから検索された値との比較が行われる前に適用されます。
この値を指定しない場合JNDIレルムは、
ユーザのエントリの識別名(DN)とユーザによって指定されたパスワードを使ってディレクトリを単純にバインドしようとします。
認証されたユーザとして解釈されればバインドは成功します。
| userPattern |
ユーザのディレクトリエントリの識別名(DN)のためのパターン。
java.text.MessageFormatクラスによってサポートされる構文に従います。
実際のユーザ名が挿入される位置の印としては{0}を使います。
識別名(DN)がユーザ名を含み、かつ、識別名(DN)のうちユーザ名以外の部分が同じ場合は、
この属性をuserSearch、userSubtree、
userBaseの代わりに使うことができます。
| userRoleName |
ユーザに割り当てられたロール名を0個以上持つユーザディレクトリエントリの属性名。
ディレクトリ検索によって見つけられた個々のロールエントリから検索される属性名を指定するために、
roleName属性も一緒に使うことができます。
userRoleNameが指定されない場合は、
ユーザに割り当てられているロールすべてがロール検索から得られます。
| userSearch |
ユーザのディレクトリエントリに対する検索において使われるLDAPフィルター式。
実際のユーザ名が挿入される位置には{0}で印をつけます。
この属性は、ディレクトリからユーザエントリを検索するために、
userPatternの代わりに(userBaseと
userSubtree属性と一緒に)使います。
| userSubtree |
userBase属性によって指定された要素の部分木からユーザエントリを検索したい場合に
trueと指定します。初期設定値である
false は最上位からしか検索しないことになります。
userPattern式を使用する場合は指定しないでください。
|
例
ディレクトリサーバで特定のスキーマを作成することはこの文書の範囲を越えています。
なぜなら、それはディレクトリサーバの実装に依存するからです。
以下の例では、http://www.openldap.org
からダウンロード可能な、OpenLDAPディレクトリサーバ(2.0.11版以降)を使うことを前提とします。
また、(特に)slapd.conf ファイルは次のように設定されているものとします:
 |  |  |  |
database ldbm
suffix dc="mycompany",dc="com"
rootdn "cn=Manager,dc=mycompany,dc=com"
rootpw secret
|  |  |  |  |
connectionURLの指定にあたっては、
Tomcatが動作しているマシンと同じマシンでディレクトリサーバが動作しているものとします。
設定とJNDI LDAP プロバイダの使用に関する詳細については、http://java.sun.com/products/jndi/docs.html
を参照してください。
次に、このディレクトリサーバは、
(LDIFフォーマット形式で)次に示すような要素を実装しているものとします:
 |  |  |  |
# Define top-level entry
dn: dc=mycompany,dc=com
objectClass: dcObject
dc:mycompany
# Define an entry to contain people
# searches for users are based on this entry
dn: ou=people,dc=mycompany,dc=com
objectClass: organizationalUnit
ou: people
# Define a user entry for Janet Jones
dn: uid=jjones,ou=people,dc=mycompany,dc=com
objectClass: inetOrgPerson
uid: jjones
sn: jones
cn: janet jones
mail: j.jones@mycompany.com
userPassword: janet
# Define a user entry for Fred Bloggs
dn: uid=fbloggs,ou=people,dc=mycompany,dc=com
objectClass: inetOrgPerson
uid: fbloggs
sn: bloggs
cn: fred bloggs
mail: f.bloggs@mycompany.com
userPassword: fred
# Define an entry to contain LDAP groups
# searches for roles are based on this entry
dn: ou=groups,dc=mycompany,dc=com
objectClass: organizationalUnit
ou: groups
# Define an entry for the "tomcat" role
dn: cn=tomcat,ou=groups,dc=mycompany,dc=com
objectClass: groupOfUniqueNames
cn: tomcat
uniqueMember: uid=jjones,ou=people,dc=mycompany,dc=com
uniqueMember: uid=fbloggs,ou=people,dc=mycompany,dc=com
# Define an entry for the "role1" role
dn: cn=role1,ou=groups,dc=mycompany,dc=com
objectClass: groupOfUniqueNames
cn: role1
uniqueMember: uid=fbloggs,ou=people,dc=mycompany,dc=com
|  |  |  |  |
上記で説明した通りに設定されたOpenLDAP ディレクトリサーバのためのRealm
要素の例は次のようになります。
ここでは、ユーザはuid(例 jjones)を使ってアプリケーションへログインし、
ディレクトリ検索とロール情報の検索をするのには匿名接続で十分であるものとします:
 |  |  |  |
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"
connectionURL="ldap://localhost:389"
userPattern="uid={0},ou=people,dc=mycompany,dc=com"
roleBase="ou=groups,dc=mycompany,dc=com"
roleName="cn"
roleSearch="(uniqueMember={0})"
/>
|  |  |  |  |
この設定によりレルムは、userPatternをユーザ名へ置き換えて、
ユーザの識別名(DN)を決定します。
そして、この識別名(DN)とユーザから受け取ったパスワードをディレクトリへ渡して認証を行い、
ユーザのロールを確定するためにディレクトリを検索します。
ユーザは最近、ユーザIDよりもeメールアドレスの入力をログイン時に求められることが多くあります。
この場合レルムは、ユーザのエントリに対してディレクトリを検索しなければなりません。
(異なる組織単位や会社住所といった複数の部分木にユーザエントリがある場合も検索は必要です。)
そしてさらにグループエントリに加えて、
ロールを固定するためのユーザエントリの属性を使いたい場合もあるでしょう。
Janet Jones のエントリーは次のようになっているはずです:
 |  |  |  |
dn: uid=jjones,ou=people,dc=mycompany,dc=com
objectClass: inetOrgPerson
uid: jjones
sn: jones
cn: janet jones
mail: j.jones@mycompany.com
memberOf: role2
memberOf: role3
userPassword: janet
|  |  |  |  |
次のレルム設定は新しい要求を満たしています:
|
|
|