Home

Working with JDBCRealm

JDBCRealmを動作させる

What is JDBCRealm?

JDBCRealm とは?

Is an implementation of a tomcat 4.X Realm that use a set of configurable tables inside a RDMS to store user's data, this tables are accessed by means of standard JDBC drivers.

JDBCRealmとは、標準のJDBCドライバを使ってアクセスしてユーザーのデータを格納するためのRDBMSの設定可能なテーブルの集合を使用するtomcat 4.Xレルムの実装です。
The passwords can be stored as digested ( using standard Java's MessageDigest ) or in plain form.
パスワードは、(標準のJavaのMessageDigestを使用して)要約されるか平文形式として格納されます。
All the parameters, drivers, tables, and columns are user configurable.

全てのパラメータ、ドライバ、テーブル、カラム、ユーザーは設定可能です。

Example Config for JDBCRealm

JDBCRealm用の設定例

This is an example of how to set up a JDBCRealm. For this example I used the MySQL JDBC driver. これは、JDBCRealmをセットアップする方法の例です。 この例のために、私はMySQL JDBCドライバを使用しました。

1. Create a database.

1. データベースを作成

I made the database named "authority"

「authority」という名前のデータベースを作成しました

2. Create needed tables.

2. 必要なテーブルを作成

1. The user table.

1. userテーブル

This table needs the user's name and a password field. In the example I use "users" for the table name, "user_name" for the column that holds the user's name, and "user_pass" for the user's password.

このテーブルは、ユーザーの名前とパスワードのフィールドを必要とします。例で私が「users」をテーブル名に指定し、ユーザーの名前を格納する「user_name」とパスワードを格納する「user_pass」というカラム名を使用します。

2. The role table.

2. role テーブル

This table needs the role's set up that will be in any deployment descriptor that is managed under the container this Realm is in. In the example I use "roles" as the table name and "role_name" as the role's name. NB: This table doesn't get used at all by tomcat.

このレルムがあるコンテナの下で、管理されるどんな配備記述子でも、役割のものがそれの上でセットしたこのテーブルが必要になります。 例では「role」をテーブル名に、「role_name」を役割の名前として使っています。 このテーブルが、tomcatによって全てで使われるというわけではないことに注意してください。

3. The role to user table.

3. userテーブルにroleをつける

This table joins a set of roles to a single user. In the example the table name is "user_roles", the role's name is "role_name" , and the user's name is assumed to have the same column name as in the user's table ("user_name" in this example.

このテーブルは役割の集合を一人のユーザーにjoinします。 例でテーブル名が「user_roles」であること、役割の名前は「role_name」、そしてユーザ名は、ユーザテーブルで同じ名前のカラムがあるとします(この例では「user_name」)。

Here is the SQL I used to create the tables:

ここにtableを作成するために使用するSQLを示します。

create table users
(
  user_name varchar(15) not null primary key,
  user_pass varchar(15) not null
);


create table roles
(
  role_name varchar(15) not null primary key
);

create table user_roles
(
  user_name varchar(15) not null,
  role_name varchar(15) not null,
  primary key( user_name, role_name )
);


Here is sample output from the tables:

mysql> select * from users;
+-----------+-----------+
| user_name | user_pass |
+-----------+-----------+
| tomcat    | tomcat    |
| user1     | tomcat    |
| user2     | tomcat    |
| user3     | tomcat    |
+-----------+-----------+
4 rows in set (0.00 sec)

mysql> 
mysql> select * from roles;
+------------+
| role_name  |
+------------+
| tomcat     |
| role1      |
+------------+
2 rows in set (0.02 sec)

mysql> 


mysql> select * from user_roles;
+------------+-----------+
| role_name  | user_name |
+------------+-----------+
| tomcat     | user1     |
| role1      | user2     |
| tomcat     | tomcat    |
| role1      | tomcat    |
+------------+-----------+
4 rows in set (0.00 sec)

mysql> 

3. Configure Tomcat

3. Tomcatの設定

Add the information to the server.xml file. For this example I used this entry inside:

server.xmlファイルへ情報を追加します。この例では、私はこのエントリを使いました


<RequestInterceptor className="org.apache.catalina.realm.JDBCRealm"
debug="99" driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority?user=test;password=test" userTable="users"
userNameCol="user_name"
userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />

The meaning of the attributes is as follow:

属性の意味は以下に示します

attribute属性

Meaning意味
driverName The name of the driver needed to connect to the databaseデータベースに接続する必要なドライバの名前
connectionURL The connection URL used to connect to the databaseデータベースに接続するためのURL接続
userTable The user's tables ユーザテーブル
userNameCol The column in the user's table that contains the name ユーザテーブル内で名前が含まれているカラム
userCredCol The column in the user's table that contains the password ユーザテーブル内でパスワードが含まれているカラム
userRoleTable The user's roles table ユーザのroleテーブル
roleNameCol The column in the user's table that contains a role given to a user ユーザに与えられるロールが含まれるテーブルのカラム
connectionName The name to use when connecting to the database.データベースに接続するときに使う名前。 (Optional)
connectionPassword The password to use when connecting to the database.(Optional) データベースに接続するときに使うパスワード。(オプション)
Digest The algorithm used for digest passwords or "No" for plain passwords, the values can be "MD5", etc... (Optional) ダイジェストパスワードのアルゴリズムか、平文パスワード"No"、値は "MD5"など...(オプション)

 

Done!!

Using digested passwords

ダイジェストパスワードを使用する

To use digested password you need to store them digested. To achieve this, you will need to use the same digest strategies that JDBCrealm uses to store the passwords, inside JDBCRealm there is a static method with signature final public static String Digest(String password,String algorithm) this method is provided as a tool to be used outside JDBCRealm by an application that want to store passwords readable by JDBCRealm.

ダイジェスト・パスワードを使用するために、ダイジェストされたものを保存する必要があります。 これを行なうためには、あなたは、JDBCrealmがパスワードを格納するために同じダイジェスト戦略を使用する必要があることになります。JDBCRealm内部では、署名付きのstaticメソッド final public static String Digest(String password,String algorithm)があり、 このメソッドは、JDBCRealmによって読むことができるパスワードを格納するためのアプリケーションによって、外部のJDBCRealmを使用するためのツールを提供します。

Hints

ヒント

- Make sure that the JDBC driver is in the lib directory. - JDBCドライバがlibディレクトリにあることを確認してください。
- If you have problem connecting you can specify connectionName and connectionPassword

- 接続するときの問題があるときには、connectionNameとconnectionPasswordを指定することができます

$Header: /home/cvs/jakarta-tomcat-4.0/catalina/docs/JDBCRealm-howto.html,v 1.3 2001/01/14 01:31:44 craigmcc Exp $