What is the proper replacement of the Resteasy 3.X PreProcessInterceptor?

后端 未结 3 1494
孤城傲影
孤城傲影 2020-12-15 03:58

I\'m building rest service using an authentication/authorization mechanism as described in this tutorial: http://howtodoinjava.com/2013/06/26/jax-rs-resteasy-basic-authentic

3条回答
  •  孤城傲影
    2020-12-15 04:34

    RESTEasy 3.x.x conforms to the JAX-RS 2.0 specification.

    What you are trying to do could be accomplished (maybe better) with:

    @Provider
    public class SecurityInterceptor 
          implements javax.ws.rs.container.ContainerRequestFilter {
         @Override
         public void filter(ContainerRequestContext requestContext){
           if (not_authenticated){ requestContext.abortWith(response)};
         }
    }
    

    since the ReaderInterceptor is invoked only if the underlying MessageBodyReader.readFrom is called by the standard JAX-RS pipeline, not fromthe application code.

    The reason why your interceptor is not called, though, could be the @ServerInterceptor annotation, which is a RESTEasy extension.

    The spec states at §6.5.2 that a interceptor is globally registered, unless the @Provider is annotated with a @NameBinding annotation, but I don't know if RESTEasy can handle a @ServerInterceptor if it's not explicitly registered as shown in RestEASY Interceptor Not Being Called

提交回复
热议问题