0

Java EE アプリケーション サーバー (jboss-eap-4.3) と、より大きな Web アプリケーションを構成するいくつかの .wars があります。アイデアは、.war を別の .war から個別に実行したり、リンクしたりできるということです。概念的にはすべて同じアプリの一部であるため、複数のログインを提示することは望ましくありません。

すべての .wars が同じセキュリティ制約とセキュリティ ロールを共有するように構成したいと考えています。基本的に web.xml のこの部分:

<security-constraint>
   <web-resource-collection>
      <url-pattern>/*</url-pattern>
   </web-resource-collection>
   <auth-constraint>
      <role-name>Admin</role-name>
   </auth-constraint>
<security-constraint>

<security-role>
   <role-name>Admin</role-name>
</security-role>

<login-config>
   <auth-method>BASIC</auth-method>
   <realm-name>WebApp</realm-name>
</login-config>

私たちの役割は最近頻繁に変更されており、新しい .wars も定期的に追加しています。さらに、デプロイ環境に応じて auth-method を変更します。これにより、微調整する別の理由が追加されます。理想的には、他の人が「継承」できるように、web.xml のセキュリティ部分を切り離す方法が必要です。レルムはこれを探すのに適した場所かもしれないと思いましたが、有望なものは何も見つかりませんでした.

このコンテナーには、セキュリティ ドメインがまったく異なる他の Web アプリがまだ存在するため、Tomcat のグローバル設定は適切でない可能性があることに注意してください。

4

1 に答える 1

0

素晴らしい答えではありませんが、以下のような ant マクロ定義を使用して汚い作業を自動化することになりました。

  <!-- 
   | Take a "plain" web.xml and add security settings to it.  
   | This will add BASIC authentication with Admin, Operator, and Guest role access 
   |
   -->
   <taskdef resource="net/sf/antcontrib/antlib.xml" /> 
   <macrodef name="addSecurityToWeb.xml">
      <attribute name="file"/>
      <sequential>
         <if>
            <not>
                <isfileselected file="@{file}">
                    <contains text="login-config" ignorewhitespace="true"/>
                </isfileselected>
            </not>
            <then>
               <replace file="@{file}">
                  <replacetoken><![CDATA[</web-app>]]></replacetoken>
                  <replacevalue>
   <![CDATA[
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>Admin</role-name>
        </auth-constraint>

        <transport-guarantee>NONE</transport-guarantee>
    </security-constraint>

    <!-- Security roles referenced by this web application -->
    <security-role>
        <role-name>Admin</role-name>
    </security-role>

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>WebApp</realm-name>
    </login-config>
</web-app>
   ]]>    
                  </replacevalue>
               </replace>
            </then>
         </if>
      </sequential>
  </macrodef>
于 2011-12-05T15:08:32.510 に答える