14.5. Elytron サブシステムを使用するためのリソースアダプターの設定
IronJacamar のリソースアダプターでは、サーバーとリソースアダプターの間で 2 種類の通信が発生します。
- 一方の種類の通信は、サーバーがリソースアダプター接続を開くときに発生します。これは、コンテナー管理のサインオンによって保護できます。コンテナー管理のサインオンでは、接続を開くときに、プリンシパルと認証情報を含む JAAS サブジェクトをリソースアダプターに伝播する必要があります。このサインオンは Elytron に委譲できます。
- もう一方の種類の通信は、リソースアダプターがワークマネージャーにワークを送信する際、または同じ JBoss EAP インスタンス内のエンドポイントにメッセージを配信する際に、セキュリティー情報を確立するときに発生します。このメカニズムはセキュリティーインフローと呼ばれます。
14.5.1. Elytron によるコンテナー管理のサインオン リンクのコピーリンクがクリップボードにコピーされました!
Elytron でコンテナー管理のサインオンを実現するには、elytron-enabled 属性を true に設定する必要があります。これにより、リソースアダプターへのすべての接続が Elytron によってセキュア化されます。
/subsystem=resource-adapters/resource-adapter=<RAR_NAME>/connection-definitions=<FACTORY_NAME>:write-attribute(name=elytron-enabled,value=true)
resource-adapters サブシステムの elytron-enabled 属性を true に設定すると、管理 CLI を使用して elytron-enabled 属性を設定できます。デフォルトではこの属性は false に設定されています。
authentication-context 属性は、サインオンの実行に使用される Elytron 認証コンテキストの名前を定義します。
Elytron の authentication-context 属性には 1 つ以上の authentication-configuration 要素を含めることができ、使用を希望する認証情報が含まれます。
authentication-context 属性が設定されていない場合、JBoss EAP は現在の authentication-context を使用します。これは、接続を開く呼び出し元コードによって使用される authentication-context です。
例: authentication-configuration の作成
/subsystem=elytron/authentication-configuration=exampleAuthConfig:add(authentication-name=sa,credential-reference={clear-text=sa})
例: 上記設定を使用した authentication-context の作成
/subsystem=elytron/authentication-context=exampleAuthContext:add(match-rules=[{authentication-configuration=exampleAuthConfig}])
14.5.2. Elytron によるセキュリティーインフロー リンクのコピーリンクがクリップボードにコピーされました!
セキュリティーインフローは、リソースアダプターがワークマネージャーにワークを送信する際、または同じ JBoss EAP インスタンス内のエンドポイントにメッセージを配信する際に、セキュリティー情報を確立することを可能にします。これにより、Elytron を使用してワークを実行する前に、ワークがワーク自身を認証できるようになります。認証に成功すると、提出されたワークは結果となる認証コンテキスト下で実行されます。認証に失敗すると、ワークの実行は拒否されます。
Elytron セキュリティーインフローを有効にするには、リソースアダプターのワークマネージャーを設定するときに wm-elytron-security-domain 属性を設定します。
-
リソースアダプターのワークマネージャーが Elytron セキュリティードメイン
wm-elytron-security-domainを使用するよう設定された場合、参照されたワークマネージャーのelytron-enabled属性をtrueに設定する必要があります。
/subsystem=jca/workmanager=customWM:add(name=customWM, elytron-enabled=true)
-
wm-elytron-security-domainの代わりにwm-security-domain属性が使用された場合、セキュリティーインフローはレガシーのsecurityサブシステムによって実行されます。
以下の jca サブシステムの設定例では、ra-with-elytron-security-domain というリソースアダプターの設定を確認できます。このリソースアダプターは、Elytron セキュリティードメインの wm-realm を使用するようワークマネージャーセキュリティーを設定します。
<subsystem xmlns="urn:jboss:domain:jca:5.0">
<archive-validation enabled="true" fail-on-error="true" fail-on-warn="false"/>
<bean-validation enabled="true"/>
<default-workmanager>
<short-running-threads>
<core-threads count="50"/>
<queue-length count="50"/>
<max-threads count="50"/>
<keepalive-time time="10" unit="seconds"/>
</short-running-threads>
<long-running-threads>
<core-threads count="50"/>
<queue-length count="50"/>
<max-threads count="50"/>
<keepalive-time time="10" unit="seconds"/>
</long-running-threads>
</default-workmanager>
<workmanager name="customWM">
<elytron-enabled>true</elytron-enabled>
<short-running-threads>
<core-threads count="20"/>
<queue-length count="20"/>
<max-threads count="20"/>
</short-running-threads>
</workmanager>
<bootstrap-contexts>
<bootstrap-context name="customContext" workmanager="customWM"/>
</bootstrap-contexts>
<cached-connection-manager/>
</subsystem>
その後、ワークマネージャーは resource-adapter サブシステムからブートストラップコンテキストを使用して参照されます。
<subsystem xmlns="urn:jboss:domain:resource-adapters:5.0">
<resource-adapters>
<resource-adapter id="ra-with-elytron-security-domain">
<archive>
ra-with-elytron-security-domain.rar
</archive>
<bootstrap-context>customContext</bootstrap-context>
<transaction-support>NoTransaction</transaction-support>
<workmanager>
<security>
<elytron-security-domain>wm-realm</elytron-security-domain>
<default-principal>wm-default-principal</default-principal>
<default-groups>
<group>
wm-default-group
</group>
</default-groups>
</security>
</workmanager>
</resource-adapter>
</resource-adapters>
</subsystem>
例: セキュリティードメインの設定
/subsystem=elytron/properties-realm=wm-properties-realm:add(users-properties={path=/security-dir/users.properties, plain-text=true}, groups-properties={path=/security-dir/groups.properties})
/subsystem=elytron/simple-role-decoder=wm-role-decoder:add(attribute=groups)
/subsystem=elytron/constant-permission-mapper=wm-permission-mapper:add(permissions=[{class-name="org.wildfly.security.auth.permission.LoginPermission"}])
/subsystem=elytron/security-domain=wm-realm:add(default-realm=wm-properties-realm, permission-mapper=wm-permission-mapper, realms=[{role-decoder=wm-role-decoder, realm=wm-properties-realm}])
Work クラスは、指定のドメイン下で Elytron の認証の認証情報を提供するロールがあります。そのためには、jakarta.resource.spi.work.WorkContextProvider を実装する必要があります。
public interface WorkContextProvider {
/**
* Gets an instance of <code>WorkContexts</code> that needs to be used
* by the <code>WorkManager</code> to set up the execution context while
* executing a <code>Work</code> instance.
*
* @return an <code>List</code> of <code>WorkContext</code> instances.
*/
List<WorkContext> getWorkContexts();
}
このインターフェイスは、Work クラスが WorkContext を使用して、ワークが実行されるコンテキストの一部の機能を設定できるようにします。その機能の 1 つがセキュリティーインフローです。そのためには、List<WorkContext> getWorkContexts メソッドが jakarta.resource.spi.work.SecurityContext を提供する必要があります。このコンテキストは、Jakarta Authentication で定義されている jakarta.security.auth.callback.Callback オブジェクトを使用します。
例: コンテキストを使用したコールバックの作成
public class ExampleWork implements Work, WorkContextProvider {
private final String username;
private final String role;
public MyWork(TestBean bean, String username, String role) {
this.principals = null;
this.roles = null;
this.bean = bean;
this.username = username;
this.role = role;
}
public List<WorkContext> getWorkContexts() {
List<WorkContext> l = new ArrayList<>(1);
l.add(new MySecurityContext(username, role));
return l;
}
public void run() {
...
}
public void release() {
...
}
public class ExampleSecurityContext extends SecurityContext {
public void setupSecurityContext(CallbackHandler handler, Subject executionSubject, Subject serviceSubject) {
try {
List<jakarta.security.auth.callback.Callback> cbs = new ArrayList<>();
cbs.add(new CallerPrincipalCallback(executionSubject, new SimplePrincipal(username)));
cbs.add(new GroupPrincipalCallback(executionSubject, new String[]{role}));
handler.handle(cbs.toArray(new jakarta.security.auth.callback.Callback[cbs.size()]));
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
上記の例では、ExampleWork は WorkContextProvider インターフェイスを実装し、ExampleSecurityContext を提供します。そのコンテキストは、ワークの実行時に Elytron によって認証されるセキュリティー情報の提供に必要なコールバックを作成します。