List of usage examples for javax.servlet FilterChain doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
From source file:gov.nih.nci.ncicb.cadsr.umlmodelbrowser.servlets.SessionFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException { String expiredSessionJSP = filterConfig.getInitParameter("expiredSessionJSP"); HttpServletRequest httpservletrequest = (HttpServletRequest) request; HttpSession httpsession = httpservletrequest.getSession(false); if (httpsession == null && httpservletrequest.getRequestedSessionId() == null) { //This is a client accessing the first time. chain.doFilter(request, response); return;//from www . j av a 2 s .c o m } if (httpsession == null || httpservletrequest.getRequestedSessionId() == null) { ((HttpServletResponse) response).sendRedirect(httpservletrequest.getContextPath() + expiredSessionJSP); return; } else { String s = httpsession.getId(); if (s.equals(httpservletrequest.getRequestedSessionId())) { chain.doFilter(request, response); } else { ((HttpServletResponse) response) .sendRedirect(httpservletrequest.getContextPath() + expiredSessionJSP); return; } } }
From source file:de.codecentric.boot.admin.web.EndpointCorsFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { try {/*from w w w .java 2 s .c om*/ if (!endpointHandlerMapping.isDisabled() && endpointHandlerMapping.getHandler(request) != null) { response.setHeader("Access-Control-Allow-Origin", origin); response.setHeader("Access-Control-Allow-Headers", headers); } } catch (Exception ex) { LOGGER.warn("Error occured while adding CORS-Headers", ex); } filterChain.doFilter(request, response); }
From source file:kziomek.filter.logging.MvcLoggingFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (logger.isDebugEnabled()) { request = new BufferedRequestWrapper(request); response = new TeeResponseWrapper(response); }/* ww w. java 2 s . c o m*/ try { if (logger.isDebugEnabled()) { logRequest((BufferedRequestWrapper) request); } filterChain.doFilter(request, response); } finally { if (logger.isDebugEnabled()) { logResponse((TeeResponseWrapper) response); } } }
From source file:com.shopzilla.ducky.WadlXsltFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (this.requestMatcher.match(request)) { LOG.debug("adding transform"); ByteBufferResponseWrapper wrapper = new ByteBufferResponseWrapper((HttpServletResponse) response); String styleSheetPath = makeProcessingInstruction(request); chain.doFilter(request, wrapper); wrapper.getWriter().flush();//from w w w . j av a2 s . c o m String responseStr = injectStyleSheet(wrapper.toString(), styleSheetPath); response.setContentLength(responseStr.length()); PrintWriter out = response.getWriter(); out.append(responseStr); out.flush(); } else { LOG.debug("NOT adding transform"); // just pass it along chain.doFilter(request, response); } }
From source file:com.thoughtworks.go.server.newsecurity.filters.VerifyAuthorityFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { final AuthenticationToken<?> authentication = SessionUtils.getAuthenticationToken(request); final Set<GrantedAuthority> authorities = authentication.getUser().getAuthorities(); if (authorityVerifier.hasAnyAuthorityMatching(authorities)) { LOGGER.debug("User {} authorized to access {}", authentication.getUser().getUsername(), request.getRequestURI()); filterChain.doFilter(request, response); } else {//from w w w .j a va 2s .c om LOGGER.debug("User {} not authorized to access {}: has authorities {}", authentication.getUser().getUsername(), request.getRequestURI(), authentication.getUser().getAuthorities()); if (SessionUtils.getCurrentUser().asUsernameObject().isAnonymous()) { requestHandler.handle(request, response, SC_UNAUTHORIZED, "You are not authenticated!"); } else { requestHandler.handle(request, response, SC_FORBIDDEN, "You are not authorized to access this resource!"); } } }
From source file:org.craftercms.security.servlet.filters.RequestSecurityFilter.java
/** * If {@code securityEnabled}, passes the request through the chain of {@link RequestSecurityProcessor}s, * depending if the request URL//w ww . j a v a 2 s. co m * matches or not the {@code urlsToInclude} or the {@code urlsToExclude}. The last processor of the chain calls * the actual filter * chain. * * @param request * @param response * @param chain * @throws IOException * @throws ServletException */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; if (securityEnabled && (includeRequest(httpRequest) || !excludeRequest(httpRequest))) { doFilterInternal((HttpServletRequest) request, (HttpServletResponse) response, chain); } else { chain.doFilter(request, response); } }
From source file:LogFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException { HttpServletRequest req = null;//from ww w.j av a 2 s . co m String id = config.getInitParameter("log-id"); if (id == null) id = "unknown"; if (log != null && (request instanceof HttpServletRequest)) { req = (HttpServletRequest) request; log.info("Log id:" + id + ": Request received from: " + req.getRemoteHost() + " for " + req.getRequestURL()); } chain.doFilter(request, response); }
From source file:com.google.gerrit.httpd.ProjectOAuthFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; Response rsp = new Response((HttpServletResponse) response); if (verify(req, rsp)) { chain.doFilter(req, rsp); }//from w ww . j a va2 s .c o m }
From source file:com.netspective.sparx.fileupload.FileUploadFilter.java
/** * This method performs the actual filtering work .In its doFilter() method, * each filter receives the current request and response, as well as a * FilterChain containing the filters that still must be processed. Here * the doFilter() method examines the request content type, and if it is a * multipart/form-data request, wraps the request with a FileUpload class. * * @param <b> request </b> The servlet request * @param <b> response </b> The servlet response * @param <b> chain </b> Object representing the chain of all filters *//* www . j a v a 2s . co m*/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; // Get the content type from the request String content = req.getHeader("Content-Type"); // If the content type is not a multipart/form-data , continue if (content == null || !content.startsWith("multipart/form-data")) { chain.doFilter(request, response); } else { log.debug("Procesing multipart request"); FileUploadWrapper load = new FileUploadWrapper(req, uploadDir, uploadPrefix, uploadFileArg); chain.doFilter(load, response); } }
From source file:com.acc.oauth2.HybrisOauth2UserFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (containsRole(auth, ROLE_ANONYMOUS) || containsRole(auth, ROLE_CUSTOMERGROUP) || containsRole(auth, ROLE_CUSTOMERMANAGERGROUP)) { final UserModel userModel = userService.getUserForUID((String) auth.getPrincipal()); userService.setCurrentUser(userModel); }/* w w w . j ava 2 s . c om*/ chain.doFilter(request, response); }