3.4. 証明書ベースの認証を使用するようにセキュリティードメインを設定する手順
JBoss EAP には、セキュリティードメインと証明書ベースの認証を使用して Web アプリケーションまたは EJB のセキュリティーを確保する機能があります。
証明書ベースの認証を設定する前に、アプリケーションの双方向 SSL/TLS を有効化して設定する必要がありますが、これには、JBoss EAP インスタンスと、セキュリティードメインでセキュリティーを確保した Web アプリケーションまたは EJB の両方に X509 証明書を設定する必要があります。
証明書、トラストストア、および双方向 SSL/TLS を設定したら、証明書ベースの認証を使用するセキュリティードメインの設定、そのセキュリティードメインを使用するアプリケーションの設定、クライアント証明書を使用するクライアントの設定に進むことができます。
3.4.1. 証明書ベースの認証を使用したセキュリティードメインの作成
証明書ベースの認証を使用するセキュリティードメインを作成するには、トラストストアと Certificate ログインモジュールまたはそのサブクラスの 1 つを指定する必要があります。
トラストストアには、認証に使用する信頼できるクライアント証明書を含めるか、クライアントの証明書署名に使用する認証局の証明書を含める必要があります。このログインモジュールを使用して、設定済みのトラストストアでクライアントが提示する証明書を認証します。セキュリティードメイン全体として、認証後にロールをプリンシパルにマッピングする方法を提供する必要もあります。Certificate ログインモジュール自体は、ロール情報をプリンシパルにマッピングしませんが、別のログインモジュールと組み合わせることでこのマッピングが可能です。または、Certificate ログインモジュールの 2 つのサブクラス (CertificateRoles および DatabaseCertificate) でも、認証後にロールをプリンシパルにマップできます。以下の例は、CertificateRoles ログインモジュールを使用して、証明書ベースの認証でセキュリティードメインを設定する方法を紹介しています。
セキュリティードメインは認証を行うときに、双方向 SSL/TLS の設定時にクライアントが提示した証明書と同じ証明書を使用します。そのため、クライアントは双方向 SSL/TLS とアプリケーションまたは EJB を使用した証明書ベースの認証の 両方 に同じ証明書を使用する必要があります。
証明書ベースの認証を使用するセキュリティードメインの例
/subsystem=security/security-domain=cert-roles-domain:add /subsystem=security/security-domain=cert-roles-domain/jsse=classic:add(truststore={password=secret, url="/path/to/server.truststore.jks"}, keystore={password=secret, url="/path/to/server.keystore.jks"}, client-auth=true) /subsystem=security/security-domain=cert-roles-domain/authentication=classic:add /subsystem=security/security-domain=cert-roles-domain/authentication=classic/login-module=CertificateRoles:add(code=CertificateRoles, flag=required, module-options=[ securityDomain="cert-roles-domain", rolesProperties="${jboss.server.config.dir}/cert-roles.properties",password-stacking="useFirstPass", verifier="org.jboss.security.auth.certs.AnyCertVerifier"])
/subsystem=security/security-domain=cert-roles-domain:add
/subsystem=security/security-domain=cert-roles-domain/jsse=classic:add(truststore={password=secret, url="/path/to/server.truststore.jks"}, keystore={password=secret, url="/path/to/server.keystore.jks"}, client-auth=true)
/subsystem=security/security-domain=cert-roles-domain/authentication=classic:add
/subsystem=security/security-domain=cert-roles-domain/authentication=classic/login-module=CertificateRoles:add(code=CertificateRoles, flag=required, module-options=[ securityDomain="cert-roles-domain", rolesProperties="${jboss.server.config.dir}/cert-roles.properties",password-stacking="useFirstPass", verifier="org.jboss.security.auth.certs.AnyCertVerifier"])
上記の例では、CertificateRoles ログインモジュールを使用して認証を処理し、ロールを認証済みのプリンシパルにマップします。これには、rolesProperties
属性を使用してプロパティーファイルを参照します。このファイルは、以下の形式を使用して、ユーザー名とロールを一覧表示します。
user1=roleA user2=roleB,roleC user3=
user1=roleA
user2=roleB,roleC
user3=
ユーザー名は指定の証明書の DN として提示されるため、プロパティーファイルを使用する場合は、=
などの特殊文字をエスケープする必要があります (例: CN=valid-client, OU=JBoss, O=Red Hat, L=Raleigh, ST=NC, C=US
)。
ロールプロパティーファイルの例
CN\=valid-client,\ OU\=JBoss,\ O\=Red\ Hat,\ L\=Raleigh,\ ST\=NC,\ C\=US=Admin
CN\=valid-client,\ OU\=JBoss,\ O\=Red\ Hat,\ L\=Raleigh,\ ST\=NC,\ C\=US=Admin
証明書の DN を表示するには、次のコマンドを実行します。
keytool -printcert -file valid-client.crt
$ keytool -printcert -file valid-client.crt
Owner: CN=valid-client, OU=JBoss, O=Red Hat, L=Raleigh, ST=NC, C=US
...
3.4.2. 証明書ベースの認証でセキュリティードメインを使用するようにアプリケーションを設定する手順
他の形式の認証でセキュリティードメインを使用するようにアプリケーションを設定する場合と同様に、jboss-web.xml
と web.xml
ファイルの両方を適切に設定する必要があります。
jboss-web.xml
の場合は、証明書ベース認証用に設定したセキュリティードメインへの参照を追加します。
jboss-web.xml の例
<jboss-web> <security-domain>cert-roles-domain</security-domain> </jboss-web>
<jboss-web>
<security-domain>cert-roles-domain</security-domain>
</jboss-web>
web.xml
の場合は、<login-config>
の <auth-method>
属性を CLIENT-CERT
に設定します。また <security-constraint>
と <security-roles>
を定義する必要もあります。
web.xml の例
<web-app> <!-- URL for secured portion of application--> <security-constraint> <web-resource-collection> <web-resource-name>secure</web-resource-name> <url-pattern>/secure/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>All</role-name> </auth-constraint> </security-constraint> <!-- Security roles referenced by this web application --> <security-role> <description>The role that is required to log in to the application</description> <role-name>All</role-name> </security-role> <login-config> <auth-method>CLIENT-CERT</auth-method> <realm-name>cert-roles-domain</realm-name> </login-config> </web-app>
<web-app>
<!-- URL for secured portion of application-->
<security-constraint>
<web-resource-collection>
<web-resource-name>secure</web-resource-name>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>All</role-name>
</auth-constraint>
</security-constraint>
<!-- Security roles referenced by this web application -->
<security-role>
<description>The role that is required to log in to the application</description>
<role-name>All</role-name>
</security-role>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>cert-roles-domain</realm-name>
</login-config>
</web-app>
3.4.3. クライアントの設定
クライアントが証明書ベースの認証でセキュリティー保護したアプリケーションに対して認証するには、クライアントから JBoss EAP インスタンスのトラストストアに含まれるクライアント証明書にアクセスできる必要があります。たとえば、ブラウザーを使用してアプリケーションにアクセスする場合には、クライアントは信頼される証明書をブラウザーのトラストストアにインポートする必要があります。