Java 类org.apache.hadoop.security.authentication.client.PseudoAuthenticator 实例源码

项目:hadoop    文件:PseudoAuthenticationHandler.java   
private String getUserName(HttpServletRequest request) {
  List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
  if (list != null) {
    for (NameValuePair nv : list) {
      if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
        return nv.getValue();
      }
    }
  }
  return null;
}
项目:hadoop    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user");

    AuthenticationToken token = handler.authenticate(request, response);

    Assert.assertNotNull(token);
    Assert.assertEquals("user", token.getUserName());
    Assert.assertEquals("user", token.getName());
    Assert.assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user");

    AuthenticationToken token = handler.authenticate(request, response);

    Assert.assertNotNull(token);
    Assert.assertEquals("user", token.getUserName());
    Assert.assertEquals("user", token.getName());
    Assert.assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:big-c    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user");

    AuthenticationToken token = handler.authenticate(request, response);

    Assert.assertNotNull(token);
    Assert.assertEquals("user", token.getUserName());
    Assert.assertEquals("user", token.getName());
    Assert.assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user");

    AuthenticationToken token = handler.authenticate(request, response);

    Assert.assertNotNull(token);
    Assert.assertEquals("user", token.getUserName());
    Assert.assertEquals("user", token.getName());
    Assert.assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hadoop-plus    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user");

    AuthenticationToken token = handler.authenticate(request, response);

    assertNotNull(token);
    assertEquals("user", token.getUserName());
    assertEquals("user", token.getName());
    assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hops    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user");

    AuthenticationToken token = handler.authenticate(request, response);

    Assert.assertNotNull(token);
    Assert.assertEquals("user", token.getUserName());
    Assert.assertEquals("user", token.getName());
    Assert.assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hadoop-TCP    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user");

    AuthenticationToken token = handler.authenticate(request, response);

    assertNotNull(token);
    assertEquals("user", token.getUserName());
    assertEquals("user", token.getName());
    assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hadoop-on-lustre    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user");

    AuthenticationToken token = handler.authenticate(request, response);

    assertNotNull(token);
    assertEquals("user", token.getUserName());
    assertEquals("user", token.getName());
    assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hardfs    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user");

    AuthenticationToken token = handler.authenticate(request, response);

    assertNotNull(token);
    assertEquals("user", token.getUserName());
    assertEquals("user", token.getName());
    assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hadoop-on-lustre2    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getQueryString()).thenReturn(PseudoAuthenticator.USER_NAME + "=" + "user");

    AuthenticationToken token = handler.authenticate(request, response);

    Assert.assertNotNull(token);
    Assert.assertEquals("user", token.getUserName());
    Assert.assertEquals("user", token.getName());
    Assert.assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hortonworks-extension    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user");

    AuthenticationToken token = handler.authenticate(request, response);

    assertNotNull(token);
    assertEquals("user", token.getUserName());
    assertEquals("user", token.getName());
    assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hortonworks-extension    文件:TestPseudoAuthenticationHandler.java   
private void _testUserName(boolean anonymous) throws Exception {
  PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();
  try {
    Properties props = new Properties();
    props.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, Boolean.toString(anonymous));
    handler.init(props);

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter(PseudoAuthenticator.USER_NAME)).thenReturn("user");

    AuthenticationToken token = handler.authenticate(request, response);

    assertNotNull(token);
    assertEquals("user", token.getUserName());
    assertEquals("user", token.getName());
    assertEquals(PseudoAuthenticationHandler.TYPE, token.getType());
  } finally {
    handler.destroy();
  }
}
项目:hadoop-oss    文件:PseudoDelegationTokenAuthenticator.java   
public PseudoDelegationTokenAuthenticator() {
  super(new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getCurrentUser().getShortUserName();
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  });
}
项目:hadoop    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hadoop    文件:PseudoDelegationTokenAuthenticator.java   
public PseudoDelegationTokenAuthenticator() {
  super(new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getCurrentUser().getShortUserName();
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  });
}
项目:aliyun-oss-hadoop-fs    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:aliyun-oss-hadoop-fs    文件:PseudoDelegationTokenAuthenticator.java   
public PseudoDelegationTokenAuthenticator() {
  super(new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getCurrentUser().getShortUserName();
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  });
}
项目:aliyun-oss-hadoop-fs    文件:PseudoAuthenticationHandler.java   
private String getUserName(HttpServletRequest request) {
  String queryString = request.getQueryString();
  if(queryString == null || queryString.length() == 0) {
    return null;
  }
  List<NameValuePair> list = URLEncodedUtils.parse(queryString, UTF8_CHARSET);
  if (list != null) {
    for (NameValuePair nv : list) {
      if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
        return nv.getValue();
      }
    }
  }
  return null;
}
项目:big-c    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:big-c    文件:PseudoDelegationTokenAuthenticator.java   
public PseudoDelegationTokenAuthenticator() {
  super(new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getCurrentUser().getShortUserName();
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  });
}
项目:big-c    文件:PseudoAuthenticationHandler.java   
private String getUserName(HttpServletRequest request) {
  List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
  if (list != null) {
    for (NameValuePair nv : list) {
      if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
        return nv.getValue();
      }
    }
  }
  return null;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hadoop-2.6.0-cdh5.4.3    文件:PseudoDelegationTokenAuthenticator.java   
