Em filtroDeAuditoria há erro na linha:
Cookie cookie = new Cookies(req.getCookies()).getUsuarioLogado();
as soluções se referem ao construtor e a inexistência de getUsuarioLogado() para Cookies.
Passei o resp como parâmetro para getUsuario.
package br.com.alura.gerenciador.web;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.util.http.Cookies;
@WebFilter(urlPatterns = "/*")
public class filtroDeAuditoria implements Filter{
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest req =(HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String uri = req.getRequestURI();
String usuario = getUsuario(req, resp);
System.out.println("Usuário" + usuario + "acessando a uri : " + uri);
chain.doFilter(request, response);
}
private String getUsuario(HttpServletRequest req ,HttpServletResponse resp) {
Cookie cookie = new Cookies(req.getCookies()).getUsuarioLogado();
if(cookie==null) return "<deslogado>";
else {
cookie.setMaxAge(60*10);
resp.addCookie(cookie);
return cookie.getValue();
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}