2
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Common pages</web-resource-name>
      <url-pattern>/test1.html</url-pattern>
      <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>MY_GROUP</role-name>
    </auth-constraint>
  </security-constraint>

予想どおり、この制約により、ページ /test1.html は認証が必要であり、ページ /test2.html は認証を必要としません。

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Common pages</web-resource-name>
      <url-pattern>/*</url-pattern>
      <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>MY_GROUP</role-name>
    </auth-constraint>
  </security-constraint>

予想どおり、この制約により、/test2.html を含むすべてのページで認証が必要になります。

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Common pages</web-resource-name>
      <url-pattern>/</url-pattern>
      <url-pattern>/test1.html</url-pattern>
      <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>MY_GROUP</role-name>
    </auth-constraint>
  </security-constraint>

この制約により、ページ /test1.html および / は認証が必要であると予想されますが、ページ /test2.html は認証を必要としません。

ただし、 /test2.html にも認証が必要であることが判明しました。

質問 1. それは正常ですか? どうしてですか?

質問 2. url-pattern "/" が "/*" に相当することは、仕様のどこに記述されていますか? Java サーブレット仕様 2.5: http://goo.gl/UxoPL

質問 3. ルート ページ "/" では認証が必要であるが、他のページでは必要ないことをどのように判断できますか?

ps: jboss-eap-4.3 を使用しています。

4

1 に答える 1

2

は、 、 などの同じ webapp 内のより具体的なサーブレット URL パターンのいずれにも一致しない/すべてのものに一致する特別な URL パターンです。たとえば、「デフォルト サーブレット」です。これは、デフォルトで、サーブレットコンテナ自身のデフォルトサーブレットによって処理され、通常、Web アプリケーションの独自のサーブレットが呼び出されないプレーンな HTML/CSS/JS/画像ファイルなどの静的リソースに使用されます。たとえば、Tomcat にはこの目的のための があります。/app/**.doDefaultServlet

は、「デフォルト サーブレット」リクエストを含む、すべて/*に一致する非常に一般的な URL パターンです。この URL パターンは、通常、サーブレットではなく、フィルターでのみ使用されます。そうしないと、プレーンなバニラ HTML/CSS/JS/画像ファイルなどの静的ファイルを処理するために、servletcontainer 独自のデフォルト サーブレットのジョブを再発明する必要があります。

具体的な機能要件については、ウェルカム ファイルを指定する必要があります。/

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

代わりにセキュリティ制約 URL パターンを配置し/index.htmlます。

于 2012-05-19T17:45:48.587 に答える