RESTEasy を使用して RESTful API を公開するアプリケーションがあります。メソッドを呼び出す前に、ユーザーは HTTP-Basic を使用して認証する必要があります。
ただし、RESTful API に、すべてのユーザーが認証なしで呼び出すことができるメソッドを追加したいと考えています。それ、どうやったら出来るの?認証がそのメソッドのオプションであることを示すために、メソッド宣言に追加できる JAX-RS/RESTEasy アノテーションはありますか。
ありがとう。
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{
}