1

RESTEasy を使用して RESTful API を公開するアプリケーションがあります。メソッドを呼び出す前に、ユーザーは HTTP-Basic を使用して認証する必要があります。

ただし、RESTful API に、すべてのユーザーが認証なしで呼び出すことができるメソッドを追加したいと考えています。それ、どうやったら出来るの?認証がそのメソッドのオプションであることを示すために、メソッド宣言に追加できる JAX-RS/RESTEasy アノテーションはありますか。

ありがとう。

4

1 に答える 1

2

web.xml で、認証を必要としない REST パスを除外します。

<security-constraint>
   <web-resource-collection>
     <web-resource-name>All Access</web-resource-name>
     <url-pattern>/unchecked/*</url-pattern>
     <http-method>DELETE</http-method>
     <http-method>PUT</http-method>
     <http-method>HEAD</http-method>
     <http-method>OPTIONS</http-method>
     <http-method>TRACE</http-method>
     <http-method>GET</http-method>
     <http-method>POST</http-method>
   </web-resource-collection>
   <user-data-constraint>
     <transport-guarantee>NONE</transport-guarantee>
   </user-data-constraint>
</security-constraint>

次に、認証を必要としない REST リソースは次のようになります。

@Path("/unchecked")
public class NoAuthResource{


}
于 2012-04-16T21:28:11.397 に答える