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:de.itsvs.cwtrpc.security.AbstractRpcProcessingFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (filterProcesses((HttpServletRequest) request)) {
        process((HttpServletRequest) request, (HttpServletResponse) response, chain);
    } else {// w w  w.  ja  va2s  .com
        chain.doFilter(request, response);
    }
}

From source file:eu.freme.broker.tools.CORSFilter.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:things.view.rest.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, PUT");
    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:com.tce.spring.oauth2.filters.CorsFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization");
    response.setHeader("Access-Control-Max-Age", "3600");
    if (!"OPTIONS".equals(request.getMethod())) {
        filterChain.doFilter(request, response);
    } else {//from   w  w w  .j  ava 2 s.  c o  m
    }
}

From source file:hr.softwarecity.osijek.filters.CorsFilter.java

@Override
public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) sr1;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    fc.doFilter(sr, sr1);
}

From source file:org.brutusin.rpc.websocket.WebsocketFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    if (isDisabled || httpRequest.getRequestURI() == null
            || !(httpRequest.getRequestURI().substring(httpRequest.getContextPath().length())
                    .startsWith(RpcConfig.getInstance().getPath() + "/wskt"))) {
        chain.doFilter(request, response);
        return;//from   w ww .  j a  v  a  2s  .  co m
    }
    final Map<String, String[]> fakedParams = Collections.singletonMap("requestId",
            new String[] { String.valueOf(counter.getAndIncrement()) });
    HttpServletRequestWrapper wrappedRequest = new HttpServletRequestWrapper(httpRequest) {
        @Override
        public Map<String, String[]> getParameterMap() {
            return fakedParams;
        }
    };
    /*
     * current request is needed for getEndpointInstance(). In glassfish getEndpointInstance() is executed out this filter chain, 
     * but inside whole request-response cycle (controlled by the overall listener that sets and removes GlobalThreadLocal)
     */
    if (GlobalThreadLocal.get() == null) {
        throw new AssertionError();
    }
    Object securityContext;
    if (ClassUtils.isPresent("org.springframework.security.core.context.SecurityContextHolder",
            RpcWebInitializer.class.getClassLoader())) {
        securityContext = SecurityContextHolder.getContext();
    } else {
        securityContext = null;
    }
    GlobalThreadLocal.set(new GlobalThreadLocal(wrappedRequest, securityContext)); // override current request with the one with faked params and security context
    chain.doFilter(wrappedRequest, response);
}

From source file:uk.ac.ebi.eva.server.CORSResponseFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, accept");
    response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Max-Age", "3600");
    chain.doFilter(req, res);
}

From source file:com.omsalung.service.filter.JWTFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String token = getToken((HttpServletRequest) request);

    try {// w w  w .  j  ava 2  s .c om
        Map<String, Object> decoded = jwtVerifier.verify(token);
        for (Map.Entry<String, Object> entry : decoded.entrySet()) {
            System.out.println("key : value --> { " + entry.getKey() + " : " + entry.getValue() + " }");
        }

        chain.doFilter(request, response);
    } catch (Exception e) {
        throw new ServletException("Unauthorized: Token validation failed", e);
    }
}

From source file:com.thoughtworks.go.server.web.ConfigValidityFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws ServletException, IOException {
    long start = System.currentTimeMillis();
    final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
    try {/*w  ww.j  ava2  s  . co  m*/
        final HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        if (licenseValid(httpServletRequest, httpServletResponse)) {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    } finally {
        if (logRequestTimings)
            LOGGER.warn(httpServletRequest.getRequestURI() + " took: " + (System.currentTimeMillis() - start)
                    + " ms");
    }
}

From source file:org.jdal.auth.AuthFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    if (!isLoginPage(req) && req.getSession().getAttribute(SESSION_USER_KEY) == null) {
        // not authorized
        res.sendRedirect(req.getContextPath() + "/" + loginPage);
    } else {//w  w  w.  ja  va  2 s  .  co  m
        // authorized
        chain.doFilter(request, response);
    }

}