2.3. データベースベースのアイデンティティーストアでの認証設定

  1. ユーザー名、パスワード、およびロールのデータベース形式を決定します。

    アイデンティティーストアのデータベースを使用して認証を設定するには、このデータベースへのユーザー名、パスワード、およびロールの保存方法を決定する必要があります。この例では、以下のデータ例でテーブルを 1 つ使用します。

    usernamepasswordroles

    user1

    password123

    Admin

    user2

    password123

    Guest

  2. データソースを設定します。

    JBoss EAP からデータベースに接続するには、適切なデータベースドライバーをデプロイし、データソースを設定する必要があります。以下の例は、PostgreSQL のドライバーをデプロイし、JBoss EAP でデータソースを設定する方法を示しています。

    deploy /path/to/postgresql-9.4.1210.jar
    
    data-source add --name=examplePostgresDS --jndi-name=java:jboss/examplePostgresDS --driver-name=postgresql-9.4.1210.jar  --connection-url=jdbc:postgresql://localhost:5432/postgresdb --user-name=postgresAdmin --password=mysecretpassword
  3. JBoss EAP で jdbc-realm を設定します。

    /subsystem=elytron/jdbc-realm=exampleDbRealm:add(principal-query=[{sql="SELECT password,roles FROM eap_users WHERE username=?",data-source=examplePostgresDS,clear-password-mapper={password-index=1},attribute-mapping=[{index=2,to=groups}]}])
    注記

    上記の例は、1 つの principal-query からパスワードおよびロールを取得する方法を示しています。ロールや、追加の認証または承認情報の取得に複数のクエリーが必要な場合には、attribute-mapping 属性を使用して追加の principal-query を作成することもできます。

    サポート対象のパスワードマッパーの一覧は、パスワードマッパー を参照してください。

  4. security-domain を設定します。

    /subsystem=elytron/security-domain=exampleDbSD:add(realms=[{realm=exampleDbRealm,role-decoder=groups-to-roles}],default-realm=exampleDbRealm,permission-mapper=default-permission-mapper)
  5. undertow サブシステムで application-security-domain を設定します。

    /subsystem=undertow/application-security-domain=exampleApplicationDomain:add(security-domain=exampleDbSD)
    注記

    ConfigurationSubsystemsWeb (Undertow)Application Security Domain に移動して、管理コンソールを使用して undertow サブシステムの application-security-domain を設定できます。

  6. アプリケーションの web.xml および jboss-web.xml を設定します。

    アプリケーションの web.xml および jboss-web.xml は、JBoss EAP で設定した application-security-domain を使用するように更新する必要があります。このサンプルは、Configure Web Applications to use Elytron or Legacy Security for Authentication で確認できます。