11.6.12. アプリケーションでのセキュリティードメインの使用
アプリケーションでセキュリティードメインを使用するには、最初にサーバーの設定でセキュリティードメインを定義し、アプリケーションのデプロイメント記述子でアプリケーションに対して有効にする必要があります。その後、使用する EJB に必要なアノテーションを追加する必要があります。ここでは、アプリケーションでセキュリティードメインを使用するために必要な手順について取り上げます。
警告
手順11.6 セキュリティードメインを使用するようアプリケーションを設定
セキュリティードメインの定義
サーバーの設定ファイルでセキュリティードメインを定義した後、アプリケーションの記述子ファイルでアプリケーションに対して有効にする必要があります。サーバーの設定ファイルへセキュリティードメインを設定
セキュリティードメインは、サーバーの設定ファイルのsecurityサブシステムに設定されます。JBoss EAP 6 インスタンスが管理対象ドメインで実行されている場合、domain/configuration/domain.xmlファイルになります。JBoss EAP 6 インスタンスがスタンドアロンサーバーとして実行されている場合はstandalone/configuration/standalone.xmlファイルになります。other、jboss-web-policy、およびjboss-ejb-policyセキュリティードメインはデフォルトとして JBoss EAP 6 に提供されます。次の XML の例は、サーバーの設定ファイルのsecurityサブシステムよりコピーされました。セキュリティードメインのcach-type属性は、高速な認証チェックを行うためにキャッシュを指定します。簡単なマップをキャッシュとして使用するdefaultか、Infinispan キャッシュを使用するinfinispanを値として使用できます。<subsystem xmlns="urn:jboss:domain:security:1.2"> <security-domains> <security-domain name="other" cache-type="default"> <authentication> <login-module code="Remoting" flag="optional"> <module-option name="password-stacking" value="useFirstPass"/> </login-module> <login-module code="RealmDirect" flag="required"> <module-option name="password-stacking" value="useFirstPass"/> </login-module> </authentication> </security-domain> <security-domain name="jboss-web-policy" cache-type="default"> <authorization> <policy-module code="Delegating" flag="required"/> </authorization> </security-domain> <security-domain name="jboss-ejb-policy" cache-type="default"> <authorization> <policy-module code="Delegating" flag="required"/> </authorization> </security-domain> </security-domains> </subsystem>管理コンソールまたは CLI を使用して、追加のセキュリティードメインを必要に応じて設定できます。アプリケーションの記述子ファイルでのセキュリティードメインの有効化
セキュリティードメインはアプリケーションのWEB-INF/web.xmlファイルにある<jboss-web>要素の<security-domain>子要素に指定されます。次の例はmy-domainという名前のセキュリティードメインを設定します。<jboss-web> <security-domain>my-domain</security-domain> </jboss-web>これがWEB-INF/jboss-web.xml記述子に指定できる多くの設定の 1 つになります。
EJB への必要なアノテーションの追加
@SecurityDomainおよび@RolesAllowedアノテーションを使用してセキュリティーを EJB に設定します。次の EJB コードの例は、guestロールのユーザーによるotherセキュリティードメインへのアクセスを制限します。package example.ejb3; import java.security.Principal; import javax.annotation.Resource; import javax.annotation.security.RolesAllowed; import javax.ejb.SessionContext; import javax.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * Simple secured EJB using EJB security annotations * Allow access to "other" security domain by users in a "guest" role. */ @Stateless @RolesAllowed({ "guest" }) @SecurityDomain("other") public class SecuredEJB { // Inject the Session Context @Resource private SessionContext ctx; /** * Secured EJB method using security annotations */ public String getSecurityInfo() { // Session context injected using the resource annotation Principal principal = ctx.getCallerPrincipal(); return principal.toString(); } }その他のコード例は、Red Hat カスタマーポータルより入手できる JBoss EAP 6 Quickstarts バンドルのejb-securityクイックスタートを参照してください。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.