Reputation: 7549
I'm trying to implement some custom authentication using Jersey (running alongside Spring). I've gotten the authentication logic working okay and have placed it inside a ContainerRequestFilter.
The issue I'm currently having is working out how to actually reject or redirect the request if the authentication fails without having to add a custom snippet of code to each endpoint method.
I've tried changing the URI and the method type in the ContainerRequestFilter filter method but it doesn't work. Although the properties for the request are changed, Jersey will still execute the original method, even if authentication fails.
I could add a snippet in each method to check whether authentication has failed and, if so, exit the method, but that sort of defeats the entire point of using a filter in the first place...
How can I handle this situation?
Upvotes: 0
Views: 270
Reputation: 7989
If the authentication fails, throw a WebApplicationException with the desired response you want to return back to the client from your request filter.
Upvotes: 2