List of usage examples for javax.servlet FilterChain doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
From source file:io.zipi.common.servlet.AuthenticationFilter.java
/** * Further process the filter chain./*from w w w. ja v a2s. co m*/ * @param request the request * @param response the response * @param chain the filter chain * @param principal the auth principal * @throws IOException when I/O failure occurs in filter chain * @throws ServletException when servlet exception occurs during auth */ protected void doFilterChain(ServletRequest request, ServletResponse response, FilterChain chain, AuthPrincipal principal) throws IOException, ServletException { if (principal == null) { chain.doFilter(request, response); } else { HttpServletRequest hsr; hsr = wrapTheRequest(request, principal); chain.doFilter(hsr, response); } }
From source file:org.imsglobal.basiclti.provider.servlet.filter.BasicLTISecurityFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { doFilter((HttpServletRequest) request, (HttpServletResponse) response, chain); } else {//from w w w .j av a 2 s . co m chain.doFilter(request, response); } }
From source file:CheckFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Enumeration params = request.getParameterNames(); boolean rejected = false; while (params.hasMoreElements()) { if (isEmpty(request.getParameter((String) params.nextElement()))) { reject(request, response);/* w ww .j a v a 2 s. c om*/ rejected = true; } } if (!rejected) chain.doFilter(request, response); }
From source file:com.sample.ecommerce.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,PUT,PATCH, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); chain.doFilter(req, res); }
From source file:com.lnu.agile.config.filter.SimpleCORSFIlter.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, GET, OPTIONS, DELETE, PUT"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); chain.doFilter(req, res); }
From source file:com.ms.app.web.commons.pagecache.PageCacheManager.java
/** * Builds the PageInfo object by passing the request along the filter chain * // w ww. ja v a 2 s . c om * @param request * @param response * @param chain * @return a Serializable value object for the page or page fragment * @throws Exception */ protected PageInfo buildPage(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); final PageCacheResponseWrapper wrapper = new PageCacheResponseWrapper(response, outstr); // chain.doFilter(request, wrapper); wrapper.flush(); // Return the page info return new PageInfo(wrapper.getContentType(), outstr.toByteArray(), wrapper.getStatus()); }
From source file:com.jaspersoft.jasperserver.war.util.SessionDecoratorFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String sessionDecorator = request.getParameter(SESSION_DECORATOR); if (!StringUtils.isEmpty(sessionDecorator)) { if (request instanceof HttpServletRequest) { HttpSession session = ((HttpServletRequest) request).getSession(); session.setAttribute(SESSION_DECORATOR, sessionDecorator); }/*from w w w . j a v a2s . co m*/ } chain.doFilter(request, response); }
From source file:org.openmhealth.reference.filter.ExceptionFilter.java
/** * <p>//from www. ja v a 2 s . c o m * If the request throws an exception, specifically a OmhException, * attempt to respond with that message from the exception. * </p> * * <p> * For example, HTTP responses have their status codes changed to * {@link HttpServletResponse#SC_BAD_REQUEST} and the body of the response * is the error message. * </p> */ @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { // Get a handler for the correct exception type. Throwable exception = null; // Always let the request continue but setup to catch exceptions. try { chain.doFilter(request, response); } // The servlet container may wrap the exception, in which case we // must first unwrap it, then delegate it. catch (NestedServletException e) { // Get the underlying cause. Throwable cause = e.getCause(); // If the underlying exception is one of ours, then store the // underlying exception. if (cause instanceof OmhException) { exception = cause; } // Otherwise, store this exception. else { exception = e; } } // Otherwise, store the exception, catch (Exception e) { exception = e; } // If an exception was thrown, attempt to handle it. if (exception != null) { // Save the exception in the request. request.setAttribute(ATTRIBUTE_KEY_EXCEPTION, exception); // Handle the exception. if (exception instanceof NoSuchSchemaException) { LOGGER.log(Level.INFO, "An unknown schema was requested.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_NOT_FOUND, exception.getMessage()); } else if (exception instanceof InvalidAuthenticationException) { LOGGER.log(Level.INFO, "A user's authentication information was invalid.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_UNAUTHORIZED, exception.getMessage()); } else if (exception instanceof InvalidAuthorizationException) { LOGGER.log(Level.INFO, "A user's authorization information was invalid.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_UNAUTHORIZED, exception.getMessage()); } else if (exception instanceof OmhException) { LOGGER.log(Level.INFO, "An invalid request was made.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_BAD_REQUEST, exception.getMessage()); } // If the exception was not one of ours, the server must have // crashed. else { LOGGER.log(Level.SEVERE, "The server threw an unexpected exception.", exception); // Respond to the user. sendResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null); } } }
From source file:com.mothsoft.alexis.web.security.TermsOfServiceFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { final HttpSession session = request.getSession(false); final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated() || ANONYMOUS_USER.equals(authentication.getName()) || isStaticContent(request)) { chain.doFilter(request, response); return;/*w ww . j a v a2s . c o m*/ } if (session.getAttribute(TOS_KEY) == null) { final UserAuthenticationDetails details = (UserAuthenticationDetails) SecurityContextHolder.getContext() .getAuthentication().getPrincipal(); final Long userId = details.getUserId(); final User user = this.userService.getUser(userId); if (user.getTosAcceptDate() != null) { session.setAttribute(TOS_KEY, user.getTosAcceptDate()); } } if (session.getAttribute(TOS_KEY) == null && !request.getRequestURI().equals(TERMS_OF_SERVICE_URI)) { response.sendRedirect(TERMS_OF_SERVICE_URI); return; } chain.doFilter(request, response); }
From source file:at.ac.univie.isc.asio.insight.ExplorerPageRedirectFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException { final String redirect = template.findRedirectTarget(request); final String original = request.getRequestURI(); if (redirect == null) { // skip redirect log.debug(Scope.REQUEST.marker(), "not an explorer request ({}) - skip redirecting", original); chain.doFilter(request, response); return;/*from www . java 2 s . co m*/ } assert redirect.startsWith("/") : "redirect target is not an absolute path"; final RequestDispatcher dispatcher = request.getRequestDispatcher(redirect); if (dispatcher == null) { // redirect cannot be handled final String message = Pretty.format("no handler for request to <%s> (redirected from <%s>) found", redirect, original); log.debug(Scope.REQUEST.marker(), message); if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, message); } return; } log.debug(Scope.REQUEST.marker(), "redirect request from {} to {}", original, redirect); dispatcher.forward(request, response); }