2

パスが /rest/* のドメインを GET リクエストのみに制限したい。だから私は私のweb.xmlでそれを宣言します:

<security-constraint>
  <web-resource-collection>
    <web-resource-name>All</web-resource-name>
    <url-pattern>/rest/*</url-pattern>
    <http-method>GET</http-method>
  </web-resource-collection>
</security-constraint>

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

ただし、(たとえば) '/rest/add' に対して POST-Request を実行すると、Webcontainer は POST-Request を受け入れて送信します。どうしてこんなことに?

4

2 に答える 2

0

これは、最初の security-constraint が http-methods を持たない 2 番目のもの (順序が重要) によって上書きされるためです (web-resource-collection に http-method 要素がない場合、すべての HTTPメソッドは許可されます。)

つまり、このコードは

<security-constraint>
  <web-resource-collection>
    <web-resource-name>All</web-resource-name>
    <url-pattern>/rest/*</url-pattern>
    <http-method>GET</http-method>
  </web-resource-collection>
</security-constraint>

役に立たない

于 2012-08-01T08:26:40.793 に答える
0

セキュリティ制約は上書きされません。異なる制約の URL パターンが同じである場合、これらは追加されます。上記の例では、URL パターンが異なるため、最初のパターンが優先され、投稿が許可されます。

于 2015-01-18T18:22:50.900 に答える