@Test public void testDoFilterNotAcceptableNoHeaders() throws Exception { when(httpServletRequest.getHeaderNames()).thenReturn(null); when(httpServletRequest.getRequestURI()).thenReturn("/containers/continerid"); when(httpServletResponse.getWriter()).thenReturn(mock(PrintWriter.class)); filter.doFilter(httpServletRequest, httpServletResponse, filterChain); verify(httpServletResponse).setStatus(Status.UNAUTHORIZED.getStatusCode()); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final AuthorizationWrapper authorizationWrapper = new AuthorizationWrapper((HttpServletRequest) request); if (!authorizationWrapper.checkAuthorizationHeaders()) { LOGGER.error("Authorization headers check failed!"); final HttpServletResponse httpServletResponse = (HttpServletResponse) response; httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, httpServletResponse, JsonHandler.createObjectNode().put("Error", "Authorization headers check failed!")); } else { chain.doFilter(request, response); } }
AuthorizationFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final AuthorizationWrapper authorizationWrapper = new AuthorizationWrapper((HttpServletRequest) request); if (!authorizationWrapper.checkAuthorizationHeaders()) { LOGGER.error("Authorization headers check failed!"); final HttpServletResponse httpServletResponse = (HttpServletResponse) response; httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, httpServletResponse, JsonHandler.createObjectNode().put("Error", "Authorization headers check failed!")); } else { chain.doFilter(request, response); } } }
AuthorizationFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final AuthorizationWrapper authorizationWrapper = new AuthorizationWrapper((HttpServletRequest) request); if (!authorizationWrapper.checkAuthorizationHeaders()) { LOGGER.error("Authorization headers check failed!"); final HttpServletResponse httpServletResponse = (HttpServletResponse) response; httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, httpServletResponse, JsonHandler.createObjectNode().put("Error", "Authorization headers check failed!")); } else { chain.doFilter(request, response); } }  }
AuthorizationFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final AuthorizationWrapper authorizationWrapper = new AuthorizationWrapper((HttpServletRequest) request); if (!authorizationWrapper.checkAuthorizationHeaders()) { LOGGER.error("Authorization headers check failed!"); final HttpServletResponse httpServletResponse = (HttpServletResponse) response; httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, httpServletResponse, JsonHandler.createObjectNode().put("Error", "Authorization headers check failed!")); } else { chain.doFilter(request, response); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); }
AuthorizationFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final AuthorizationWrapper authorizationWrapper = new AuthorizationWrapper((HttpServletRequest) request); if (!authorizationWrapper.checkAuthorizationHeaders()) { LOGGER.error("Authorization headers check failed!"); final HttpServletResponse httpServletResponse = (HttpServletResponse) response; httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, httpServletResponse, JsonHandler.createObjectNode().put("Error", "Authorization headers check failed!")); } else { chain.doFilter(request, response); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }