List of usage examples for org.apache.hadoop.yarn.server.webproxy.amfilter AmIpServletRequestWrapper AmIpServletRequestWrapper
public AmIpServletRequestWrapper(HttpServletRequest request, AmIpPrincipal principal)
From source file:org.apache.slider.server.appmaster.web.rest.InsecureAmFilter.java
License:Apache License
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { rejectNonHttpRequests(req);// www.j a va 2 s. c o m HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpResp = (HttpServletResponse) resp; String requestURI = httpReq.getRequestURI(); if (requestURI == null || !requestURI.startsWith(wsContextRoot)) { // hand off to the AM filter if it is not the context root super.doFilter(req, resp, chain); return; } String user = null; if (httpReq.getCookies() != null) { for (Cookie c : httpReq.getCookies()) { if (WebAppProxyServlet.PROXY_USER_COOKIE_NAME.equals(c.getName())) { user = c.getValue(); break; } } } if (user == null) { log.debug("Could not find " + WebAppProxyServlet.PROXY_USER_COOKIE_NAME + " cookie, so user will not be set"); chain.doFilter(req, resp); } else { final AmIpPrincipal principal = new AmIpPrincipal(user); ServletRequest requestWrapper = new AmIpServletRequestWrapper(httpReq, principal); chain.doFilter(requestWrapper, resp); } }
From source file:org.apache.slider.server.appmaster.web.SliderAmIpFilter.java
License:Apache License
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (!(req instanceof HttpServletRequest)) { throw new ServletException("This filter only works for HTTP/HTTPS"); }/*from w w w.ja va 2 s. co m*/ HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpResp = (HttpServletResponse) resp; if (log.isDebugEnabled()) { log.debug("Remote address for request is: " + httpReq.getRemoteAddr()); } String requestURI = httpReq.getRequestURI(); if (!isWsRequest(requestURI) && !getProxyAddresses().contains(httpReq.getRemoteAddr())) { String redirectUrl = httpResp.encodeRedirectURL(proxyUriBase + requestURI); httpResp.sendRedirect(redirectUrl); return; } String user = null; if (httpReq.getCookies() != null) { for (Cookie c : httpReq.getCookies()) { if (WebAppProxyServlet.PROXY_USER_COOKIE_NAME.equals(c.getName())) { user = c.getValue(); break; } } } try { if (user == null) { log.debug("Could not find " + WebAppProxyServlet.PROXY_USER_COOKIE_NAME + " cookie, so user will not be set"); chain.doFilter(req, resp); } else { final AmIpPrincipal principal = new AmIpPrincipal(user); ServletRequest requestWrapper = new AmIpServletRequestWrapper(httpReq, principal); chain.doFilter(requestWrapper, resp); } // JKD7 } catch (IOException | ServletException e) { } catch (IOException e) { log.warn("When fetching {}: {}", requestURI, e); throw e; } catch (ServletException e) { log.warn("When fetching {}: {}", requestURI, e); throw e; } }