Subversion Repositories bacoAlunos

Rev

Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 fvelez 1
package pt.estgp.estgweb.web.filters;
2
 
3
import org.apache.log4j.Logger;
1830 jmachado 4
import pt.estgp.estgweb.domain.UserSessionImpl;
1814 jmachado 5
import pt.estgp.estgweb.utils.Globals;
1830 jmachado 6
import pt.estgp.estgweb.web.UserSessionProxy;
1 fvelez 7
 
8
import javax.servlet.*;
9
import javax.servlet.http.HttpServletRequest;
10
import java.io.IOException;
11
 
12
/**
13
 *
14
 * @author  Jorge Machado
15
 */
16
 
1830 jmachado 17
public class AuthenticationAllFilter extends UserFilter {
1 fvelez 18
 
1830 jmachado 19
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(AuthenticationAllFilter.class);
1 fvelez 20
 
21
 
1830 jmachado 22
    public AuthenticationAllFilter()
1 fvelez 23
    {
24
    }
25
 
1830 jmachado 26
    static 1.5.0/docs/api/java/lang/String.html">String[] allowedPatternsContains;
27
    static 1.5.0/docs/api/java/lang/String.html">String[] allowedPatternsStartsWith;
28
    static 1.5.0/docs/api/java/lang/String.html">String[] allowedPatternsEqual;
29
 
1 fvelez 30
    public void init(FilterConfig config)
31
    {
1830 jmachado 32
        allowedPatternsContains = config.getInitParameter("allowedPatternsContains").replaceAll(" ","").replaceAll("\t","").replaceAll("\r","").replaceAll("\n","").trim().split(",");
33
        allowedPatternsStartsWith = config.getInitParameter("allowedPatternsStartsWith").replaceAll(" ","").replaceAll("\t","").replaceAll("\r","").replaceAll("\n","").trim().split(",");
34
        allowedPatternsEqual = config.getInitParameter("allowedPatternsEqual").replaceAll(" ","").replaceAll("\t","").replaceAll("\r","").replaceAll("\n","").trim().split(",");;
1 fvelez 35
    }
36
 
1830 jmachado 37
    static 1.5.0/docs/api/java/lang/String.html">String linkSubmitLogin = Globals.SYSTEM_REDIRECTIONS_POLICY_AUTHENTICATION_ACTION;
1 fvelez 38
    /**
39
     *
40
     * @param request The servlet request we are processing
41
     * @param chain The filter chain we are processing
42
     *
43
     * @exception java.io.IOException if an input/output error occurs
44
     * @exception javax.servlet.ServletException if a servlet error occurs
45
     */
46
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
47
            throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException
48
    {
1830 jmachado 49
        //String linkLogin = Globals.SYSTEM_REDIRECTIONS_POLICY_INDEX_WELCOME;
50
 
1 fvelez 51
        HttpServletRequest hrequest = (HttpServletRequest) request;
1830 jmachado 52
 
53
        UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSessionFromRequest(hrequest);
54
        if(userSession != null && userSession.isAuthenticated())
55
        {
1 fvelez 56
            chain.doFilter(request,response);
1830 jmachado 57
            return;
58
        }
1 fvelez 59
 
697 jmachado 60
 
1830 jmachado 61
 
62
        if(hrequest.getServletPath().equals("")
63
                || hrequest.getServletPath().equals("/")
64
                || hrequest.getServletPath().startsWith(linkSubmitLogin))
65
        {
1 fvelez 66
            chain.doFilter(request,response);
1830 jmachado 67
            return;
68
        }
69
 
70
        if(FilterUtils.checkIfIsIgnoredExtension(request, hrequest))
697 jmachado 71
        {
1830 jmachado 72
            chain.doFilter(request, response);
73
            return;
697 jmachado 74
        }
1830 jmachado 75
 
76
        for(1.5.0/docs/api/java/lang/String.html">String patternEqual : allowedPatternsEqual)
1 fvelez 77
        {
1830 jmachado 78
            if(hrequest.getServletPath().equals(patternEqual))
79
            {
80
                chain.doFilter(request,response);
81
                return;
82
            }
83
        }
1771 jmachado 84
 
1830 jmachado 85
        for(1.5.0/docs/api/java/lang/String.html">String patternEqual : allowedPatternsContains)
86
        {
87
            if(hrequest.getServletPath().contains(patternEqual))
88
            {
89
                chain.doFilter(request,response);
90
                return;
91
            }
92
        }
1771 jmachado 93
 
1830 jmachado 94
        for(1.5.0/docs/api/java/lang/String.html">String patternEqual : allowedPatternsStartsWith)
95
        {
96
            if(hrequest.getServletPath().startsWith(patternEqual))
1771 jmachado 97
            {
1830 jmachado 98
                chain.doFilter(request,response);
99
                return;
1771 jmachado 100
            }
1 fvelez 101
        }
1830 jmachado 102
 
103
 
104
        logger.warn("URL nao permitido, enviando filtragem para a Super Classe UserFilter");
105
        super.doFilter(request,response,chain);
1 fvelez 106
    }
107
 
108
 
1830 jmachado 109
 
110
 
1 fvelez 111
    public void destroy()
112
    {
113
        // Nothing
114
    }
115
 
116
}