AuditFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { final String requestTimeISO9601 = DateTimeHelper.formatDateUTC(new Date()); final HttpServletRequest httpRequest = (HttpServletRequest) request; final String requestId = UUID.randomUUID().toString(); final Thread currentThread = Thread.currentThread(); final String oldName = currentThread.getName(); String user = getUserFromRequest(httpRequest); try { currentThread.setName(formatName(oldName, requestId)); RequestContext requestContext = RequestContext.createContext(); requestContext.setUser(user); recordAudit(httpRequest, requestTimeISO9601, user); filterChain.doFilter(request, response); } finally { ((HttpServletResponse) response).setHeader(AtlasClient.REQUEST_ID, requestId); currentThread.setName(oldName); recordMetrics(); RequestContext.clear(); RequestContextV1.clear(); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain); static void audit(String who, String fromAddress, String whatRequest, String fromHost, String whatURL, String whatAddrs,
            String whenISO9601); static void recordMetrics(); @Override void destroy();  }
@Test public void testAuditWithExcludedOperation() throws IOException, ServletException { AtlasRepositoryConfiguration.resetExcludedOperations(); when(configuration.getStringArray(AtlasRepositoryConfiguration.AUDIT_EXCLUDED_OPERATIONS)).thenReturn(new String[]{"GET:Version", "GET:Ping"}); when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("api/atlas/version")); when(servletRequest.getMethod()).thenReturn("GET"); AuditFilter auditFilter = new AuditFilter(); auditFilter.doFilter(servletRequest, servletResponse, filterChain); verify(filterChain).doFilter(servletRequest, servletResponse); }
@Test public void testAuditWithExcludedOperationInIncorrectFormat() throws IOException, ServletException { AtlasRepositoryConfiguration.resetExcludedOperations(); when(configuration.getStringArray(AtlasRepositoryConfiguration.AUDIT_EXCLUDED_OPERATIONS)).thenReturn(new String[]{"Version", "Ping"}); when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("api/atlas/version")); when(servletRequest.getMethod()).thenReturn("GET"); AuditFilter auditFilter = new AuditFilter(); auditFilter.doFilter(servletRequest, servletResponse, filterChain); verify(filterChain).doFilter(servletRequest, servletResponse); }