Search in sources :

Example 1 with SelectedCandidat

use of mom.trd.opentheso.SelectedBeans.SelectedCandidat in project opentheso by miledrousset.

the class loginFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    CurrentUser session = (CurrentUser) req.getSession().getAttribute("user1");
    String url = req.getRequestURI();
    Connexion conn = (Connexion) request.getServletContext().getAttribute("poolConnexion");
    HikariDataSource hds;
    if (url.contains("install.xhtml") || url.contains("no_connection")) {
        chain.doFilter(request, response);
        return;
    } else {
        if (conn != null) {
            hds = (HikariDataSource) conn.getPoolConnexion();
            if (hds == null) {
                resp.sendRedirect("./admin/no_connection.xhtml");
                return;
            }
        }
        if (conn == null) {
            resp.sendRedirect("./admin/no_connection.xhtml");
            return;
        }
    }
    /* if(req.getRequestedSessionId()==null || !req.isRequestedSessionIdValid()){
            req.getSession(true);
            resp.sendRedirect("/index.xhtml");
       
        }*/
    if (session != null) {
        // resp.sendRedirect("./install.xhtml");
        if (session.getConnect().getPoolConnexion() == null) {
            return;
        }
    }
    if (url.contains("deco.xhtml")) {
        CurrentUser temp = (CurrentUser) req.getSession().getAttribute("user1");
        temp.setUser(new NodeUser());
        temp.setIsLogged(false);
        req.getSession().setAttribute("user1", temp);
        ((SelectedCandidat) req.getSession().getAttribute("selectedCandidat")).reInit();
        // req.getServletContext().getContextPath());
        resp.sendRedirect("./index.xhtml");
    } else if (session == null || !session.isLogged()) {
        if (url.contains("conf.xhtml") || url.contains("gestCandidat.xhtml") || url.contains("edition.xhtml") || url.contains("statistic.xhtml")) {
            resp.sendRedirect(req.getServletContext().getContextPath());
        } else {
            chain.doFilter(request, response);
        }
    } else {
        if (url.contains("connect.xhtml")) {
            resp.sendRedirect(req.getServletContext().getContextPath());
        } else {
            chain.doFilter(request, response);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HikariDataSource(com.zaxxer.hikari.HikariDataSource) CurrentUser(mom.trd.opentheso.SelectedBeans.CurrentUser) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser) SelectedCandidat(mom.trd.opentheso.SelectedBeans.SelectedCandidat) HttpServletResponse(javax.servlet.http.HttpServletResponse) Connexion(mom.trd.opentheso.bdd.helper.Connexion)

Aggregations

HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CurrentUser (mom.trd.opentheso.SelectedBeans.CurrentUser)1 SelectedCandidat (mom.trd.opentheso.SelectedBeans.SelectedCandidat)1 Connexion (mom.trd.opentheso.bdd.helper.Connexion)1 NodeUser (mom.trd.opentheso.bdd.helper.nodes.NodeUser)1