Example usage for javax.servlet FilterChain doFilter

List of usage examples for javax.servlet FilterChain doFilter

Introduction

In this page you can find the example usage for javax.servlet FilterChain doFilter.

Prototype

public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;

Source Link

Document

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.

Usage

From source file:com.glaf.core.web.filter.GZIPFilter.java

public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (isGZIPSupported(request)) {
        GZIPResponseWrapper wrappedResponse = new GZIPResponseWrapper(response);
        chain.doFilter(request, wrappedResponse);
        wrappedResponse.finishResponse();
        return;/*from  w  w w . j  av a2 s .  com*/
    }
    chain.doFilter(request, response);
}

From source file:com.sun.socialsite.web.filters.AnonymousAccessFilter.java

/**
 * If anonymous access not allowed then reject any request that does not
 * have either a SocialSite security token or an OAuth token.
 *//*from  w  w w.jav a 2s. c o m*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    log.debug("--- entering");
    if (allowAnonymous) {
        chain.doFilter(req, res);
    } else {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        log.debug(request.getMethod() + " " + request.getRequestURL().toString());
        log.debug("st=" + request.getParameter("st"));

        SecurityToken st = new AuthInfo(request).getSecurityToken();
        if (st != null && (st instanceof SocialSiteToken || st instanceof OAuthSecurityToken
                || st instanceof AssertedToken)) {
            chain.doFilter(req, res);
        } else {
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                    "No suitable security token found in request");
        }
    }
    log.debug("--- exiting");
}

From source file:MyServlet.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String password = ((HttpServletRequest) request).getParameter("password");

    if (password.equals("opensesame")) {
        chain.doFilter(request, response);
    } else {/*  w ww. ja va  2 s .co  m*/
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD>");
        out.println("<TITLE>");
        out.println("Incorrect Password");
        out.println("</TITLE>");
        out.println("</HEAD>");
        out.println("<BODY>");
        out.println("<H1>Incorrect Password</H1>");
        out.println("Sorry, that password was incorrect.");
        out.println("</BODY>");
        out.println("</HTML>");
    }
}

From source file:vlove.spring.jpa.OptionalOpenEntityManagerInViewFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (this.emfAvailable) {
        super.doFilterInternal(request, response, filterChain);
    } else {//  w  ww. j a  va  2s . c o m
        filterChain.doFilter(request, response);
    }
}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (log.isDebugEnabled()) {
        debugRequest(request);//  ww w. ja  va2 s.  c  o m
    }
    chain.doFilter(request, response);

    if (log.isDebugEnabled()) {
        debugResponse(response);
    }
}

From source file:com.framework.demo.web.filter.DebugRequestAndResponseFilter.java

public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (log.isDebugEnabled()) {
        debugRequest(request);/*from  www  .  j a va 2  s .  c om*/
    }
    chain.doFilter(request, response);

    if (log.isDebugEnabled()) {
        debugResponse(response);
    }
}

From source file:sample.ContextFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    String tenantId = getTenantId(request);
    if (tenantId == null) {
        filterChain.doFilter(request, response);
        return;//from   w ww  .  j  a va2 s  . c o m
    }
    filterChain.doFilter(new TenantAwareHttpServletRequest(request, tenantId), response);
}

From source file:com.sun.socialsite.web.filters.CustomizedPageFragmentCachingFilter.java

@Override
protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws Exception {
    if (enabled) {
        super.doFilter(request, response, chain);
    } else {// w  w  w  .j a  v a2 s  . com
        chain.doFilter(request, response);
    }
}

From source file:cz.sohlich.workstack.security.StatelessAuthenticationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    SecurityContextHolder.getContext()/*from   w  w w .j av a2 s  .  c o  m*/
            .setAuthentication(tokenAuthenticationService.getAuthentication((HttpServletRequest) request));
    chain.doFilter(request, response);
}

From source file:filter.ConexaoHibernateFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws ServletException, IOException {
    try {/*from  w w w.  j av  a 2s  .  c  om*/

        this.sf.getCurrentSession().beginTransaction();
        chain.doFilter(servletRequest, servletResponse);
        this.sf.getCurrentSession().getTransaction().commit();
        this.sf.getCurrentSession().close();
    } catch (Throwable ex) {
        try {
            if (this.sf.getCurrentSession().getTransaction().isActive()) {
                this.sf.getCurrentSession().getTransaction().rollback();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
        throw new ServletException(ex);
    }
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpSession session = request.getSession();

    // recupera o usuario adm logado da sesso
    Object login = session.getAttribute("UsuarioAtual");
    RequestDispatcher dispatcher = null;

    if (!(request.getRequestURI().equals(paginaLogin) || request.getRequestURI().equals(paginaPrimeiroAcesso)
            || request.getRequestURI().equals(paginaRecuperarSenha))) {
        if (login == null) {
            // ento envia para a pagina de acesso invalido
            dispatcher = servletRequest.getRequestDispatcher("loginEntrar.xhtml");
            dispatcher.forward(servletRequest, servletResponse);
        }

    }

}