Examples of AuthenticatedURL


Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    private static HttpURLConnection getConnection(URL url) throws IOException {
        AuthenticatedURL.Token token = new AuthenticatedURL.Token();
        HttpURLConnection conn;
        try {
            conn = new AuthenticatedURL(AuthenticatorClass.newInstance()).openConnection(url, token);
        }
        catch (AuthenticationException ex) {
            throw new IOException("Could not authenticate, " + ex.getMessage(), ex);
        }
        catch (InstantiationException ex) {
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

      DelegationTokenOperation.GETDELEGATIONTOKEN;
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, op.toString());
    params.put(RENEWER_PARAM,renewer);
    URL url = HttpFSUtils.createHttpURL(new Path(fsURI), params);
    AuthenticatedURL aUrl =
      new AuthenticatedURL(new HttpFSKerberosAuthenticator());
    try {
      HttpURLConnection conn = aUrl.openConnection(url, token);
      conn.setRequestMethod(op.getHttpMethod());
      HttpFSUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
      JSONObject json = (JSONObject) ((JSONObject)
        HttpFSUtils.jsonParse(conn)).get(DELEGATION_TOKEN_JSON);
      String tokenStr = (String)
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM,
               DelegationTokenOperation.RENEWDELEGATIONTOKEN.toString());
    params.put(TOKEN_PARAM, dToken.encodeToUrlString());
    URL url = HttpFSUtils.createHttpURL(new Path(fsURI), params);
    AuthenticatedURL aUrl =
      new AuthenticatedURL(new HttpFSKerberosAuthenticator());
    try {
      HttpURLConnection conn = aUrl.openConnection(url, token);
      conn.setRequestMethod(
        DelegationTokenOperation.RENEWDELEGATIONTOKEN.getHttpMethod());
      HttpFSUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
      JSONObject json = (JSONObject) ((JSONObject)
        HttpFSUtils.jsonParse(conn)).get(DELEGATION_TOKEN_JSON);
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM,
               DelegationTokenOperation.CANCELDELEGATIONTOKEN.toString());
    params.put(TOKEN_PARAM, dToken.encodeToUrlString());
    URL url = HttpFSUtils.createHttpURL(new Path(fsURI), params);
    AuthenticatedURL aUrl =
      new AuthenticatedURL(new HttpFSKerberosAuthenticator());
    try {
      HttpURLConnection conn = aUrl.openConnection(url, token);
      conn.setRequestMethod(
        DelegationTokenOperation.CANCELDELEGATIONTOKEN.getHttpMethod());
      HttpFSUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    } catch (AuthenticationException ex) {
      throw new IOException(ex.toString(), ex);
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    Class<? extends Authenticator> klass =
      getConf().getClass("httpfs.authenticator.class",
                         HttpFSKerberosAuthenticator.class, Authenticator.class);
    Authenticator authenticator = ReflectionUtils.newInstance(klass, getConf());
    try {
      HttpURLConnection conn = new AuthenticatedURL(authenticator).openConnection(url, authToken);
      conn.setRequestMethod(method);
      if (method.equals(HTTP_POST) || method.equals(HTTP_PUT)) {
        conn.setDoOutput(true);
      }
      return conn;
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

  private HttpURLConnection getConnection(URL url, String method) throws IOException {
    Class<? extends Authenticator> klass =
      getConf().getClass("httpfs.authenticator.class", HttpKerberosAuthenticator.class, Authenticator.class);
    Authenticator authenticator = ReflectionUtils.newInstance(klass, getConf());
    try {
      HttpURLConnection conn = new AuthenticatedURL(authenticator).openConnection(url, authToken);
      conn.setRequestMethod(method);
      if (method.equals(HTTP_POST) || method.equals(HTTP_PUT)) {
        conn.setDoOutput(true);
      }
      return conn;
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    try {
      if (requireAuth) {
        LOG.debug("open AuthenticatedURL connection");
        UserGroupInformation.getCurrentUser().checkTGTAndReloginFromKeytab();
        final AuthenticatedURL.Token authToken = new AuthenticatedURL.Token();
        conn = new AuthenticatedURL(AUTH).openConnection(url, authToken);
      } else {
        LOG.debug("open URL connection");
        conn = (HttpURLConnection)url.openConnection();
      }
    } catch (AuthenticationException e) {
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    KerberosTestUtils.doAsClient(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        URL url = new URL(TestJettyHelper.getJettyURL(),
                          "/webhdfs/v1/?op=GETHOMEDIRECTORY");
        AuthenticatedURL aUrl = new AuthenticatedURL();
        AuthenticatedURL.Token aToken = new AuthenticatedURL.Token();
        HttpURLConnection conn = aUrl.openConnection(url, aToken);
        Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
        return null;
      }
    });
  }
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

      @Override
      public Void call() throws Exception {
        //get delegation token doing SPNEGO authentication
        URL url = new URL(TestJettyHelper.getJettyURL(),
                          "/webhdfs/v1/?op=GETDELEGATIONTOKEN");
        AuthenticatedURL aUrl = new AuthenticatedURL();
        AuthenticatedURL.Token aToken = new AuthenticatedURL.Token();
        HttpURLConnection conn = aUrl.openConnection(url, aToken);
        Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
        JSONObject json = (JSONObject) new JSONParser()
          .parse(new InputStreamReader(conn.getInputStream()));
        json =
          (JSONObject) json
            .get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_JSON);
        String tokenStr = (String) json
          .get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);

        //access httpfs using the delegation token
        url = new URL(TestJettyHelper.getJettyURL(),
                      "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation=" +
                      tokenStr);
        conn = (HttpURLConnection) url.openConnection();
        Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);

        //try to renew the delegation token without SPNEGO credentials
        url = new URL(TestJettyHelper.getJettyURL(),
                      "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=" + tokenStr);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("PUT");
        Assert.assertEquals(conn.getResponseCode(),
                            HttpURLConnection.HTTP_UNAUTHORIZED);

        //renew the delegation token with SPNEGO credentials
        url = new URL(TestJettyHelper.getJettyURL(),
                      "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=" + tokenStr);
        conn = aUrl.openConnection(url, aToken);
        conn.setRequestMethod("PUT");
        Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);

        //cancel delegation token, no need for SPNEGO credentials
        url = new URL(TestJettyHelper.getJettyURL(),
View Full Code Here

Examples of org.apache.hadoop.security.authentication.client.AuthenticatedURL

    if (!UserGroupInformation.isSecurityEnabled() || useKsslAuth) {
      return url.openConnection();
    } else {
      AuthenticatedURL.Token token = new AuthenticatedURL.Token();
      try {
        return new AuthenticatedURL().openConnection(url, token);
      } catch (AuthenticationException e) {
        throw new IOException("Exception trying to open authenticated connection to "
            + url, e);
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.