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.ecsteam.springutils.pattern.filter.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-Methods", "POST, HEAD");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "content-type, x-requested-with");
    chain.doFilter(req, res);
}

From source file:de.thorstenberger.taskmodel.view.webapp.filter.ExportPDFFilter.java

/**
 * {@inheritDoc}//from w  w w.j a  v  a  2 s .  co  m
 */
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
        final FilterChain filterChain) throws IOException, ServletException {

    if (servletRequest.getParameter(EXPORTFILENAME) == null) {
        // don't filter!
        filterChain.doFilter(servletRequest, servletResponse);
    } else {

        // create a buffer for the rendered contents
        final ContentCaptureServletResponse wrapper = new ContentCaptureServletResponse(
                (HttpServletResponse) servletResponse);
        // call the rest of the filter chain
        filterChain.doFilter(servletRequest, wrapper);

        final Document dom = getRenderedXhtml(new String(wrapper.getBinaryContent(), Charset.forName("UTF8")));

        // call flying saucer to render xHtml to pdf
        renderPdf(dom, (HttpServletRequest) servletRequest, servletResponse);
    }
}

From source file:hudson.plugins.mercurial.MercurialStatusCrumbExclusion.java

@Override
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    String pathInfo = req.getPathInfo();
    if (StringUtils.isEmpty(pathInfo)) {
        return false;
    }/*from ww w .jav  a  2s .  co  m*/
    // in case the notifier cannot follow redirects
    pathInfo = pathInfo.endsWith("/") ? pathInfo : pathInfo + '/';
    if (!pathInfo.equals(getExclusionPath())) {
        return false;
    }
    chain.doFilter(req, resp);
    return true;
}

From source file:com.assemblade.rest.AuthenticationFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletRequest httpServletRequest = ((HttpServletRequest) servletRequest);

    String address = httpServletRequest.getRequestURI();

    if (address.endsWith("/login") || address.endsWith("/login/changepassword")) {
        filterChain.doFilter(servletRequest, servletResponse);
    } else {/*  w  ww .  ja  v a2 s.c  om*/
        String token = httpServletRequest.getParameter(OAuthConstants.CONSUMER_KEY);
        if (StringUtils.isEmpty(token)) {
            ((HttpServletResponse) servletResponse).setStatus(401);
        } else {
            try {
                AccessToken accessToken = accessTokenManager.getAccessToken(token);
                if (accessToken == null) {
                    ((HttpServletResponse) servletResponse).setStatus(401);
                } else {
                    if (checkOauthAuthentication(httpServletRequest, accessToken)) {
                        User user = new User();
                        user.setUserId(accessToken.getUid());
                        user = directoryService.getAdminSession().get(user);

                        if (user == null) {
                            ((HttpServletResponse) servletResponse).setStatus(401);
                        } else {
                            Authentication authentication = new Authentication();
                            authentication.setUser(user);
                            authentication.setBaseUrl(accessToken.getBaseUrl());
                            AuthenticationHolder.setAuthentication(authentication);
                            filterChain.doFilter(servletRequest, servletResponse);
                            AuthenticationHolder.resetAuthentication();
                        }
                    } else {
                        ((HttpServletResponse) servletResponse).setStatus(401);
                    }
                }
            } catch (StorageException e) {
                ((HttpServletResponse) servletResponse).setStatus(500);
            }
        }
    }
}

From source file:fr.aliasource.webmail.server.LoginFilter.java

private void performLoginProcedure(HttpSession s, FilterChain fc, HttpServletRequest hreq,
        HttpServletResponse resp) throws Exception {
    logger.info("performLogin(" + hreq.getRequestURI() + ")");
    if ("true".equals(settings.get(GetSettings.AJAX_LOGIN))) {
        fc.doFilter(hreq, resp);
    } else {//from  ww w . j a va  2 s. c om
        logger.info("Should perform std login procedure => sso server");
        ISSOProvider sso = getSSOProvider(s);
        if (!sso.wentToSSOServer(hreq)) {
            sso.redirectToSSOServer(computeMyUrl(hreq, resp), settings, hreq, resp);
            return;
        } else {
            Credentials creds = sso.obtainCredentials(settings, hreq);
            if (creds != null) {
                if (doLogin(s, creds.getLogin(), creds.getPassword())) {
                    fc.doFilter(hreq, resp);
                } else {
                    logger.warn("sso returned credentials, but minig-backend seems to refuse them.");
                    denyCall(hreq, resp);
                }
                return;
            } else {
                logger.warn("SSO server did not validate ticket");
                denyCall(hreq, resp);
                return;
            }
        }
    }
}

From source file:Controlador.SimpleCORSFilter.java

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-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Content-Type");
    chain.doFilter(req, res);
}

From source file:info.losd.galen.api.SimpleCORSFilter.java

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-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
    chain.doFilter(req, res);
}

From source file:it.scoppelletti.programmerpower.web.security.SingleSignOutFilter.java

/**
 * Implementazione del filtro.//  www  . ja va2  s .c  o  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 {
    String ticket;

    if (myCasClient == null) {
        throw new PropertyNotSetException(toString(), "casClient");
    }

    ticket = getTicket(req);
    if (ticket == null) {
        chain.doFilter(req, resp);
    } else {
        myCasClient.removeAuthenticatedSession(ticket);
    }
}

From source file:io.lavagna.web.security.SecurityFilter.java

@Override
protected void doFilterInternal(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    addHeaders(req, resp);//  w  w  w.  j  ava 2s  .  co  m

    for (ImmutablePair<SecurityConfiguration, List<UrlMatcher>> path : pathsToCheck.values()) {
        if (path.left.matchRequest(req)) {
            handleWith(req, resp, chain, path.right);
            return;
        }
    }

    chain.doFilter(req, resp);
}

From source file:egovframework.com.utl.wed.filter.CkFilter.java

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

    if (request.getContentType() == null || request.getContentType().indexOf("multipart") == -1) {
        // contentType ? multipart  ? .
        chain.doFilter(request, response);
    } else {/*w ww  .  j  a  v  a2 s  .  co m*/
        ckImageSaver.saveAndReturnUrlToClient(request, response);

    }
}