@Test void testWithAuthorizationException() throws IOException { Mockito.when(request.getRequestURI()) .thenReturn(FOO_REQUEST_URI); Mockito.when(fooUriAuthorizationFilter.ensureUserIsAuthorized(request, response)) .thenThrow(new SLException("...")); PrintWriter writer = Mockito.mock(PrintWriter.class); Mockito.when(response.getWriter()) .thenReturn(writer); assertFalse(compositeUriAuthorizationFilter.ensureUserIsAuthorized(request, response)); Mockito.verify(response) .setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); Mockito.verify(writer) .print("..."); Mockito.verify(writer) .flush(); }
@Override protected boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response) throws IOException { try { String uri = ServletUtil.decodeUri(request); String normalizedUri = ServletUtil.removeInvalidForwardSlashes(uri); LOGGER.trace("Looking for a matching authorization filter for request to \"{}\"...", uri); LOGGER.trace("Registered authorization filters: {}", uriAuthorizationFilters); for (UriAuthorizationFilter uriAuthorizationFilter : uriAuthorizationFilters) { if (normalizedUri.matches(uriAuthorizationFilter.getUriRegex())) { return ensureUserIsAuthorized(uriAuthorizationFilter, request, response); } } LOGGER.trace("No matching authorization filter for request to \"{}\".", uri); return true; } catch (Exception e) { ResponseEntity<String> responseEntity = exceptionMapper.handleException(e); ServletUtil.send(response, responseEntity.getStatusCodeValue(), responseEntity.getBody()); return false; } }
CompositeUriAuthorizationFilter extends AuthorizationFilter { @Override protected boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response) throws IOException { try { String uri = ServletUtil.decodeUri(request); String normalizedUri = ServletUtil.removeInvalidForwardSlashes(uri); LOGGER.trace("Looking for a matching authorization filter for request to \"{}\"...", uri); LOGGER.trace("Registered authorization filters: {}", uriAuthorizationFilters); for (UriAuthorizationFilter uriAuthorizationFilter : uriAuthorizationFilters) { if (normalizedUri.matches(uriAuthorizationFilter.getUriRegex())) { return ensureUserIsAuthorized(uriAuthorizationFilter, request, response); } } LOGGER.trace("No matching authorization filter for request to \"{}\".", uri); return true; } catch (Exception e) { ResponseEntity<String> responseEntity = exceptionMapper.handleException(e); ServletUtil.send(response, responseEntity.getStatusCodeValue(), responseEntity.getBody()); return false; } } }
CompositeUriAuthorizationFilter extends AuthorizationFilter { @Override protected boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response) throws IOException { try { String uri = ServletUtil.decodeUri(request); String normalizedUri = ServletUtil.removeInvalidForwardSlashes(uri); LOGGER.trace("Looking for a matching authorization filter for request to \"{}\"...", uri); LOGGER.trace("Registered authorization filters: {}", uriAuthorizationFilters); for (UriAuthorizationFilter uriAuthorizationFilter : uriAuthorizationFilters) { if (normalizedUri.matches(uriAuthorizationFilter.getUriRegex())) { return ensureUserIsAuthorized(uriAuthorizationFilter, request, response); } } LOGGER.trace("No matching authorization filter for request to \"{}\".", uri); return true; } catch (Exception e) { ResponseEntity<String> responseEntity = exceptionMapper.handleException(e); ServletUtil.send(response, responseEntity.getStatusCodeValue(), responseEntity.getBody()); return false; } } @Inject  CompositeUriAuthorizationFilter(List<UriAuthorizationFilter> uriAuthorizationFilters, CFExceptionMapper exceptionMapper); }
CompositeUriAuthorizationFilter extends AuthorizationFilter { @Override protected boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response) throws IOException { try { String uri = ServletUtil.decodeUri(request); String normalizedUri = ServletUtil.removeInvalidForwardSlashes(uri); LOGGER.trace("Looking for a matching authorization filter for request to \"{}\"...", uri); LOGGER.trace("Registered authorization filters: {}", uriAuthorizationFilters); for (UriAuthorizationFilter uriAuthorizationFilter : uriAuthorizationFilters) { if (normalizedUri.matches(uriAuthorizationFilter.getUriRegex())) { return ensureUserIsAuthorized(uriAuthorizationFilter, request, response); } } LOGGER.trace("No matching authorization filter for request to \"{}\".", uri); return true; } catch (Exception e) { ResponseEntity<String> responseEntity = exceptionMapper.handleException(e); ServletUtil.send(response, responseEntity.getStatusCodeValue(), responseEntity.getBody()); return false; } } @Inject  CompositeUriAuthorizationFilter(List<UriAuthorizationFilter> uriAuthorizationFilters, CFExceptionMapper exceptionMapper);  }
CompositeUriAuthorizationFilter extends AuthorizationFilter { @Override protected boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response) throws IOException { try { String uri = ServletUtil.decodeUri(request); String normalizedUri = ServletUtil.removeInvalidForwardSlashes(uri); LOGGER.trace("Looking for a matching authorization filter for request to \"{}\"...", uri); LOGGER.trace("Registered authorization filters: {}", uriAuthorizationFilters); for (UriAuthorizationFilter uriAuthorizationFilter : uriAuthorizationFilters) { if (normalizedUri.matches(uriAuthorizationFilter.getUriRegex())) { return ensureUserIsAuthorized(uriAuthorizationFilter, request, response); } } LOGGER.trace("No matching authorization filter for request to \"{}\".", uri); return true; } catch (Exception e) { ResponseEntity<String> responseEntity = exceptionMapper.handleException(e); ServletUtil.send(response, responseEntity.getStatusCodeValue(), responseEntity.getBody()); return false; } } @Inject  CompositeUriAuthorizationFilter(List<UriAuthorizationFilter> uriAuthorizationFilters, CFExceptionMapper exceptionMapper);   }