-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Closed
Labels
in: webAn issue in web modules (web, webmvc)An issue in web modules (web, webmvc)status: duplicateA duplicate of another issueA duplicate of another issuetype: enhancementA general enhancementA general enhancement
Description
Summary
In BasicAuthenticationEntryPoint and DelegatingAuthenticationEntryPoint, HTTP status codes are returned using HttpStatus.UNAUTHORIZED.value().
However, in Http403ForbiddenEntryPoint, the status code 403 is hardcoded.
For consistency and maintainability, should we update Http403ForbiddenEntryPoint to also use HttpStatus.FORBIDDEN.value()?
Suggested Improvement
To maintain consistency across different authentication entry points,
Http403ForbiddenEntryPoint could be modified as follows:
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException {
logger.debug("Pre-authenticated entry point called. Rejecting access");
response.sendError(HttpStatus.FORBIDDEN.value(), HttpStatus.FORBIDDEN.getReasonPhrase());
}Current Implementation
BasicAuthenticationEntryPoint(UsesHttpStatus.UNAUTHORIZED.value())public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { response.addHeader("WWW-Authenticate", "Basic realm=\"" + this.realmName + "\""); response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase()); }
DelegatingAuthenticationEntryPoint(UsesHttpStatus.UNAUTHORIZED.value())public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { response.addHeader("WWW-Authenticate", authenticateHeader); response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase()); }
Http403ForbiddenEntryPoint(Hardcoded403)public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { logger.debug("Pre-authenticated entry point called. Rejecting access"); response.sendError(403, "Access Denied"); }
Questions
- Is there any specific reason why
Http403ForbiddenEntryPointdoes not follow the same pattern asBasicAuthenticationEntryPointandDelegatingAuthenticationEntryPoint? - Would it make sense to standardize the use of
HttpStatus.FORBIDDEN.value()for better readability and maintainability?
Metadata
Metadata
Assignees
Labels
in: webAn issue in web modules (web, webmvc)An issue in web modules (web, webmvc)status: duplicateA duplicate of another issueA duplicate of another issuetype: enhancementA general enhancementA general enhancement