Tomcat 8でRESTeasy 3.0.17FINALで認証フィルターを実装しようとしています。ここに私のweb.xml
の項目があります。ここでRESTeasy ContainerRequestFilterが呼び出されない
<!-- RESTEasy Config -->
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>RESTEasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
私は私のテストAPI
@Path("/test")
public class TestAPI extends APIServlet {
@GET
@Path("/{id}")
@AllowUsers
@Produces(MediaType.APPLICATION_JSON)
public Response printMessage(@PathParam("id") int id) {
JsonObject json = new JsonObject();
json.addProperty("status", "awesome");
json.addProperty("yeah", "It worked");
return Response.ok(json).build();
}
}
そして、ここでは私の一時的なフィルタであります
@Provider
public class AuthFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
if(Math.random() < 0.5) {
containerRequestContext.abortWith(Response.status(403).build());
}
System.out.println("Filtered");
}
}
は私のフィルタが呼び出されていませんさん。 printlnに到達することはありません、私は正常にブレークポイントをフィルタに配置することはできません。 catalineまたはlocalhostログにエラーメッセージはありません。私は、次のような名前バインディングアノテーションを使用して試してみました:
@NameBinding
@Inherited
@Target({ElementType.TYPE, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Secured {
}
右AuthFilter
上とprintMessage
上@GET
上記@Provider
上記@Secured
で。それはどちらもうまくいかない。
私はなぜ私のフィルタは決して呼ばされていないweb.xml
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>com.myPackage.mvc.servlet.API.AuthFilter</param-value>
</context-param>
でフィルタをリスト明示的に試してみましたか?私は@Provider
とマークされた2つの他のクラスを持っていて、それらはシステムによって認識されており、ブレークポイントを配置することができ、彼らは期待どおりに働いています。
あなたのRESTエンドポイントは保護するメソッド(またはクラス)の上に@Securedを呼び出す必要があります – Rilcon42