@WebFilter(urlPatterns="/*") public class FiltroDeAuditoria implements Filter {
@Override public void destroy() {
}
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; String uri = req.getRequestURI();
Cookie[] cookies = req.getCookies(); String usuario = ""; if (cookies == null) { System.out.println(usuario); } for (Cookie cookie : cookies) { if (cookie.getName().equals("usuario.logado")) { usuario = cookie.getValue(); } }
System.out.println(usuario);
System.out.println("Usuário: " + usuario + " acessando a URI" + uri); chain.doFilter(request, response);
}
@Override public void init(FilterConfig arg0) throws ServletException {
}
}