You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Next »

このセクションではデータベースを使ってユーザー名とパスワードを検証・検索する方法を説明します。

この例では、組み込まれているDerbyデータベースを使って SecurityDatabase という名前の新しいデータベースを作ります。以下のステップではデータベースとテーブルを作り、サンプル・データをロードし、コネクション・プールを作る手順を要約します。データベースへコネクション・プールを定義するための詳細な方法はConfiguring database poolsセクションに記載されています。

データベースの作成とサンプル・データのロード

  • 左側の Console Navigation メニューから Database Manager をクリックします。
  • Create DB: フィールドに SecurityDatabase と入力し、Create をクリックします。
  • Use DB: プルダウン・メニューから SecurityDatabase を選択し、以下のコマンドを入力して Run SQL をクリックします。

create table users
(username varchar(15),
password varchar(15));
create table groups
(username varchar(15),
groupname varchar(15));
insert into users values('userone','p1');
insert into users values('usertwo','p2');
insert into users values('userthree','p3');
insert into groups values('userone','admin');
insert into groups values('usertwo','admin');
insert into groups values('userthree','user');

コネクション・プールの作成

  • 左側の Console Navigation メニューから Database Pools をクリックします。
  • Using the Geronimo database pool wizard をクリックします。
  • データベース・プール名に SecurityDatabasePool と入力します。
  • database pool typeプルダウン・メニューから Derby embedded XA を選択し、Next をクリックします。
  • Driver JAR スクロール・ボックスから org.apache.geronimo.configs/system-database/2.0.1/car を選択します。
  • DB user name と passwordは 空白 にします。
  • Databaseに SecurityDatabase と入力します。
  • Deploy をクリックします。

新規セキュリティ・レルムの追加

新規にセキュリティ・レルムを作成するには Security Realms ポートレットで Add new security realm をクリックします

Name of Security Realm: フィールドに derby_security_realm と入力し、Realm type: プルダウン・メニューから Database (SQL) Realm を選択して Next をクリックします。

以下の画面でログイン・モジュールを構成します。冒頭の2つのフィールドは利用しているデータベースにより異なる値を入力する必要があるでしょう。今回はembedded Derby database を使用しますので、ユーザーとグループを入手するためのSQLは下記のようになります。

User SELECT SQL: select username, password from users where username=?
Group SELECT SQL: select username, groupname from groups where username=?

ユーザーとグループを検索するSQLステートメントを入力したら、前のステップで作成したデータベース・コネクション・プールを Database Pool プルダウン・メニューから選択してください。下記を参考に必要なフィールドに値を追加して Next をクリックします。

Database Pool: SecurityDatabasePool

以下の手順を踏めば、このレルムに対するログインの試みを監査しモニターできます。また設定した期間内に失敗したログインの回数に基づき、アカウントをロックアウトするように構成することもできます。Store Password を有効にすれば、ユーザーのパスワードを"Subject"内のプライベート・クリデンシャルに格納できます。また Naming Credential も有効にすれば、ユーザーのパスワードのみならずユーザーの名前もプライベート・クリデンシャルに格納できます。

ここまでで新しいセキュリティ・レルムを構成してきました。次は構成をテストしてデプロイしましょう。Test a Login をクリックします。

データベースから読み取れる有効なユーザー名とパスワードを入力し Next をクリックします。

ログイン成功を示す確認メッセージが表示されたら Deploy Realm をクリックしてこの構成をサーバーにロードします。

これでDerbyデータベース内のユーザー名とパスワードを使った、新規に完全に構成されたセキュリティ・レルムが完成しました。

このレルムの初回の検証時にエラーが発生した場合は、画面やログに SQL Exception: Failed to start database ... が出ているかもしれません。これはDerbyの既知の問題で、Geronimoをリスタートすれば新規データベースとの通信が正しく行えるようになります。

以下はこのセキュリティ・レルムのデプロイメント・プランの例です。Geronimo管理コンソールを使う方法以外に、このサンプルをファイル(derby_security_realm.xml)に保存して 1.9.3. Deployer tool - デプロイヤー・ツール を使って以下のコマンドを実行する方法もあります。

<geronimo_home>\bin\deploy --user system --password manager deploy <realm_path>\derby_security_realm.xml

derby_security_realm
<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
    <environment>
        <moduleId>
            <groupId>console.realm</groupId>
            <artifactId>derby_security_realm</artifactId>
            <version>1.0</version>
            <type>car</type>
        </moduleId>
        <dependencies>
            <dependency>
                <groupId>org.apache.geronimo.configs</groupId>
                <artifactId>j2ee-security</artifactId>
                <type>car</type>
            </dependency>
            <dependency>
                <groupId>console.dbpool</groupId>
                <artifactId>SecurityDatabasePool</artifactId>
                <version>1.0</version>
                <type>rar</type>
            </dependency>
        </dependencies>
    </environment>
    <gbean name="derby_security_realm" class="org.apache.geronimo.security.realm.GenericSecurityRealm" xsi:type="dep:gbeanType"
           xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <attribute name="realmName">derby_security_realm</attribute>
        <reference name="ServerInfo">
            <name>ServerInfo</name>
        </reference>
        <xml-reference name="LoginModuleConfiguration">
            <log:login-config xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0">
                <log:login-module control-flag="REQUIRED" wrap-principals="false">
                    <log:login-domain-name>derby_security_realm</log:login-domain-name>
                    <log:login-module-class>org.apache.geronimo.security.realm.providers.SQLLoginModule</log:login-module-class>
                    <log:option name="dataSourceName">SecurityDatabasePool</log:option>
                    <log:option name="dataSourceApplication">null</log:option>
                    <log:option name="groupSelect">select username, groupname from groups where username=?</log:option>
                    <log:option name="userSelect">select username, password from users where username=?</log:option>
                </log:login-module>
                <log:login-module control-flag="OPTIONAL" wrap-principals="false">
                    <log:login-domain-name>derby_security_realm-Audit</log:login-domain-name>
                    <log:login-module-class>org.apache.geronimo.security.realm.providers.FileAuditLoginModule</log:login-module-class>
                    <log:option name="file">var/log/derby_security_realm.log</log:option>
                </log:login-module>
                <log:login-module control-flag="REQUISITE" wrap-principals="false">
                    <log:login-domain-name>derby_security_realm-Lockout</log:login-domain-name>
                    <log:login-module-class>org.apache.geronimo.security.realm.providers.RepeatedFailureLockoutLoginModule</log:login-module-class>
                    <log:option name="failureCount">3</log:option>
                    <log:option name="failurePeriodSecs">10</log:option>
                    <log:option name="lockoutDurationSecs">60</log:option>
                </log:login-module>
            </log:login-config>
        </xml-reference>
    </gbean>
</module>

一旦セキュリティ・レルムを作ってしまえば、usageリンクから、そのレルムをアプリケーションで使用するためのサンプルを参照できます。

  • No labels