服务器上的自定义身份验证
我正在尝试使用 Jersey (与 Spring 一起运行)来实现一些自定义身份验证。我已经使身份验证逻辑正常工作并将其放置在 ContainerRequestFilter 中。
我当前遇到的问题是,如果身份验证失败,如何实际拒绝或重定向请求,而无需向每个端点方法添加自定义代码片段。
我尝试更改 ContainerRequestFilter 过滤器方法中的 URI 和方法类型,但它不起作用。尽管请求的属性已更改,但即使身份验证失败,Jersey 仍将执行原始方法。
我可以在每个方法中添加一个片段来检查身份验证是否失败,如果失败,则退出该方法,但这种方式首先就破坏了使用过滤器的全部意义......
我该如何处理这种情况?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果身份验证失败,请抛出 WebApplicationException 以及您希望从请求过滤器返回给客户端的所需响应。
If the authentication fails, throw a WebApplicationException with the desired response you want to return back to the client from your request filter.