Example usage for org.apache.hadoop.yarn.server.webproxy.amfilter AmIpPrincipal AmIpPrincipal

List of usage examples for org.apache.hadoop.yarn.server.webproxy.amfilter AmIpPrincipal AmIpPrincipal

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.server.webproxy.amfilter AmIpPrincipal AmIpPrincipal.

Prototype

public AmIpPrincipal(String name) 

Source Link

Usage

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);//from   www .  j a v a  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");
    }/*w  ww . j  a v  a 2s.c  o  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;
    }
}