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

项目:hadoop    文件:TestAltKerberosAuthenticationHandler.java   
@Override
protected KerberosAuthenticationHandler getNewAuthenticationHandler() {
  // AltKerberosAuthenticationHandler is abstract; a subclass would normally
  // perform some other authentication when alternateAuthenticate() is called.
  // For the test, we'll just return an AuthenticationToken as the other
  // authentication is left up to the developer of the subclass
  return new AltKerberosAuthenticationHandler() {
    @Override
    public AuthenticationToken alternateAuthenticate(
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, AuthenticationException {
      return new AuthenticationToken("A", "B", getType());
    }
  };
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
public String open(String path, OutputStream os)
        throws MalformedURLException, IOException, AuthenticationException {
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=OPEN", URLUtil.encodePath(path))),
            token);
    conn.setRequestMethod("GET");
    conn.setRequestProperty("Content-Type", "application/octet-stream");
    conn.connect();
    InputStream is = conn.getInputStream();
    copy(is, os);
    is.close();
    os.close();
    String resp = result(conn, false);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>GETCONTENTSUMMARY</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETCONTENTSUMMARY"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getContentSummary(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=GETCONTENTSUMMARY",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("GET");
    // conn.setRequestProperty("Content-Type", "application/octet-stream");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>LISTSTATUS</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String listStatus(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();
    System.out.println("Token = "+token.isSet());

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=LISTSTATUS",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("GET");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>GETFILESTATUS</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILESTATUS"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getFileStatus(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=GETFILESTATUS",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("GET");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>GETFILECHECKSUM</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILECHECKSUM"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getFileCheckSum(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=GETFILECHECKSUM",
                    URLUtil.encodePath(path))), token);

    conn.setRequestMethod("GET");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>CREATESYMLINK</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=CREATESYMLINK
 * &destination=<PATH>[&createParent=<true|false>]"
 *
 * @param srcPath
 * @param destPath
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String createSymLink(String srcPath, String destPath)
        throws MalformedURLException, IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=CREATESYMLINK&destination={1}",
                    URLUtil.encodePath(srcPath),
                    URLUtil.encodePath(destPath))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>RENAME</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=RENAME
 * &destination=<PATH>[&createParent=<true|false>]"
 *
 * @param srcPath
 * @param destPath
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String rename(String srcPath, String destPath)
        throws MalformedURLException, IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=RENAME&destination={1}",
                    URLUtil.encodePath(srcPath),
                    URLUtil.encodePath(destPath))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>SETPERMISSION</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION
 * [&permission=<OCTAL>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setPermission(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=SETPERMISSION",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>SETOWNER</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETOWNER
 * [&owner=<USER>][&group=<GROUP>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setOwner(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl),
                    MessageFormat.format("/webhdfs/v1/{0}?op=SETOWNER",
                            URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>SETREPLICATION</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETREPLICATION
 * [&replication=<SHORT>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setReplication(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?op=SETREPLICATION",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection2.java   
/**
 * <b>DELETE</b>
 *
 * curl -i -X DELETE "http://<host>:<port>/webhdfs/v1/<path>?op=DELETE
 * [&recursive=<true|false>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String delete(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL
            .openConnection(
                    new URL(new URL(httpfsUrl), MessageFormat.format(
                            "/webhdfs/v1/{0}?op=DELETE",
                            URLUtil.encodePath(path))), token);
    conn.setRequestMethod("DELETE");
    conn.setInstanceFollowRedirects(false);
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosAuthenticator2.java   
/**
 * Performs SPNEGO authentication against the specified URL.
 * <p/>
 * If a token is given it does a NOP and returns the given token.
 * <p/>
 * If no token is given, it will perform the SPNEGO authentication sequence
 * using an HTTP <code>OPTIONS</code> request.
 *
 * @param url the URl to authenticate against.
 * @param token the authentication token being used for the user.
 * @throws IOException if an IO error occurred.
 * @throws AuthenticationException if an authentication error occurred.
 */
public void authenticate(URL url, AuthenticatedURL.Token token)
        throws IOException, AuthenticationException {
    if (!token.isSet()) {
        this.url = url;
        base64 = new Base64(0);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod(AUTH_HTTP_METHOD);
        conn.connect();
        if (isNegotiate()) {
            doSpnegoSequence(token);
        } else {
            getFallBackAuthenticator().authenticate(url, token);
        }
    }
}
项目:hadoop    文件:AuthToken.java   
/**
 * Splits the string representation of a token into attributes pairs.
 *
 * @param tokenStr string representation of a token.
 *
 * @return a map with the attribute pairs of the token.
 *
 * @throws AuthenticationException thrown if the string representation of the token could not be broken into
 * attribute pairs.
 */
private static Map<String, String> split(String tokenStr) throws AuthenticationException {
  Map<String, String> map = new HashMap<String, String>();
  StringTokenizer st = new StringTokenizer(tokenStr, ATTR_SEPARATOR);
  while (st.hasMoreTokens()) {
    String part = st.nextToken();
    int separator = part.indexOf('=');
    if (separator == -1) {
      throw new AuthenticationException("Invalid authentication token");
    }
    String key = part.substring(0, separator);
    String value = part.substring(separator + 1);
    map.put(key, value);
  }
  return map;
}
项目:hadoop    文件:AuthToken.java   
public static AuthToken parse(String tokenStr) throws AuthenticationException {
  if (tokenStr.length() >= 2) {
    // strip the \" at the two ends of the tokenStr
    if (tokenStr.charAt(0) == '\"' &&
        tokenStr.charAt(tokenStr.length()-1) == '\"') {
      tokenStr = tokenStr.substring(1, tokenStr.length()-1);
    }
  } 
  Map<String, String> map = split(tokenStr);
  // remove the signature part, since client doesn't care about it
  map.remove("s");

  if (!map.keySet().equals(ATTRIBUTES)) {
    throw new AuthenticationException("Invalid token string, missing attributes");
  }
  long expires = Long.parseLong(map.get(EXPIRES));
  AuthToken token = new AuthToken(map.get(USER_NAME), map.get(PRINCIPAL), map.get(TYPE));
  token.setExpires(expires);
  return token;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>LISTSTATUS</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String listStatus(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();
    System.out.println("Token = "+token.isSet());

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=LISTSTATUS",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("GET");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>GETFILESTATUS</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILESTATUS"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getFileStatus(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=GETFILESTATUS",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("GET");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>GETFILECHECKSUM</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILECHECKSUM"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getFileCheckSum(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=GETFILECHECKSUM",
                    URLUtil.encodePath(path))), token);

    conn.setRequestMethod("GET");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>MKDIRS</b>
 *
 * curl -i -X PUT
 * "http://<HOST>:<PORT>/<PATH>?op=MKDIRS[&permission=<OCTAL>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String mkdirs(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL
            .openConnection(
                    new URL(new URL(httpfsUrl), MessageFormat.format(
                            "/webhdfs/v1/{0}?delegation="+delegation+"&op=MKDIRS",
                            URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>CREATESYMLINK</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=CREATESYMLINK
 * &destination=<PATH>[&createParent=<true|false>]"
 *
 * @param srcPath
 * @param destPath
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String createSymLink(String srcPath, String destPath)
        throws MalformedURLException, IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=CREATESYMLINK&destination={1}",
                    URLUtil.encodePath(srcPath),
                    URLUtil.encodePath(destPath))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>RENAME</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=RENAME
 * &destination=<PATH>[&createParent=<true|false>]"
 *
 * @param srcPath
 * @param destPath
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String rename(String srcPath, String destPath)
        throws MalformedURLException, IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=RENAME&destination={1}",
                    URLUtil.encodePath(srcPath),
                    URLUtil.encodePath(destPath))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>SETPERMISSION</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION
 * [&permission=<OCTAL>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setPermission(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=SETPERMISSION",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>SETOWNER</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETOWNER
 * [&owner=<USER>][&group=<GROUP>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setOwner(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl),
                    MessageFormat.format("/webhdfs/v1/{0}?delegation="+delegation+"&op=SETOWNER&owner=hdfs",
                            URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>SETREPLICATION</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETREPLICATION
 * [&replication=<SHORT>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setReplication(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl), MessageFormat.format(
                    "/webhdfs/v1/{0}?delegation="+delegation+"&op=SETREPLICATION",
                    URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:KerberosWebHDFSConnection.java   
/**
 * <b>SETTIMES</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETTIMES
 * [&modificationtime=<TIME>][&accesstime=<TIME>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setTimes(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();

    HttpURLConnection conn = authenticatedURL.openConnection(
            new URL(new URL(httpfsUrl),
                    MessageFormat.format("/webhdfs/v1/{0}?delegation="+delegation+"&op=SETTIMES",
                            URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>OPEN</b>
 *
 * curl -i -L "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=OPEN
 * [&offset=<LONG>][&length=<LONG>][&buffersize=<INT>]"
 *
 * @param path
 * @param os
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String open(String path, OutputStream os)
        throws MalformedURLException, IOException, AuthenticationException {
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=OPEN&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("GET");
    conn.setRequestProperty("Content-Type", "application/octet-stream");
    conn.connect();
    InputStream is = conn.getInputStream();
    copy(is, os);
    is.close();
    os.close();
    String resp = result(conn, false);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>LISTSTATUS</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String listStatus(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=LISTSTATUS&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("GET");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>GETFILESTATUS</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILESTATUS"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getFileStatus(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=GETFILESTATUS&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("GET");
    conn.connect();
    String resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>GETFILECHECKSUM</b>
 *
 * curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILECHECKSUM"
 *
 * @param path
 * @return
 * @throws MalformedURLException
 * @throws IOException
 * @throws AuthenticationException
 */
public String getFileCheckSum(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=GETFILECHECKSUM&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);

    conn.setRequestMethod("GET");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>CREATESYMLINK</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=CREATESYMLINK
 * &destination=<PATH>[&createParent=<true|false>]"
 *
 * @param srcPath
 * @param destPath
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String createSymLink(String srcPath, String destPath)
        throws MalformedURLException, IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat
            .format("/webhdfs/v1/{0}?op=CREATESYMLINK&destination={1}&user.name={2}",
                    URLUtil.encodePath(srcPath),
                    URLUtil.encodePath(destPath), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>RENAME</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=RENAME
 * &destination=<PATH>[&createParent=<true|false>]"
 *
 * @param srcPath
 * @param destPath
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String rename(String srcPath, String destPath)
        throws MalformedURLException, IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=RENAME&destination={1}&user.name={2}",
            URLUtil.encodePath(srcPath), URLUtil.encodePath(destPath),
            this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>SETPERMISSION</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION
 * [&permission=<OCTAL>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setPermission(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=SETPERMISSION&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>SETOWNER</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETOWNER
 * [&owner=<USER>][&group=<GROUP>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setOwner(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=SETOWNER&user.name={1}&owner={2}",
            URLUtil.encodePath(path), this.principal,this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>SETREPLICATION</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETREPLICATION
 * [&replication=<SHORT>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setReplication(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=SETREPLICATION&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>SETTIMES</b>
 *
 * curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETTIMES
 * [&modificationtime=<TIME>][&accesstime=<TIME>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String setTimes(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=SETTIMES&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:Transwarp-Sample-Code    文件:PseudoWebHDFSConnection.java   
/**
 * <b>DELETE</b>
 *
 * curl -i -X DELETE "http://<host>:<port>/webhdfs/v1/<path>?op=DELETE
 * [&recursive=<true|false>]"
 *
 * @param path
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws MalformedURLException
 */
public String delete(String path) throws MalformedURLException,
        IOException, AuthenticationException {
    String resp = null;
    ensureValidToken();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=DELETE&user.name={1}",
            URLUtil.encodePath(path), this.principal);
    HttpURLConnection conn = authenticatedURL.openConnection(new URL(
            new URL(httpfsUrl), spec), token);
    conn.setRequestMethod("DELETE");
    conn.setInstanceFollowRedirects(false);
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
项目:hadoop    文件:URLConnectionFactory.java   
/**
 * Opens a url with read and connect timeouts
 *
 * @param url
 *          URL to open
 * @param isSpnego
 *          whether the url should be authenticated via SPNEGO
 * @return URLConnection
 * @throws IOException
 * @throws AuthenticationException
 */
public URLConnection openConnection(URL url, boolean isSpnego)
    throws IOException, AuthenticationException {
  if (isSpnego) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("open AuthenticatedURL connection" + url);
    }
    UserGroupInformation.getCurrentUser().checkTGTAndReloginFromKeytab();
    final AuthenticatedURL.Token authToken = new AuthenticatedURL.Token();
    return new AuthenticatedURL(new KerberosUgiAuthenticator(),
        connConfigurator).openConnection(url, authToken);
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("open URL connection");
    }
    URLConnection connection = url.openConnection();
    if (connection instanceof HttpURLConnection) {
      connConfigurator.configure((HttpURLConnection) connection);
    }
    return connection;
  }
}
项目:hadoop-oss    文件:DelegationTokenAuthenticator.java   
@Override
public void authenticate(URL url, AuthenticatedURL.Token token)
    throws IOException, AuthenticationException {
  if (!hasDelegationToken(url, token)) {
    authenticator.authenticate(url, token);
  }
}
项目:hadoop    文件:DelegationTokenAuthenticatedURL.java   
/**
 * Renews a delegation token from the server end-point using the
 * configured <code>Authenticator</code> for authentication.
 *
 * @param url the URL to renew the delegation token from. Only HTTP/S URLs are
 * supported.
 * @param token the authentication token with the Delegation Token to renew.
 * @param doAsUser the user to do as, which will be the token owner.
 * @throws IOException if an IO error occurred.
 * @throws AuthenticationException if an authentication exception occurred.
 */
public long renewDelegationToken(URL url, Token token, String doAsUser)
    throws IOException, AuthenticationException {
  Preconditions.checkNotNull(url, "url");
  Preconditions.checkNotNull(token, "token");
  Preconditions.checkNotNull(token.delegationToken,
      "No delegation token available");
  try {
    return ((KerberosDelegationTokenAuthenticator) getAuthenticator()).
        renewDelegationToken(url, token, token.delegationToken, doAsUser);
  } catch (IOException ex) {
    token.delegationToken = null;
    throw ex;
  }
}
项目:hadoop-oss    文件:DelegationTokenAuthenticatedURL.java   
/**
 * Renews a delegation token from the server end-point using the
 * configured <code>Authenticator</code> for authentication.
 *
 * @param url the URL to renew the delegation token from. Only HTTP/S URLs are
 * supported.
 * @param token the authentication token with the Delegation Token to renew.
 * @param doAsUser the user to do as, which will be the token owner.
 * @throws IOException if an IO error occurred.
 * @throws AuthenticationException if an authentication exception occurred.
 */
public long renewDelegationToken(URL url, Token token, String doAsUser)
    throws IOException, AuthenticationException {
  Preconditions.checkNotNull(url, "url");
  Preconditions.checkNotNull(token, "token");
  Preconditions.checkNotNull(token.delegationToken,
      "No delegation token available");
  try {
    return ((KerberosDelegationTokenAuthenticator) getAuthenticator()).
        renewDelegationToken(url, token, token.delegationToken, doAsUser);
  } catch (IOException ex) {
    token.delegationToken = null;
    throw ex;
  }
}