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:org.xmlactions.web.PagerFilter.java

public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain chain)
        throws IOException, ServletException {
    logger.debug("PagerFilter.doFilter");

    MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    PagerServlet pagerServlet = new PagerServlet();
    try {/*from   ww  w. j a v  a  2s.c om*/
        pagerServlet.init(filterConfig);
        if (req instanceof HttpServletRequest && rsp instanceof HttpServletResponse) {
            pagerServlet.setupExecContext((HttpServletRequest) req, (HttpServletResponse) rsp);
        }
        chain.doFilter(req, mockResponse);
        RequestExecContext.remove();
    } catch (FileUploadException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    } finally {
        String page = mockResponse.getContentAsString();
        pagerServlet.processPageFromFilter(req, rsp, page);
    }
}

From source file:org.obiba.shiro.web.filter.AuthenticationFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    if (ThreadContext.getSubject() != null) {
        log.warn("Previous executing subject was not properly unbound from executing thread. Unbinding now.");
        ThreadContext.unbindSubject();//  w ww  .j  av a  2  s. c om
    }

    try {
        authenticateAndBind(request);
        filterChain.doFilter(request, response);
    } catch (AuthenticationException e) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (Exception e) {
        log.error("Exception", e);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        response.getWriter().println(e.getMessage());
    } finally {
        unbind();
    }
}

From source file:com.salesmanager.core.security.JAASCustomerSecurityFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.setHeader("Cache-Control", "no-cache");
    resp.setHeader("Pragma", "no-cache");
    resp.setDateHeader("Expires", 0);
    String url = req.getRequestURI();
    if (isEscapeUrlFromFilter(url) || url.endsWith(".css") || url.endsWith(".js")) {
        chain.doFilter(request, response);
        return;/* www .  j  av a 2 s  .c  o  m*/
    }

    String authToken = request.getParameter(CUSTOMER_AUTH_TOKEN);
    if (StringUtils.isBlank(authToken)) {

        HttpSession session = req.getSession();
        if (session == null) {
            resp.sendRedirect(getLogonPage(req));
        } else {
            if (session.getAttribute(SecurityConstants.SM_CUSTOMER_USER) != null) {
                chain.doFilter(request, response);
            } else {
                resp.sendRedirect(getLogonPage(req));
            }
        }
    } else {
        if (logonModule.isValidAuthToken(authToken)) {
            chain.doFilter(request, response);
        } else {
            ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.filters.JSessionStripFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse hResponse = (HttpServletResponse) response;
    HttpServletRequest hRequest = (HttpServletRequest) request;
    hRequest.setAttribute(USING_JSESSION_STRIP, "true");

    if (hResponse.isCommitted()) {
        log.error("response is comitted cannot forward "
                + " (check you haven't done anything to the response (ie, written to it) before here)");
        return;/*w  ww  .  j  a  v a2  s . c  om*/
    }
    chain.doFilter(hRequest, new StripSessionIdWrapper(hResponse));

}

From source file:edu.cornell.mannlib.vitro.webapp.filters.RequestModelsPrep.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;

    // If we're not authorized for this request, skip the chain and
    // redirect.//from   w  w  w.j a v a  2s .c  om
    if (!ModelSwitcher.authorizedForSpecialModel(req)) {
        VitroHttpServlet.redirectUnauthorizedRequest(req, resp);
        return;
    }

    try {
        setCollator(new VitroRequest(req));
        filterChain.doFilter(req, resp);
    } finally {
        if (ModelAccess.isPresent(req)) {
            ModelAccess.on(req).close();
        }
    }
}

From source file:org.sharetask.utility.log.LogUidFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    try {/*from   www. j av  a  2 s .  c o  m*/
        final SecurityContext context = SecurityContextHolder.getContext();
        String uid = null;
        if (context != null) {
            final Authentication authentication = context.getAuthentication();
            if (authentication != null) {
                uid = context.getAuthentication().getName();
            }
        }
        MDC.put(identifiert, uid == null ? NOT_KNOWN : uid);
        chain.doFilter(request, response);
    } finally {
        MDC.remove(identifiert);
    }
}

From source file:org.deegree.securityproxy.authentication.wass.AddParameterAnonymousAuthenticationFilter.java

@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        FilterChain chain, Authentication authResult) throws IOException, ServletException {
    LOG.debug("Authentication was successful, request will be modified if required!");
    String method = request.getMethod();
    if (isGetRequestedAndSupported(method))
        addParameter(request, authResult);
    else if (isPostRequestedAndSupported(method)) {
        modifyPostBody(request, authResult);
    }//from   w  w  w .jav  a  2  s . co  m
    chain.doFilter(request, response);
}

From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.filter.UserInfoFilter.java

@Override
public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain)
        throws IOException, ServletException {
    HttpServletRequest servletRequest = (HttpServletRequest) inRequest;
    String remoteUser = servletRequest.getRemoteUser();
    boolean userIsActivated = false;
    if (!StringUtils.isEmpty(remoteUser)) {
        User user = (User) inRequest.getAttribute("user");
        if (user != null && user.isActive()) {
            userIsActivated = true;/*  ww  w .j  a  v  a 2  s.c  o  m*/
        }
    }

    inRequest.setAttribute("userIsActivated", userIsActivated);
    inFilterChain.doFilter(inRequest, inResponse);
}