Senhores,o problema é o seguinte:
Estou iniciando uma aplicação em Primefaces com Facelets e pretendo usar um Servlet Filter que funcionava perfeitamente no JSF 1.2 para autenticação do sistema.
O problema é que o filter está redirecionando corretamente pra página de login,mas não está carregando a parte do template no arquivo.
Eu sei que o problema está nesse redirecionamento,pois se chamar a página sem passar pelo filtro a mesma é carregada corretamente.
Código do filtro:
public class LoginFilter implements Filter {
@Override
public void init(FilterConfig arg0) throws ServletException {}
@Override
public void destroy() {}
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
try{
HttpServletRequest httpReq = (HttpServletRequest)req;
HttpServletResponse httpRes = (HttpServletResponse)res;
HttpSession session = httpReq.getSession(true);
String url = httpReq.getRequestURL().toString();
if(session.getAttribute("usuario")==null && precisaAutenticar(url)){
httpRes.sendRedirect(httpReq.getContextPath()+"/login.jsf");
}else{
chain.doFilter(req, res);
}
}catch(Exception e){
e.printStackTrace();
}
}
boolean precisaAutenticar(String url){
return !url.contains("teste")
&& !url.contains("login.jsf")
&& !url.endsWith(".css")
&& !url.endsWith(".js")
&& !url.endsWith(".jpg")
&& !url.endsWith(".gif");
}
login.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core" >
<h:body>
<ui:composition template="template/common/commonLayout.xhtml">
<ui:define name="content">
PÁGINA DE LOGIN
</ui:define>
</ui:composition>
</h:body>
</html>