サーブレット・セキュリティー動的アノテーション

プログラマチック API を使用してサーブレットを追加または作成する場合、セキュリティー・アノテーション RunAS、declareRoles、および ServletSecurity を、setRunAsRole()、declareRoles()、および setServletSecurity() メソッドをそれぞれ使用して動的に更新できます。

注: RunAs、declareRoles、および ServletSecurity サーブレット・セキュリティー・アノテーションの動的更新のサポートは、このリリースの WebSphere® Application Server の新機能です。

アプリケーションの開始時に、 Web コンテナーは、RunAs、declareRoles、および ServletSecurity アノテーションが付いたサーブレットをすべて検査し、ServletRegistration アノテーションの setServletSecurity() メソッドでこれらのアノテーションを設定します。 Web コンテナーは、セキュリティー・コンポーネントに対し、URL パターンとセキュリティー制約が含まれているすべての ServletRegistration アノテーションを検査するように通知します。セキュリティー・コンポーネントは、デプロイメント記述子内に URL パターンが定義されているか どうかを判別します。デプロイメント記述子内で完全に一致する URL パターンが既に定義されている場合、デプロイメント記述子の URL パターンのセキュリティー制約と RunAs ロールが、動的データの代わりに使用されます。

トラブルの回避 (Avoid trouble) トラブルの回避 (Avoid trouble): 動的セキュリティー・アノテーション declareRoles、setRunAs、および rolesAllowed が使用される場合、ロール名は、デプロイメント記述子またはサーブレット・クラスの declareRoles または RunAs アノテーションを使用して事前に定義されている必要があります。デプロイ時に、管理コンソールを使用してユーザーまたはグループをこのロールにマップできます。gotcha

セキュリティー動的アノテーションに、ServletSecurity アノテーションに正確に一致する URL パターンがある場合、セキュリティー動的アノテーション内の URL パターンのセキュリティー制約が優先されます。同じ URL パターンを使用して setServletSecurity() メソッドを複数回呼び出す場合、最後に呼び出されたメソッドが優先されます。

  • ServletRegistration.Dynamic.setRunAsRole(String roleName) は、このサーブレット登録の RunAs ロールの名前を設定します。
  • ServletContext.declareRoles(String roleNames) は、isUserInRole() メソッドでテストされるロール名を宣言します。
  • ServletRegistration.Dynmaic.setServletSecurity(ServletSecurityElement constraint) は、このサーブレット登録の ServletSecurityElement を設定します。
注: Web 認証システム・プロパティー com.ibm.wsspi.security.web.webAuthReq が persisting に設定されており、有効なユーザー名とパスワードを使用する場合は、保護されていない URL にログインできます。

以下の 2 つの例は、setServletSecurity() メソッドを使用して動的サーブレットのセキュリティー制約と RunAs ロールを設定する際に使用できます。

以下の例では、PUT メソッド以外のすべての HTTP エレメントに Employee ロールのメンバーシップが必要です。PUT メソッドでは、<auth-constraint> エレメントに Manager ロールのメンバーシップが必要であり、TransportGuarantee は機密です。
HttpConstraintElement constraint = new HttpConstraintElement(TransportGuarantee.NONE,
new String[]{"Employee"});
List<HttpMethodConstraintElement> methodConstraints =
new ArrayList<HttpMethodConstraintElement>();
methodConstraints.add(new HttpMethodConstraintElement("PUT",
new HttpConstraintElement(TransportGuarantee.CONFIDENTIAL, new String[]{"Manager"})));
ServletSecurityElement servletSecurity =
new ServletSecurityElement(constraint, methodConstraints);
次の例では、CUSTOM メソッドおよび GET メソッド以外のすべての HTTP メソッドが許可されます。CUSTOM メソッドでは、<auth-constraint> エレメントに Manager ロールのメンバーシップが必要です。GET メソッドでは、<auth-constraint> エレメントに Employee ロールのメンバーシップが必要であり、TransportGuarantee は機密です。
HttpConstraintElement constraint = new HttpConstraintElement();
List<HttpMethodConstraintElement> methodConstraints =
new ArrayList<HttpMethodConstraintElement>();
methodConstraints.add(new HttpMethodConstraintElement("CUSTOM",
new HttpConstraintElement(TransportGuarantee.NONE, new String[]{"Manager"})));
methodConstraints.add(new HttpMethodConstraintElement("GET",
new HttpConstraintElement(TransportGuarantee.CONFIDENTIAL, new String[]{"Employee"})));
ServletSecurityElement servletSecurity = new ServletSecurityElement(constraint,
methodConstraints);

トピックのタイプを示すアイコン 概念トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=csec_dynamic_annotations
ファイル名:csec_dynamic_annotations.html