2.3. データベースベースのアイデンティティーストアでの認証設定
ユーザー名、パスワード、およびロールのデータベース形式を決定します。
アイデンティティーストアのデータベースを使用して認証を設定するには、このデータベースへのユーザー名、パスワード、およびロールの保存方法を決定する必要があります。この例では、以下のデータ例でテーブルを 1 つ使用します。
username password roles user1
password123
Admin
user2
password123
Guest
データソースを設定します。
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
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
を作成することもできます。サポート対象のパスワードマッパーの一覧は、パスワードマッパー を参照してください。
security-domain
を設定します。/subsystem=elytron/security-domain=exampleDbSD:add(realms=[{realm=exampleDbRealm,role-decoder=groups-to-roles}],default-realm=exampleDbRealm,permission-mapper=default-permission-mapper)
undertow
サブシステムでapplication-security-domain
を設定します。/subsystem=undertow/application-security-domain=exampleApplicationDomain:add(security-domain=exampleDbSD)
注記Configuration → Subsystems → Web (Undertow) → Application Security Domain に移動して、管理コンソールを使用して
undertow
サブシステムのapplication-security-domain
を設定できます。アプリケーションの
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 で確認できます。