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.hdiv.filter.ValidatorFilter.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * /* w w w  .j a  v a2  s .c  o  m*/
 * @param requestWrapper
 *            request wrapper
 * @param responseWrapper
 *            response wrapper
 * @param filterChain
 *            filter chain
 * @throws Exception
 *             if there is an error in request process.
 */
protected void processRequest(HttpServletRequest requestWrapper, ResponseWrapper responseWrapper,
        FilterChain filterChain) throws IOException, ServletException {

    this.validationHelper.startPage(requestWrapper);
    filterChain.doFilter(requestWrapper, responseWrapper);
    this.validationHelper.endPage(requestWrapper);
}

From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.JerseyOAuth2Filter.java

public void doFilter(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    if (checkAccessControl(request, response)) {
        try {//from www  .j  a va  2s .c o  m
            filterChain.doFilter(request, response);
        } finally {
            Authenticate.unmock();
        }
    }
}

From source file:io.fabric8.apiman.BootstrapFilter.java

/**
 * No-opt filter, we really only care about the init phase to bootstrap apiman.
 *///  www . jav  a2s.c  o m
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    //no-opt, we only cared about bootstrapping on startup
    try {
        chain.doFilter(request, response);
    } finally {
        AbstractMessages.clearLocale();
    }
}

From source file:com.edgenius.wiki.security.acegi.BasicAuthenticationRequireFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    String header = request.getHeader("Authorization");
    if ((header != null) && header.startsWith("Basic ")) {
        //this user input authenticate code
        chain.doFilter(request, response);
        return;//from   w  ww  .  ja  va2s .  c  o  m
    }

    //if user does not input Basic Authentication information, then try to use HttpRequest to authenticate
    String enString = "Basic ";
    User user = userReadingService.getUserByName(request.getRemoteUser());
    if (user != null && !user.isAnonymous()) {
        enString = user.getUsername() + ":" + user.getPassword();
        enString = "Basic " + new String(Base64.encodeBase64(enString.getBytes()));
    }

    request = new AuthenticateRequestWrapper(request, enString);
    chain.doFilter(request, response);

}

From source file:com.iflytek.edu.cloud.frame.spring.DelegatingFilterProxyExt.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {
    String appkey = request.getParameter("appkey");
    if (excludeAppkeys != null && excludeAppkeys.contains(appkey)) {
        logger.debug("(appkey=" + appkey + ")??oauth?");
        filterChain.doFilter(request, response);
    } else/*from w ww.j ava  2 s .c  o m*/
        super.doFilter(request, response, filterChain);
}

From source file:com.doculibre.constellio.filters.SetCharacterEncodingFilter.java

/**
 * Select and set (if specified) the character encoding to be used to
 * interpret request parameters for this request.
 * /* w  ww  . j  a  v  a2s .  c  om*/
 * @param request
 *            The servlet request we are processing
 * @param result
 *            The servlet response we are creating
 * @param chain
 *            The filter chain we are processing
 * @exception IOException
 *                if an input/output error occurs
 * @exception ServletException
 *                if a servlet error occurs
 */
@SuppressWarnings("unchecked")
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (false) {
        chain.doFilter(request, response);
    } else {
        String lookupCharSet = lookupCharSet(request);

        SimpleParams simpleParams = new SimpleParams();
        Enumeration<String> paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = paramNames.nextElement();
            String convertedParamName = convertIfNeeded(paramName, lookupCharSet);
            String[] paramValues = request.getParameterValues(paramName);
            List<String> convertedParamValues = new ArrayList<String>();
            if (paramValues != null) {
                for (String paramValue : paramValues) {
                    String convertedParamValue = convertIfNeeded(paramValue, lookupCharSet);
                    if (convertedParamValue != null) {
                        convertedParamValues.add(convertedParamValue);
                    }
                }
            }
            simpleParams.add(convertedParamName, convertedParamValues.toArray(new String[0]));
        }
        HttpServletRequest requestWrapper = new SimpleParamsHttpServletRequestWrapper(
                (HttpServletRequest) request, simpleParams);

        // Conditionally select and set the character encoding to be used
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null) {
                request.setCharacterEncoding(encoding);
            }
        }

        // Pass control on to the next filter
        chain.doFilter(requestWrapper, response);
    }
}

From source file:ar.com.zauber.commons.web.filter.HttpRequestHeaderFilter.java

/** @see OncePerRequestFilter#doFilterInternal(
 *       HttpServletRequest, HttpServletResponse, FilterChain) */
@Override/*from   w  w w .  ja v a  2  s .  c o m*/
protected final void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {

    final String headerValue = request.getHeader(headerName);

    if (headerValue != null && isAcceptableValue(headerValue)) {
        //se contina procesando el request
        filterChain.doFilter(request, response);
    } else {
        //se detiene el proceso y redirecciona a target
        response.setStatus(statusCode);
        request.getRequestDispatcher(target).forward(request, response);
    }
}

From source file:trycb.util.CorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    chain.doFilter(req, res);
}

From source file:org.netxilia.server.security.ExcludeAjaxExceptionTranslationFilter.java

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

    try {/*from  www. j a  va2 s  .c o m*/
        chain.doFilter(request, response);

    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        // Try to extract a SpringSecurityException from the stacktrace
        Throwable[] causeChain = throwableAnalyzer.determineCauseChain(ex);
        RuntimeException ase = (AuthenticationException) throwableAnalyzer
                .getFirstThrowableOfType(AuthenticationException.class, causeChain);

        if (ase == null) {
            ase = (AccessDeniedException) throwableAnalyzer.getFirstThrowableOfType(AccessDeniedException.class,
                    causeChain);
        }

        if (ase != null) {
            handleException(request, response, chain, ase);
        } else {
            // Wrap other Exceptions. These are not expected to happen
            throw new RuntimeException(ex);
        }
    }

}