Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
farrell-m committed May 29, 2024
1 parent f2162e6 commit 8a83c73
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class ApiAccessDeniedHandler implements AccessDeniedHandler {
}

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException, ServletException {
int code = HttpServletResponse.SC_FORBIDDEN;
response.setStatus(code);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
Expand All @@ -38,7 +39,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Acc

response.getWriter().write(objectMapper.writeValueAsString(errorResponse));

log.info("Request rejected for endpoint '{}': {}", request.getRequestURI(), message);
log.info("Request rejected for endpoint '{} {}': {}", request.getMethod(), request.getRequestURI(), message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
try {
Authentication authentication = authenticationService.getAuthentication((HttpServletRequest) request);
SecurityContextHolder.getContext().setAuthentication(authentication);
log.info("Endpoint '{}' accessed by {}.", ((HttpServletRequest) request).getRequestURI(), authentication.getPrincipal().toString());
log.info("Endpoint '{} {}' requested by {}.", ((HttpServletRequest) request).getMethod(),
((HttpServletRequest) request).getRequestURI(), authentication.getPrincipal().toString());
filterChain.doFilter(request, response);
} catch (Exception ex) {
int code = HttpServletResponse.SC_UNAUTHORIZED;
Expand All @@ -63,7 +64,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

httpResponse.getWriter().write(objectMapper.writeValueAsString(errorResponse));

log.info("Request rejected for endpoint '{}': {}", ((HttpServletRequest) request).getRequestURI(), message);
log.info("Request rejected for endpoint '{} {}': {}", ((HttpServletRequest) request).getMethod(),
((HttpServletRequest) request).getRequestURI(), message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ApiAuthenticationToken extends AbstractAuthenticationToken {
private final String clientName;
private final String accessToken;

public ApiAuthenticationToken(String clientName, String accessToken, Collection<? extends GrantedAuthority> authorities) {
public ApiAuthenticationToken(String clientName, String accessToken,
Collection<? extends GrantedAuthority> authorities) {
super(authorities);
this.clientName = clientName;
this.accessToken = accessToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ public class AuthenticationProperties {

/**
* The list of clients who are authorized to access the API, and their roles
* JSON formatted string, with the top level being a list and each contained item representing a {@link ClientCredential}.
* JSON formatted string, with the top level being a list and each contained item
* representing a {@link ClientCredential}.
*/
@NotNull(message = "authorizedClients is required")
private String authorizedClients;

/**
* The list of roles that can be used to access the API, and the URIs they enable access to.
* JSON formatted string, with the top level being a list and each contained item representing an {@link AuthorizedRole}.
* JSON formatted string, with the top level being a list and each contained item representing
* an {@link AuthorizedRole}.
*/
@NotNull(message = "authorizedRoles is required")
private String authorizedRoles;
Expand Down

0 comments on commit 8a83c73

Please sign in to comment.