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.envision.envservice.filter.CertificateFilter.java

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

    if (verifyCertificate()) {
        chain.doFilter(request, response);
    } else {//from   w ww  . j ava 2  s .  c om
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        response.setContentType(MediaType.APPLICATION_JSON);
        response.getWriter().print(FailResult.toJson(Code.NO_CERTIFICATE, ""));
    }
}

From source file:io.neba.core.spring.web.filter.NebaRequestContextFilter.java

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

    ServletRequestAttributes attributes = createServletRequestAttributes(request);
    initContextHolders(request, attributes);

    try {// w ww.  j  a v a  2s.  c om
        filterChain.doFilter(request, response);
    } finally {
        resetContextHolders();
        if (logger.isDebugEnabled()) {
            logger.debug("Cleared thread-bound request context: " + request);
        }
        attributes.requestCompleted();
    }
}

From source file:com.envision.envservice.filter.AccessLogFilter.java

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

    logAccessAPI(request);//from   w w  w .  j a  v  a 2  s  . c o  m

    chain.doFilter(request, response);
}

From source file:com.qatickets.web.service.BuildVersionFilter.java

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

    HttpServletRequest req = (HttpServletRequest) request;

    req.setAttribute("BUILD_VERSION", buildVersion);
    req.setAttribute("BUILD_TIMESTAMP", buildTimestamp);

    chain.doFilter(req, response);
}

From source file:org.apereo.openlrs.OpenLRSAuthenticationFilter.java

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

    if (!enabled) {
        log.warn("Authentication is disabled");
        filterChain.doFilter(request, response);
    } else {
        String authorizationHeader = request.getHeader("Authorization");

        if (log.isDebugEnabled()) {
            log.debug(String.format("Authorization Header: %s", authorizationHeader));
        }//from w w w. j a va 2  s .c  o m

        if (StringUtils.isNotBlank(authorizationHeader)) {
            if (StringUtils.containsIgnoreCase(authorizationHeader, "oauth")) {
                authenticateOAuth(authorizationHeader, request, response, filterChain);
            } else {
                authenticateBasic(authorizationHeader, request, response, filterChain);
            }
        } else if ("OPTIONS".equals(request.getMethod())) {
            log.warn("OPTIONS request - returning no content");
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        } else {
            unauthorized(response, "Missing Authorization Header", "None");
        }
    }
}

From source file:com.thoughtworks.go.server.security.DenyGoCDAccessForArtifactsFilter.java

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

    if (isRequestFromArtifact(request) && !requestingAnArtifact(request)) {
        throw new AccessDeniedException("Denied GoCD access for requests from artifacts.");
    }/*from w  w  w  .  j  av  a  2  s . c om*/

    chain.doFilter(request, response);
}

From source file:gov.nih.nci.cabig.caaers.web.filters.XSSFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    // Skip filtering for non-HTTP requests and responses.
    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
        filterChain.doFilter(request, response);
        return;//from   w w w . j  a  v a2 s  .  c om
    }
    //Prevention of doing XSS attacks using frames, see rfc7034
    ((HttpServletResponse) response).addHeader(XFrameHeader, XFrameSetting);

    if (isAllowedURI(((HttpServletRequest) request).getRequestURI())) {
        logger.debug("Skip filtering: '" + ((HttpServletRequest) request).getRequestURI() + "'");
        filterChain.doFilter(request, response);
        return;
    }
    filterChain.doFilter(new XSSRequestWrapper((HttpServletRequest) request), response);
}

From source file:org.fornax.cartridges.sculptor.framework.accessimpl.mongodb.DbManagerFilter.java

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

    DbManager dbManager = null;/*w w  w.  ja v a2s  .  co  m*/
    try {
        dbManager = lookupDbManager();
        DbManager.setThreadInstance(dbManager);
        dbManager.requestStart();

        filterChain.doFilter(request, response);

    } finally {
        if (dbManager != null) {
            dbManager.requestDone();
            DbManager.setThreadInstance(null);
        }
    }

}

From source file:tds.student.web.filter.ConcurrentRequestLimitFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {
    final int currentRequest = concurrentRequests.incrementAndGet();
    try {/*  ww w  .j a  v  a2  s.c o  m*/
        if (maxConcurrentRequests < 0 || currentRequest <= maxConcurrentRequests) {
            filterChain.doFilter(request, response);
        } else {
            LOG.error("Rejecting request due to too many concurrent requests: {}, {}/{}",
                    request.getRequestURI(), currentRequest, maxConcurrentRequests);
            response.addHeader(HttpHeaders.RETRY_AFTER, "30");
            response.sendError(503, "Too many requests");
        }
    } finally {
        concurrentRequests.decrementAndGet();
    }
}

From source file:org.andresoviedo.util.spring.jee.HttpSessionWrapperFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    filterChain.doFilter(new HttpRequestWrapper((HttpServletRequest) request), response);
}