Search in sources :

Example 11 with Text

use of org.apache.hadoop.io.Text 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 12 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class DelegationTokenManager method createToken.

@SuppressWarnings("unchecked")
public Token<? extends AbstractDelegationTokenIdentifier> createToken(UserGroupInformation ugi, String renewer) {
    LOG.debug("Creating token with ugi:{}, renewer:{}.", ugi, renewer);
    renewer = (renewer == null) ? ugi.getShortUserName() : renewer;
    String user = ugi.getUserName();
    Text owner = new Text(user);
    Text realUser = null;
    if (ugi.getRealUser() != null) {
        realUser = new Text(ugi.getRealUser().getUserName());
    }
    AbstractDelegationTokenIdentifier tokenIdentifier = (AbstractDelegationTokenIdentifier) secretManager.createIdentifier();
    tokenIdentifier.setOwner(owner);
    tokenIdentifier.setRenewer(new Text(renewer));
    tokenIdentifier.setRealUser(realUser);
    return new Token(tokenIdentifier, secretManager);
}
Also used : AbstractDelegationTokenIdentifier(org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier) Text(org.apache.hadoop.io.Text) Token(org.apache.hadoop.security.token.Token)

Example 13 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class UserProvider method createCredentialEntry.

@Override
public synchronized CredentialEntry createCredentialEntry(String name, char[] credential) throws IOException {
    Text nameT = new Text(name);
    if (credentials.getSecretKey(nameT) != null) {
        throw new IOException("Credential " + name + " already exists in " + this);
    }
    credentials.addSecretKey(new Text(name), new String(credential).getBytes("UTF-8"));
    return new CredentialEntry(name, credential);
}
Also used : Text(org.apache.hadoop.io.Text) IOException(java.io.IOException)

Example 14 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class TestFileSystemTokens method testFsWithChildTokensOneExists.

@Test
public void testFsWithChildTokensOneExists() throws Exception {
    Credentials credentials = new Credentials();
    Text service1 = new Text("singleTokenFs1");
    Text service2 = new Text("singleTokenFs2");
    Token<?> token = mock(Token.class);
    credentials.addToken(service2, token);
    MockFileSystem fs1 = createFileSystemForServiceName(service1);
    MockFileSystem fs2 = createFileSystemForServiceName(service2);
    MockFileSystem fs3 = createFileSystemForServiceName(null);
    MockFileSystem multiFs = createFileSystemForServiceName(null, fs1, fs2, fs3);
    multiFs.addDelegationTokens(renewer, credentials);
    verifyTokenFetch(multiFs, false);
    verifyTokenFetch(fs1, true);
    // we had added its token to credentials
    verifyTokenFetch(fs2, false);
    verifyTokenFetch(fs3, false);
    assertEquals(2, credentials.numberOfTokens());
    assertNotNull(credentials.getToken(service1));
    assertSame(token, credentials.getToken(service2));
}
Also used : Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Example 15 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class TestFileSystemTokens method testFsWithDuplicateChildrenTokenExists.

@Test
public void testFsWithDuplicateChildrenTokenExists() throws Exception {
    Credentials credentials = new Credentials();
    Text service = new Text("singleTokenFs1");
    Token<?> token = mock(Token.class);
    credentials.addToken(service, token);
    MockFileSystem fs = createFileSystemForServiceName(service);
    MockFileSystem multiFs = createFileSystemForServiceName(null, fs, new FilterFileSystem(fs));
    multiFs.addDelegationTokens(renewer, credentials);
    verifyTokenFetch(multiFs, false);
    verifyTokenFetch(fs, false);
    assertEquals(1, credentials.numberOfTokens());
    assertSame(token, credentials.getToken(service));
}
Also used : Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Aggregations

Text (org.apache.hadoop.io.Text)1012 Test (org.junit.Test)397 Path (org.apache.hadoop.fs.Path)180 Configuration (org.apache.hadoop.conf.Configuration)169 LongWritable (org.apache.hadoop.io.LongWritable)141 IOException (java.io.IOException)139 IntWritable (org.apache.hadoop.io.IntWritable)115 FileSystem (org.apache.hadoop.fs.FileSystem)109 ArrayList (java.util.ArrayList)100 Token (org.apache.hadoop.security.token.Token)94 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)86 BytesWritable (org.apache.hadoop.io.BytesWritable)73 SequenceFile (org.apache.hadoop.io.SequenceFile)68 Credentials (org.apache.hadoop.security.Credentials)63 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)54 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)53 JobConf (org.apache.hadoop.mapred.JobConf)50 FloatWritable (org.apache.hadoop.io.FloatWritable)46 BooleanWritable (org.apache.hadoop.io.BooleanWritable)45 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)42