Search in sources :

Example 71 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project hadoop by apache.

the class ZKDelegationTokenSecretManager method getTokenInfoFromZK.

private DelegationTokenInformation getTokenInfoFromZK(TokenIdent ident, boolean quiet) throws IOException {
    String nodePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber());
    try {
        byte[] data = zkClient.getData().forPath(nodePath);
        if ((data == null) || (data.length == 0)) {
            return null;
        }
        ByteArrayInputStream bin = new ByteArrayInputStream(data);
        DataInputStream din = new DataInputStream(bin);
        createIdentifier().readFields(din);
        long renewDate = din.readLong();
        int pwdLen = din.readInt();
        byte[] password = new byte[pwdLen];
        int numRead = din.read(password, 0, pwdLen);
        if (numRead > -1) {
            DelegationTokenInformation tokenInfo = new DelegationTokenInformation(renewDate, password);
            return tokenInfo;
        }
    } catch (KeeperException.NoNodeException e) {
        if (!quiet) {
            LOG.error("No node in path [" + nodePath + "]");
        }
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 72 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project hadoop by apache.

the class ZKDelegationTokenSecretManager method cancelToken.

@Override
public synchronized TokenIdent cancelToken(Token<TokenIdent> token, String canceller) throws IOException {
    ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
    DataInputStream in = new DataInputStream(buf);
    TokenIdent id = createIdentifier();
    id.readFields(in);
    syncLocalCacheWithZk(id);
    return super.cancelToken(token, canceller);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 73 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project hadoop by apache.

the class SaslRpcServer method getIdentifier.

public static <T extends TokenIdentifier> T getIdentifier(String id, SecretManager<T> secretManager) throws InvalidToken {
    byte[] tokenId = decodeIdentifier(id);
    T tokenIdentifier = secretManager.createIdentifier();
    try {
        tokenIdentifier.readFields(new DataInputStream(new ByteArrayInputStream(tokenId)));
    } catch (IOException e) {
        throw (InvalidToken) new InvalidToken("Can't de-serialize tokenIdentifier").initCause(e);
    }
    return tokenIdentifier;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidToken(org.apache.hadoop.security.token.SecretManager.InvalidToken) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 74 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project hadoop by apache.

the class AbstractDelegationTokenSecretManager method cancelToken.

/**
   * Cancel a token by removing it from cache.
   * @return Identifier of the canceled token
   * @throws InvalidToken for invalid token
   * @throws AccessControlException if the user isn't allowed to cancel
   */
public synchronized TokenIdent cancelToken(Token<TokenIdent> token, String canceller) throws IOException {
    ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
    DataInputStream in = new DataInputStream(buf);
    TokenIdent id = createIdentifier();
    id.readFields(in);
    LOG.info("Token cancellation requested for identifier: " + formatTokenId(id));
    if (id.getUser() == null) {
        throw new InvalidToken("Token with no owner " + formatTokenId(id));
    }
    String owner = id.getUser().getUserName();
    Text renewer = id.getRenewer();
    HadoopKerberosName cancelerKrbName = new HadoopKerberosName(canceller);
    String cancelerShortName = cancelerKrbName.getShortName();
    if (!canceller.equals(owner) && (renewer == null || renewer.toString().isEmpty() || !cancelerShortName.equals(renewer.toString()))) {
        throw new AccessControlException(canceller + " is not authorized to cancel the token " + formatTokenId(id));
    }
    DelegationTokenInformation info = currentTokens.remove(id);
    if (info == null) {
        throw new InvalidToken("Token not found " + formatTokenId(id));
    }
    removeStoredToken(id);
    return id;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HadoopKerberosName(org.apache.hadoop.security.HadoopKerberosName) AccessControlException(org.apache.hadoop.security.AccessControlException) Text(org.apache.hadoop.io.Text) DataInputStream(java.io.DataInputStream)

Example 75 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project hadoop by apache.

the class DelegationTokenManager method decodeToken.

private static DelegationTokenIdentifier decodeToken(Token<DelegationTokenIdentifier> token, Text tokenKind) throws IOException {
    ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
    DataInputStream dis = new DataInputStream(buf);
    DelegationTokenIdentifier id = new DelegationTokenIdentifier(tokenKind);
    id.readFields(dis);
    dis.close();
    return id;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractDelegationTokenIdentifier(org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier) DataInputStream(java.io.DataInputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6879 Test (org.junit.Test)2274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1791 InputStream (java.io.InputStream)1531 IOException (java.io.IOException)1400 DataInputStream (java.io.DataInputStream)600 ObjectInputStream (java.io.ObjectInputStream)597 X509Certificate (java.security.cert.X509Certificate)397 CertificateFactory (java.security.cert.CertificateFactory)355 ObjectOutputStream (java.io.ObjectOutputStream)333 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Certificate (java.security.cert.Certificate)234 HashMap (java.util.HashMap)212 DataOutputStream (java.io.DataOutputStream)200 FileInputStream (java.io.FileInputStream)182 InputStreamReader (java.io.InputStreamReader)180 Test (org.testng.annotations.Test)171 Document (org.w3c.dom.Document)143 Map (java.util.Map)138