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.sentinel.config.StatelessAuthenticationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    LOG.trace("Method: doFilter called.");

    Authentication authentication = tokenAuthenticationService.getAuthentication((HttpServletRequest) request);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    chain.doFilter(request, response);
    // SecurityContextHolder.getContext().setAuthentication( null );

    LOG.trace("Method: doFilter finished.");
}

From source file:it.geosolutions.geostore.services.rest.security.GeoStoreAuthenticationFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    if (req instanceof HttpServletRequest) {
        authenticate((HttpServletRequest) req);
    }// w  w  w.j a  v  a  2s.c o  m
    chain.doFilter(req, resp);
}

From source file:org.kmnet.com.fw.web.logging.mdc.AbstractMDCPutFilter.java

/**
 * Stores the information in {@link MDC} and calls the next filter in chain. Information fetching is to be implemented in
 * subclass of this class./*  w ww.  j  a  va 2  s  .  c  o  m*/
 * @param request {@link HttpServletRequest}
 * @param response {@link HttpServletResponse}
 * @param filterChain {@link FilterChain}
 * @throws ServletException If {@link ServletException} occurs in further in the execution chain
 * @throws IOException If {@link IOException} occurs in further in the execution chain
 * @see org.springframework.web.filter.OncePerRequestFilter#doFilterInternal(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain)
 */
@Override
protected final void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    String key = getMDCKey(request, response);
    String value = getMDCValue(request, response);
    MDC.put(key, cutValue(value));
    try {
        filterChain.doFilter(request, response);
    } finally {
        if (removeValue) {
            MDC.remove(key);
        }
    }
}

From source file:edu.cornell.mannlib.oce.filters.FakeLoginFilter.java

@Override
public void doFilter(ServletRequest rawReq, ServletResponse rawResp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) rawReq;
    HttpServletResponse resp = (HttpServletResponse) rawResp;

    if (isImageRequest(req)) {
        chain.doFilter(req, resp);
    } else if (isLoggedIn(req)) {
        chain.doFilter(new LoggedInRequest(req), resp);
    } else if (isLoggingIn(req)) {
        acceptLoginInfo(req);//from  www  . j a va2  s. co  m
        chain.doFilter(new LoggedInRequest(req), resp);
    } else {
        sendToLoginScreen(req, resp);
    }
}

From source file:com.adobe.acs.commons.forms.impl.FormsPostSlingFilterImpl.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    if (!(servletRequest instanceof SlingHttpServletRequest)
            || !(servletResponse instanceof SlingHttpServletResponse)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;/*w  w  w.ja va  2 s . c om*/
    }

    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

    /**
     * Fail fast and early!
     *
     * Must be:
     *  - HTTP POST Request
     *  - Have Forms Sling Suffix
     *    - At this point, 99% of includes will be passed over
     *  - Must contain Form Resource Query Parameter
     */

    if (!StringUtils.equals("POST", slingRequest.getMethod()) || !formHelper.hasValidSuffix(slingRequest)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    final String formResource = this.getParameter(slingRequest, FormHelper.FORM_RESOURCE_INPUT);
    if (formResource == null || slingRequest.getResourceResolver().resolve(formResource) == null) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    String formSelector = formHelper.getFormSelector(slingRequest);
    if (formSelector == null) {
        formSelector = FormHelper.DEFAULT_FORM_SELECTOR;
    }

    final RequestDispatcherOptions options = new RequestDispatcherOptions();

    options.setReplaceSelectors(formSelector);
    options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix());

    if (log.isDebugEnabled()) {
        log.debug("Form Filter; Internal forward to path: {} ", formResource);
        log.debug("Form Filter; Internal forward w/ replace selectors: {} ", options.getReplaceSelectors());
        log.debug("Form Filter; Internal forward w/ suffix: {} ", options.getReplaceSuffix());
    }

    slingRequest.getRequestDispatcher(formResource, options).forward(slingRequest, slingResponse);
}

From source file:it.scoppelletti.programmerpower.web.rest.RestServerFilter.java

/**
 * Filtro di una richiesta.//from ww w .j a v  a 2 s  .  co m
 * 
 * @param req   Richiesta.
 * @param resp  Risposta.
 * @param chain Catena dei filtri.
 */
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpReq;
    HttpServletResponse httpResp;

    if (!(req instanceof HttpServletRequest)) {
        myLogger.warn("No HTTP request.");
        chain.doFilter(req, resp);
        return;
    }
    if (!(resp instanceof HttpServletResponse)) {
        myLogger.warn("No HTTP response.");
        chain.doFilter(req, resp);
        return;
    }

    httpReq = (HttpServletRequest) req;
    httpResp = (HttpServletResponse) resp;

    myAdapter.service(httpReq, httpResp);
}

From source file:alpine.filters.ContentSecurityPolicyFilter.java

@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletResponse response = (HttpServletResponse) res;
    chain.doFilter(req, response);
    response.addHeader("Content-Security-Policy", policy);
}

From source file:com.thoughtworks.go.server.newsecurity.filters.AccessTokenAuthenticationFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws IOException, ServletException {
    if (isPreviouslyAuthenticated(request)) {
        LOGGER.debug("Request is already authenticated.");
        filterChain.doFilter(request, response);
        return;/*from  w w  w.  ja v a 2  s  .c o  m*/
    }

    AccessTokenCredential credential;
    try {
        credential = extractAuthTokenCredential(request.getHeader("Authorization"));
    } catch (Exception e) {
        onAuthenticationFailure(request, response, e.getMessage());
        return;
    }

    if (credential != null) {
        LOGGER.debug("[Bearer Authentication] Authorization header found for user '{}'",
                credential.getAccessToken().getUsername());
    }

    LOGGER.debug("Security Enabled: " + securityService.isSecurityEnabled());
    if (securityService.isSecurityEnabled()) {
        filterWhenSecurityEnabled(request, response, filterChain, credential);
    } else {
        filterWhenSecurityDisabled(request, response, filterChain, credential);
    }
}

From source file:de.micromata.genome.logging.web.MultipleReadRequestWrapperFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    ServletRequest wrappedRequest = servletRequest;
    if (servletRequest instanceof HttpServletRequest) {
        wrappedRequest = new MultipleReadRequestWrapper((HttpServletRequest) servletRequest, maxCacheSize);
    }//from   ww  w . j a  v  a2s. c o m

    filterChain.doFilter(wrappedRequest, servletResponse);
}

From source file:UpperCaseFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    ServletResponse newResponse = response;

    if (request instanceof HttpServletRequest) {
        newResponse = new CharResponseWrapper((HttpServletResponse) response);
    }//  www .  j a  v  a 2s  . co m

    chain.doFilter(request, newResponse);

    if (newResponse instanceof CharResponseWrapper) {
        String text = newResponse.toString();
        if (text != null) {
            text = text.toUpperCase();
            response.getWriter().write(text);
        }
    }
}