public PseudoDelegationTokenAuthenticator() {
  super(new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getCurrentUser().getShortUserName();
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  });
}
项目:hadoop-2.6.0-cdh5.4.3    文件:PseudoAuthenticationHandler.java   
private String getUserName(HttpServletRequest request) {
  List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
  if (list != null) {
    for (NameValuePair nv : list) {
      if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
        return nv.getValue();
      }
    }
  }
  return null;
}
项目:sqoop-on-spark    文件:RequestContext.java   
/**
 * Get username specified by custom username HTTP header.
 *
 * @return Name of user sending the request
 */
public String getUserName() {
  if (AuthenticationManager.getAuthenticationHandler().isSecurityEnabled()) {
    return HttpUserGroupInformation.get().getShortUserName();
  } else {
    return request.getParameter(PseudoAuthenticator.USER_NAME);
  }
}
项目:hadoop-plus    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:FlexMap    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hops    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hops    文件:PseudoDelegationTokenAuthenticator.java   
public PseudoDelegationTokenAuthenticator() {
  super(new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getCurrentUser().getShortUserName();
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  });
}
项目:hops    文件:PseudoAuthenticationHandler.java   
private String getUserName(HttpServletRequest request) {
  String queryString = request.getQueryString();
  if(queryString == null || queryString.length() == 0) {
    return null;
  }
  List<NameValuePair> list = URLEncodedUtils.parse(queryString, UTF8_CHARSET);
  if (list != null) {
    for (NameValuePair nv : list) {
      if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
        return nv.getValue();
      }
    }
  }
  return null;
}
项目:hadoop-TCP    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hadoop-on-lustre    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hardfs    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hadoop-on-lustre2    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hadoop-on-lustre2    文件:PseudoAuthenticationHandler.java   
private String getUserName(HttpServletRequest request) {
  List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
  if (list != null) {
    for (NameValuePair nv : list) {
      if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
        return nv.getValue();
      }
    }
  }
  return null;
}
项目:hortonworks-extension    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:hortonworks-extension    文件:KerberosUgiAuthenticator.java   
@Override
protected Authenticator getFallBackAuthenticator() {
  return new PseudoAuthenticator() {
    @Override
    protected String getUserName() {
      try {
        return UserGroupInformation.getLoginUser().getUserName();
      } catch (IOException e) {
        throw new SecurityException("Failed to obtain current username", e);
      }
    }
  };
}
项目:sqoop-on-spark    文件:ResourceRequest.java   
private String addUsername(String strUrl) {
  String paramSeparator = (strUrl.contains("?")) ? "&" : "?";
  strUrl += paramSeparator + PseudoAuthenticator.USER_NAME + "=" + System.getProperty("user.name");
  return strUrl;
}
项目:hadoop-plus    文件:PseudoAuthenticationHandler.java   
/**
 * Authenticates an HTTP client request.
 * <p/>
 * It extracts the {@link PseudoAuthenticator#USER_NAME} parameter from the query string and creates
 * an {@link AuthenticationToken} with it.
 * <p/>
 * If the HTTP client request does not contain the {@link PseudoAuthenticator#USER_NAME} parameter and
 * the handler is configured to allow anonymous users it returns the {@link AuthenticationToken#ANONYMOUS}
 * token.
 * <p/>
 * If the HTTP client request does not contain the {@link PseudoAuthenticator#USER_NAME} parameter and
 * the handler is configured to disallow anonymous users it throws an {@link AuthenticationException}.
 *
 * @param request the HTTP client request.
 * @param response the HTTP client response.
 *
 * @return an authentication token if the HTTP client request is accepted and credentials are valid.
 *
 * @throws IOException thrown if an IO error occurred.
 * @throws AuthenticationException thrown if HTTP client request was not accepted as an authentication request.
 */
@Override
public AuthenticationToken authenticate(HttpServletRequest request, HttpServletResponse response)
  throws IOException, AuthenticationException {
  AuthenticationToken token;
  String userName = request.getParameter(PseudoAuthenticator.USER_NAME);
  if (userName == null) {
    if (getAcceptAnonymous()) {
      token = AuthenticationToken.ANONYMOUS;
    } else {
      throw new AuthenticationException("Anonymous requests are disallowed");
    }
  } else {
    token = new AuthenticationToken(userName, userName, getType());
  }
  return token;
}