Jump to content

Recommended Posts

Posted (edited)

Tenho o seguinte filtro

package filtro;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebFilter("/admin/*")
public class AdminFilter implements Filter 
{
   private static List<String> allowedURIs;

   public AdminFilter() 
   {
       // TODO Auto-generated constructor stub
   }

public void destroy() 
{
// TODO Auto-generated method stub
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException 
   {         
     HttpServletRequest req = (HttpServletRequest) request;  
     HttpServletResponse res = (HttpServletResponse) response;  
     HttpSession sessao= req.getSession();  

     if(sessao.getAttribute("admin")!= null || allowedURIs.contains(req.getRequestURI()))
     {
      chain.doFilter( request, response );
     }
     else
     {    
      res.sendRedirect("index.jsp");  
     }    
   }

public void init(FilterConfig fConfig) throws ServletException 
   {
       if(allowedURIs == null)
       {
           allowedURIs = new ArrayList<String>();
           allowedURIs.add(fConfig.getInitParameter("loginActionURI"));
           allowedURIs.add("/imwsaogotardo/admin/index.jsp");
           allowedURIs.add("/imwsaogotardo/admin/retornos/*");
       }
   }
}

E a seguinte Servlet:

...
AutenticaAdmin autenticaAdmin = new AutenticaAdmin();

Admin admin = autenticaAdmin.pesquisaAutenticaAdmin (login, senha);

if(admin!=null)
{
HttpSession sessao = request.getSession();

if(admin.getStatus().equals("d"))
{ 
sessao.setAttribute("admin", admin);
                               //só redireciona aqui, as demais param na Servlet
response.sendRedirect("admin/retornos/admin/loginOK.jsp");
}
else
{ 
sessao.setAttribute("nomeAdmin", admin.getNome()); 
response.sendRedirect("admin/retornos/admin/loginBloqueado.jsp");
}
}
else
{
response.sendRedirect("admin/retornos/admin/loginERRO.jsp");
} 
...

No filtro, adicionei à lista de exceções:


           allowedURIs = new ArrayList<String>();
           allowedURIs.add(fConfig.getInitParameter("loginActionURI"));
           allowedURIs.add("/imwsaogotardo/admin/index.jsp");
           allowedURIs.add("/imwsaogotardo/admin/retornos/*");

Mas o filtro só permite a execução na pasta retornos apenas quando o login é realizado com sucesso e a condição de status é igual a 'd'!

Porque isso esta acontecendo?

Edited by carcleo

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.