List of usage examples for javax.servlet FilterChain doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
From source file:com.netease.channel.security.AuthenticatorFilter.java
@Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { LOG.debug("login Filter!!!"); login("qmgeng@corp.netease.com"); try {//from w w w . j a v a 2 s .c o m arg2.doFilter(arg0, arg1); } catch (Exception e) { LOG.error(e); } return; // HttpServletRequest request = (HttpServletRequest) arg0; // HttpServletResponse response = (HttpServletResponse) arg1; // String assoc_handle = (String) request.getSession().getAttribute(LoginUtil.ASSOC_HANDLE); // String mac_key = (String) request.getSession().getAttribute(LoginUtil.MAC_KEY); // String passport = LoginUtil.getSessionLoginStatus(request); // // String originurl = // request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString()); // // try { // if (StringUtils.isEmpty(assoc_handle) || StringUtils.isEmpty(mac_key)) { // LOG.debug("first"); // OpenidAuth consumer = new OpenidAuth(); // Map<String, String> asso = consumer.association(); // String redirecturl = consumer.authentication(originurl, realm, asso.get(LoginUtil.ASSOC_HANDLE)); // // request.getSession().setAttribute(LoginUtil.ASSOC_HANDLE, asso.get(LoginUtil.ASSOC_HANDLE)); // request.getSession().setAttribute(LoginUtil.MAC_KEY, asso.get(LoginUtil.MAC_KEY)); // // request.getSession().setMaxInactiveInterval(Integer.parseInt(asso.get(LoginUtil.EXPIRES_IN))-10); // // // session // response.sendRedirect(redirecturl); // return; // } else if (StringUtils.isEmpty(passport)) { // OpenidAuth consumer = new OpenidAuth(); // Map<String, String> dataMap = consumer.check_signature(originurl, assoc_handle, mac_key); // if (dataMap != null && !StringUtils.isEmpty(dataMap.get("email")) // && !StringUtils.isEmpty(dataMap.get("returnto"))) { // request.getSession().setAttribute(LoginUtil.SESSION_USER_NAME, dataMap.get("email")); // request.getSession().setAttribute(LoginUtil.CHINESEUSERNAME, dataMap.get("fullname")); // response.sendRedirect(dataMap.get("returnto")); // return; // } // // ?? // LOG.error("?url=" + originurl); // request.getSession().setAttribute(LoginUtil.ASSOC_HANDLE, null); // request.getSession().setAttribute(LoginUtil.MAC_KEY, null); // } else { // request.setAttribute(LoginUtil.USER_NAME, passport); // try { // LOG.debug("Login-User:" + passport); // login(passport); // arg2.doFilter(arg0, arg1); // } catch (Exception e) { // LOG.error(e); // } // return; // } // } catch (Exception e) { // request.getSession().setAttribute(LoginUtil.ASSOC_HANDLE, null); // request.getSession().setAttribute(LoginUtil.MAC_KEY, null); // request.getSession().setAttribute(LoginUtil.SESSION_USER_NAME, null); // LOG.error("?: ", e); // response.sendRedirect("/unLogin.do"); // } }
From source file:jp.co.opentone.bsol.framework.web.filter.GZipFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (isFiltered(req)) { chain.doFilter(req, res); return;// w w w . jav a 2 s .c om } req.setAttribute(FILTERED, "true"); if (!isCompressionSupported(req)) { chain.doFilter(req, res); return; } GZipResponseWrapper wrapper = new GZipResponseWrapper(res); try { chain.doFilter(req, wrapper); } finally { wrapper.finish(); } }
From source file:com.binarybirchtree.filters.IpFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { // Do not block localhost. if (request.getRemoteAddr().equals("127.0.0.1")) { filterChain.doFilter(request, response); return;//from ww w.ja v a 2s .com } boolean allowed = true; // Refuse connections that circumvented Cloudflare. // Checking the latest IP from the X-Forwarded-For header on Heroku, since request.getRemoteAddr() seems to return an IP in Heroku's internal network. if (!ipIsInList(request.getRemoteAddr(), internalIps) || (getForwardedIp(request, 1) != null && !ipIsInList(getForwardedIp(request, 1), bypassCloudflareIps) && !ipIsInList(getForwardedIp(request, 1), cloudflareIps))) allowed = false; if (allowed) { // Check if the IP before Cloudflare is blacklisted. String proxiedIp = getForwardedIp(request, 2); if (proxiedIp != null) { for (String ip : blacklistIps) { SubnetUtils subnet = new SubnetUtils(ip); subnet.setInclusiveHostCount(true); if (!subnet.getInfo().isInRange(proxiedIp)) { allowed = false; break; } } } } // If the request failed one of the tests, send an error response and do not continue processing the request. if (!allowed) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return; } // If the request passed the tests, allow it to be processed normally. filterChain.doFilter(request, response); }
From source file:org.mitre.openid.connect.web.SAMLEntryPoint.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { FilterInvocation fi = new FilterInvocation(request, response, chain); if (processFilter(fi.getRequest())) { logger.debug("une requte EIDAS=" + fi.getRequestUrl()); }/*from w ww .ja v a2 s .c om*/ chain.doFilter(request, response); }
From source file:br.gov.frameworkdemoiselle.util.BasicAuthFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {//from w ww . j a v a 2s .c o m boolean isLoggedIn = performLogin(getAuthHeader(request), (HttpServletRequest) request); chain.doFilter(request, response); if (isLoggedIn) { performLogout(); } } catch (InvalidCredentialsException cause) { setUnauthorizedStatus((HttpServletResponse) response, cause); } }
From source file:io.scigraph.services.jersey.dynamic.SwaggerFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Capture the output of the filter chain ByteArrayResponseWrapper wrappedResp = new ByteArrayResponseWrapper((HttpServletResponse) response); chain.doFilter(request, wrappedResp); if (isGzip(request)) { try (InputStream is = new ByteArrayInputStream(wrappedResp.getBytes()); GZIPInputStream gis = new GZIPInputStream(is); ByteArrayOutputStream bs = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(bs)) { byte[] newApi = writeDynamicResource(gis); gzos.write(newApi);// w ww .ja v a 2 s .c o m gzos.close(); byte[] output = bs.toByteArray(); response.setContentLength(output.length); response.getOutputStream().write(output); } } else { try (InputStream is = new ByteArrayInputStream(wrappedResp.getBytes()); ByteArrayOutputStream bs = new ByteArrayOutputStream()) { byte[] newApi = writeDynamicResource(is); response.setContentLength(newApi.length); response.getOutputStream().write(newApi); } } }
From source file:cc.kune.core.server.rack.filters.LogFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { long start;/* ww w . j av a 2s . c om*/ if (logduration) { start = System.currentTimeMillis(); } final String uri = RackHelper.getURI(request); LOG.debug("REQUEST: " + uri); chain.doFilter(request, response); if (logduration) { final long finish = System.currentTimeMillis(); LOG.debug("Total time '" + uri + "': " + (finish - start) + " miliseconds"); } }
From source file:com.thoughtworks.go.server.newsecurity.filters.AccessTokenAuthenticationFilter.java
private void filterWhenSecurityDisabled(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain, AccessTokenCredential accessTokenCredential) throws IOException, ServletException { if (accessTokenCredential == null) { filterChain.doFilter(request, response); } else {/* w w w.j a va 2s . c o m*/ onAuthenticationFailure(request, response, "Bearer authentication credentials are not required, since security has been disabled on this server."); } }
From source file:com.supinfo.supfriends.web.filter.ProtectorFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean validCredentials = false; String path = ((HttpServletRequest) request).getRequestURI(); if (isFullyAuthorizedUrl(path)) { chain.doFilter(request, response); return;// ww w . j ava 2s .c o m } HttpSession session = ((HttpServletRequest) request).getSession(); if (session.getAttribute("id") != null && session.getAttribute("username") != null && session.getAttribute("password") != null) { UserEntity user = userFacade.find((Long) session.getAttribute("id")); if (user != null) { if (user.getPassword().equals(session.getAttribute("password"))) { validCredentials = true; } } } if (validCredentials) { chain.doFilter(request, response); } else { ((HttpServletResponse) response).sendRedirect(ServerConfig.CONTEXT_URL + "/faces/login.xhtml"); } }
From source file:MyServlet.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { GregorianCalendar calendar = new GregorianCalendar(); Date date1 = new Date(); calendar.setTime(date1);//www . j ava 2 s.co m int hour = calendar.get(Calendar.HOUR_OF_DAY); if (hour < 9 || hour > 17) { chain.doFilter(request, response); } else { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("Get Back to Work!"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>Get Back to Work!</H1>"); out.println("Sorry, that resource is not available now."); out.println("</BODY>"); out.println("</HTML>"); } }