Java Filter to redirect users who are not logged in to login page

后端 未结 4 2061
执念已碎
执念已碎 2020-12-17 05:05

I was trying to make a filter to stop users who are not logged in from accessing certain pages.For this i made a filter class with the following doFilter method

4条回答
  •  Happy的楠姐
    2020-12-17 05:36

    I think you have to change your web.xml... You have to put your restricted resources to appropriate folder. In this way Filter Servlet will restrict files which allocates in "restricted" folder.(http://www.developer.com/security/article.php/3467801/Securing-J2EE-Applications-with-a-Servlet-Filter.htm) (And I think the reason of using Filter Servlet is writing own Authorization system. - in this way you have not to define your Security Constraints in the web.xml, you have to define it in Data Base ;))) )

    
    
         AuthorizationFilter
         examples.AuthorizationFilter
         This Filter authorizes user access to application
                      components based upon request URI.
         
            error_page
            ../../login.html
         
    
    
    
         AuthorizationFilter
         /restricted/*
    
    

提交回复
热议问题