List of usage examples for javax.servlet FilterChain doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
From source file:com.aplikasi.penjualan.config.CsrfAttributeToCookieFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie);/*w ww . j av a2 s .co m*/ } } filterChain.doFilter(request, response); }
From source file:com.fiveamsolutions.nci.commons.web.filter.UsernameFilter.java
/** * {@inheritDoc}/* www . jav a 2s . c om*/ */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final String previousUsername = UsernameHolder.getUser(); HttpServletRequest httpRequest = (HttpServletRequest) request; String username = httpRequest.getRemoteUser(); if (caseSensitive) { UsernameHolder.setUserCaseSensitive(username); } else { UsernameHolder.setUser(username); } try { chain.doFilter(request, response); } finally { // See PO-6019. Username needs to be cleaned up after the thread is done. UsernameHolder.setUserCaseSensitive(previousUsername); } }
From source file:com.sfwl.framework.web.casclient.HttpServletRequestWrapperFilter.java
/** * Wraps the HttpServletRequest in a wrapper class that delegates * <code>request.getRemoteUser</code> to the underlying Assertion object * stored in the user session./*from w ww. jav a2 s .com*/ */ public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { // URL(js+css+img) HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; if (excepUrlPattern != null && excepUrlPattern.matcher(request.getServletPath()).matches()) { filterChain.doFilter(request, response); return; } final AttributePrincipal principal = retrievePrincipalFromSessionOrRequest(servletRequest); filterChain.doFilter(new CasHttpServletRequestWrapper((HttpServletRequest) servletRequest, principal), servletResponse); }
From source file:co.edu.utb.softeng.springtodos.config.security.CsrfHeaderFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie);/*ww w. ja v a 2s. c o m*/ } } filterChain.doFilter(request, response); }
From source file:com.tce.oauth2.spring.client.filters.SessionDataFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; // Todo Controller is not authorized for anonymous user if (req.getRequestURI().indexOf("/todos") != -1) { if (req.getSession().getAttribute("username") == null) { resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); } else {// w w w . j a va 2s . c o m filterChain.doFilter(request, response); } } else { filterChain.doFilter(request, response); } }
From source file:com.googlecode.jtiger.modules.ecside.filter.ECSideFilter.java
public void doExportFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain, WebContext context) throws IOException, ServletException { String exportFileName = ExportFilterUtils.getExportFileName(context); boolean isPrint = "_print_".equals(exportFileName); try {/* ww w.j a va 2 s . c om*/ if (isPrint) { chain.doFilter(request, response); } else { request.setAttribute(ContextUtils.RESPONSE_OUTPUTSTREAM_KEY, response.getOutputStream()); HttpServletResponseWrapper responseWrapper = new ExportResponseWrapper(response); setResponseHeaders(request, response, exportFileName); chain.doFilter(request, responseWrapper); responseWrapper = null; } handleExport(request, response, context); } catch (IOException e) { throw e; } finally { // request.setAttribute(ContextUtils.RESPONSE_OUTPUTSTREAM_KEY, // "".intern()); } }
From source file:filters.ActionValidationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String requPath = httpServletRequest.getServletPath(); /*//w w w . ja v a2 s. co m * ignore resource files (CSS, JPEG/PNG, JavaScript) ... */ if (requPath.startsWith(STATIC_RESOURCES) || requPath.startsWith(API)) { chain.doFilter(request, response); return; } /* * This filter makes only sense, if user is logged in. */ User user = AuthenticationUtils.getUser(); if (user != null && user.getName() != null) { /* * get sessions credential storage variable */ String storedCredential = (String) request.getAttribute(REQUEST_ATTRIB_CREDENTIAL); /* * if null, create new one */ if (storedCredential == null) { storedCredential = getNewCredential(user, httpServletRequest.getSession()); request.setAttribute(REQUEST_ATTRIB_CREDENTIAL, storedCredential); } log.debug("credential for " + user.getName() + " = " + storedCredential); /* * get credential from request parameter * * FIXME: This does not work with multipart-requests! Thus, on such * requests we must otherwise send the ckey. */ String requestCredential = request.getParameter(REQUEST_PARAM_CREDENTIAL); /* * check and propagate correctness */ request.setAttribute(REQUEST_ATTRIB_VALID_CREDENTIAL, storedCredential.equals(requestCredential)); } // Pass control on to the next filter chain.doFilter(request, response); }
From source file:org.apereo.openlrs.XAPIHeaderFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String allowedRequestHeaders = request.getHeader("Access-Control-Request-Headers"); String responseHeader = Constants.XAPI_VERSION_HEADER; if (StringUtils.isNotBlank(allowedRequestHeaders)) { if (StringUtils.contains(allowedRequestHeaders, Constants.XAPI_VERSION_HEADER.toLowerCase())) { responseHeader = responseHeader.toLowerCase(); }/*from w ww .j a va 2s . c o m*/ } response.addHeader(responseHeader, version); filterChain.doFilter(request, response); }
From source file:org.iqvis.nvolv3.request.filter.LoggingFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { long startTime = 0; long elapsed = 0; if (logger.isDebugEnabled()) { long requestId = id.incrementAndGet(); request = new RequestWrapper(requestId, request); response = new ResponseWrapper(requestId, response); }/*from w w w.j a v a2 s .co m*/ try { startTime = System.currentTimeMillis(); filterChain.doFilter(request, response); // response.flushBuffer(); elapsed = System.currentTimeMillis() - startTime; } finally { if (logger.isDebugEnabled()) { // logRequest(request); logResponse((ResponseWrapper) response, request, elapsed); } } }
From source file:cc.kune.core.server.rack.RackServletFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final String relative = RackHelper.getRelativeURL(request); for (final RequestMatcher matcher : excludes) { if (matcher.matches(relative)) { LOG.info("Excluded (from Guice): " + relative); chain.doFilter(request, response); return; }/*from w w w . j a v a2s .c o m*/ } LOG.debug("REQUEST: " + relative); final FilterChain newChain = new DockChain(docks.iterator()); newChain.doFilter(request, response); }