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

The following examples show how to use org.apache.hadoop.security.authentication.client.AuthenticationException. 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 File: KerberosWebHDFSConnection2.java    From Transwarp-Sample-Code with 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 #2
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #3
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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();
    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;
}
 
Example #4
Source File: KerberosWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #5
Source File: KerberosAuthenticator2.java    From Transwarp-Sample-Code with 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 #6
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #7
Source File: TestSCMNodeManager.java    From hadoop-ozone with 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 #8
Source File: AuthToken.java    From hadoop with 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 #9
Source File: TestSCMNodeManager.java    From hadoop-ozone with 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 #10
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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 File: MiniOzoneClusterImpl.java    From hadoop-ozone with 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 File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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;
}
 
Example #13
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #14
Source File: KerberosWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #15
Source File: KerberosWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #16
Source File: AuthToken.java    From hadoop with 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 #17
Source File: OzoneManager.java    From hadoop-ozone with 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 #18
Source File: KerberosWebHDFSConnection2.java    From Transwarp-Sample-Code with 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 #19
Source File: KerberosWebHDFSConnection2.java    From Transwarp-Sample-Code with 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 #20
Source File: KerberosWebHDFSConnection2.java    From Transwarp-Sample-Code with 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 #21
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #22
Source File: KerberosWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #23
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #24
Source File: KerberosWebHDFSConnection.java    From Transwarp-Sample-Code with 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 #25
Source File: SecurityContext.java    From NNAnalytics with 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 #26
Source File: KerberosWebHDFSConnection2.java    From Transwarp-Sample-Code with 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 #27
Source File: URLConnectionFactory.java    From hadoop with 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 #28
Source File: TestAltKerberosAuthenticationHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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 #29
Source File: TestAuthenticationFilter.java    From hadoop with 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 #30
Source File: PseudoWebHDFSConnection.java    From Transwarp-Sample-Code with 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;
}