Java Code Examples for org.apache.hadoop.security.authentication.client.AuthenticationException

The following examples show how to use org.apache.hadoop.security.authentication.client.AuthenticationException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: AuthToken.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source Project: hadoop-ozone   Source File: TestSCMNodeManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests that Node manager handles heartbeats correctly, and comes out of
 * safe Mode.
 *
 * @throws IOException
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test
public void testScmHeartbeat()
    throws IOException, InterruptedException, AuthenticationException {

  try (SCMNodeManager nodeManager = createNodeManager(getConf())) {
    int registeredNodes = 5;
    // Send some heartbeats from different nodes.
    for (int x = 0; x < registeredNodes; x++) {
      DatanodeDetails datanodeDetails = TestUtils
          .createRandomDatanodeAndRegister(nodeManager);
      nodeManager.processHeartbeat(datanodeDetails);
    }

    //TODO: wait for heartbeat to be processed
    Thread.sleep(4 * 1000);
    assertTrue("Heartbeat thread should have picked up the" +
            "scheduled heartbeats.",
        nodeManager.getAllNodes().size() == registeredNodes);
  }
}
 
Example 3
Source Project: Transwarp-Sample-Code   Source File: KerberosAuthenticator2.java    License: MIT License 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 4
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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();
    String spec = MessageFormat.format(
            "/webhdfs/v1/{0}?op=GETCONTENTSUMMARY&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;
}
 
Example 5
Source Project: hadoop-ozone   Source File: TestSCMNodeManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that we detect as many healthy nodes as we have generated heartbeat
 * for.
 *
 * @throws IOException
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test
public void testScmHealthyNodeCount()
    throws IOException, InterruptedException, AuthenticationException {
  OzoneConfiguration conf = getConf();
  final int count = 10;

  try (SCMNodeManager nodeManager = createNodeManager(conf)) {

    for (int x = 0; x < count; x++) {
      DatanodeDetails datanodeDetails = TestUtils
          .createRandomDatanodeAndRegister(nodeManager);
      nodeManager.processHeartbeat(datanodeDetails);
    }
    //TODO: wait for heartbeat to be processed
    Thread.sleep(4 * 1000);
    assertEquals(count, nodeManager.getNodeCount(HEALTHY));
  }
}
 
Example 6
Source Project: hadoop   Source File: AuthToken.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 8
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 9
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 10
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 11
Source Project: hadoop-ozone   Source File: MiniOzoneClusterImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new StorageContainerManager instance.
 *
 * @return {@link StorageContainerManager}
 * @throws IOException
 */
protected StorageContainerManager createSCM()
    throws IOException, AuthenticationException {
  configureSCM();
  SCMStorageConfig scmStore = new SCMStorageConfig(conf);
  initializeScmStorage(scmStore);
  StorageContainerManager scm = StorageContainerManager.createSCM(conf);
  HealthyPipelineSafeModeRule rule =
      scm.getScmSafeModeManager().getHealthyPipelineSafeModeRule();
  if (rule != null) {
    // Set threshold to wait for safe mode exit - this is needed since a
    // pipeline is marked open only after leader election.
    rule.setHealthyPipelineThresholdCount(numOfDatanodes / 3);
  }
  return scm;
}
 
Example 12
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 13
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 14
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection2.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 15
Source Project: hadoop-ozone   Source File: OzoneManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Login OM service user if security and Kerberos are enabled.
 *
 * @param conf
 * @throws IOException, AuthenticationException
 */
private static void loginOMUser(OzoneConfiguration conf)
    throws IOException, AuthenticationException {

  if (SecurityUtil.getAuthenticationMethod(conf).equals(
      AuthenticationMethod.KERBEROS)) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Ozone security is enabled. Attempting login for OM user. "
              + "Principal: {}, keytab: {}", conf.get(
          OZONE_OM_KERBEROS_PRINCIPAL_KEY),
          conf.get(OZONE_OM_KERBEROS_KEYTAB_FILE_KEY));
    }

    UserGroupInformation.setConfiguration(conf);

    InetSocketAddress socAddr = OmUtils.getOmAddress(conf);
    SecurityUtil.login(conf, OZONE_OM_KERBEROS_KEYTAB_FILE_KEY,
        OZONE_OM_KERBEROS_PRINCIPAL_KEY, socAddr.getHostName());
  } else {
    throw new AuthenticationException(SecurityUtil.getAuthenticationMethod(
        conf) + " authentication method not supported. OM user login "
        + "failed.");
  }
  LOG.info("Ozone Manager login successful.");
}
 
Example 16
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection2.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 17
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection2.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 18
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection2.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 19
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 20
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 21
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 22
Source Project: NNAnalytics   Source File: SecurityContext.java    License: Apache License 2.0 6 votes vote down vote up
private boolean localLogin(
    HttpServletRequest request, HttpServletResponse response, String username, String password)
    throws AuthenticationException {
  if (localOnlyUsers.allows(username)) {
    if (localOnlyUsers.authenticate(username, password)) {
      LOG.debug("Login success via [LOCAL] for: {} at {}", username, request.getRemoteAddr());
      CommonProfile profile = new CommonProfile();
      profile.setId(username);
      String generate = jwtGenerator.generate(profile);
      response.addHeader("Set-Cookie", "nna-jwt-token=" + generate);
      currentUser.set(username);
      return true;
    } else {
      LOG.info("Login failed via [LOCAL] for: {}", request.getRemoteAddr());
      throw new BadCredentialsException("Invalid credentials for: " + username);
    }
  }
  return false;
}
 
Example 23
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection2.java    License: MIT License 6 votes vote down vote up
/**
 * <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}?op=SETTIMES",
                            URLUtil.encodePath(path))), token);
    conn.setRequestMethod("PUT");
    conn.connect();
    resp = result(conn, true);
    conn.disconnect();

    return resp;
}
 
Example 24
Source Project: hadoop   Source File: URLConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example 25
@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());
    }
  };
}
 
Example 26
Source Project: hadoop   Source File: TestAuthenticationFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AuthenticationToken authenticate(HttpServletRequest request, HttpServletResponse response)
  throws IOException, AuthenticationException {
  AuthenticationToken token = null;
  String param = request.getParameter("authenticated");
  if (param != null && param.equals("true")) {
    token = new AuthenticationToken("u", "p", "t");
    token.setExpires((expired) ? 0 : System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
  } else {
    if (request.getHeader("WWW-Authenticate") == null) {
      response.setHeader("WWW-Authenticate", "dummyauth");
    } else {
      throw new AuthenticationException("AUTH FAILED");
    }
  }
  return token;
}
 
Example 27
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 28
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 29
Source Project: Transwarp-Sample-Code   Source File: KerberosWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 30
Source Project: Transwarp-Sample-Code   Source File: PseudoWebHDFSConnection.java    License: MIT License 6 votes vote down vote up
/**
 * <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;
}