eclipse-ee4j / eclipse-ee4j/jersey

Allow specifying HttpServletResponse reset behaviour on error

Open
#3,361 4 comments 0 reactions 0 assignees View on GitHub
Priority: Major Type: Improvement
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

As Jersey currently stands, it is not fully compatible with using Spring Security's ExceptionTranslationFilter. For example:

1) Spring Security sets headers such as cache-control on response in filter before Jersey
2) AccessDeniedException is thrown from a method called by Jersey (by a preAuthorize check on a method)
3) Jersey is specifically configured to not handle AccessDeniedException, and thus ResponseWriter.failure() is called.
4) ResponseWriter.failure() resets the HttpServletResponse before rethrowing AccessDeniedException, thus erasing all the headers previously set by Spring Security.
5) Spring handles AccessDeniedException, but the proper headers are not set on the response anymore.

The basic issue is that any headers set on the HttpServletResponse object before Jersey is invoked get removed by Jersey's error handling. The solution would seem to be to call resetBuffer() rather than reset() in the ResponseWriter.falure() method. A Jersey Server Property could be used to indicate if resetBuffer(), rather than reset() should be called.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.