Search in sources :

Example 11 with Credentials

use of org.apache.hadoop.security.Credentials in project hadoop by apache.

the class TestProtocolRecords method testNodeHeartBeatResponse.

@Test
public void testNodeHeartBeatResponse() throws IOException {
    NodeHeartbeatResponse record = Records.newRecord(NodeHeartbeatResponse.class);
    Map<ApplicationId, ByteBuffer> appCredentials = new HashMap<ApplicationId, ByteBuffer>();
    Credentials app1Cred = new Credentials();
    Token<DelegationTokenIdentifier> token1 = new Token<DelegationTokenIdentifier>();
    token1.setKind(new Text("kind1"));
    app1Cred.addToken(new Text("token1"), token1);
    Token<DelegationTokenIdentifier> token2 = new Token<DelegationTokenIdentifier>();
    token2.setKind(new Text("kind2"));
    app1Cred.addToken(new Text("token2"), token2);
    DataOutputBuffer dob = new DataOutputBuffer();
    app1Cred.writeTokenStorageToStream(dob);
    ByteBuffer byteBuffer1 = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
    appCredentials.put(ApplicationId.newInstance(1234, 1), byteBuffer1);
    record.setSystemCredentialsForApps(appCredentials);
    NodeHeartbeatResponse proto = new NodeHeartbeatResponsePBImpl(((NodeHeartbeatResponsePBImpl) record).getProto());
    Assert.assertEquals(appCredentials, proto.getSystemCredentialsForApps());
}
Also used : HashMap(java.util.HashMap) DelegationTokenIdentifier(org.apache.hadoop.security.token.delegation.web.DelegationTokenIdentifier) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) NodeHeartbeatResponsePBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.NodeHeartbeatResponsePBImpl) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ByteBuffer(java.nio.ByteBuffer) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

Example 12 with Credentials

use of org.apache.hadoop.security.Credentials in project hadoop by apache.

the class TestMerger method testEncryptedMerger.

@Test
public void testEncryptedMerger() throws Throwable {
    jobConf.setBoolean(MRJobConfig.MR_ENCRYPTED_INTERMEDIATE_DATA, true);
    conf.setBoolean(MRJobConfig.MR_ENCRYPTED_INTERMEDIATE_DATA, true);
    Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();
    TokenCache.setEncryptedSpillKey(new byte[16], credentials);
    UserGroupInformation.getCurrentUser().addCredentials(credentials);
    testInMemoryAndOnDiskMerger();
}
Also used : Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

Example 13 with Credentials

use of org.apache.hadoop.security.Credentials in project hadoop by apache.

the class TestTokenCache method testSingleTokenFetch.

@Test
public void testSingleTokenFetch() throws Exception {
    Configuration conf = new Configuration();
    conf.set(YarnConfiguration.RM_PRINCIPAL, "mapred/host@REALM");
    String renewer = Master.getMasterPrincipal(conf);
    Credentials credentials = new Credentials();
    final MockFileSystem fs = new MockFileSystem();
    final MockFileSystem mockFs = (MockFileSystem) fs.getRawFileSystem();
    when(mockFs.getCanonicalServiceName()).thenReturn("host:0");
    when(mockFs.getUri()).thenReturn(new URI("mockfs://host:0"));
    Path mockPath = mock(Path.class);
    when(mockPath.getFileSystem(conf)).thenReturn(mockFs);
    Path[] paths = new Path[] { mockPath, mockPath };
    when(mockFs.addDelegationTokens("me", credentials)).thenReturn(null);
    TokenCache.obtainTokensForNamenodesInternal(credentials, paths, conf);
    verify(mockFs, times(1)).addDelegationTokens(renewer, credentials);
}
Also used : Path(org.apache.hadoop.fs.Path) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Example 14 with Credentials

use of org.apache.hadoop.security.Credentials in project storm by apache.

the class AutoHBase method addTokensToUGI.

public void addTokensToUGI(Subject subject) {
    if (subject != null) {
        Set<Credentials> privateCredentials = subject.getPrivateCredentials(Credentials.class);
        if (privateCredentials != null) {
            for (Credentials cred : privateCredentials) {
                Collection<Token<? extends TokenIdentifier>> allTokens = cred.getAllTokens();
                if (allTokens != null) {
                    for (Token<? extends TokenIdentifier> token : allTokens) {
                        try {
                            UserGroupInformation.getCurrentUser().addToken(token);
                            LOG.info("Added delegation tokens to UGI.");
                        } catch (IOException e) {
                            LOG.error("Exception while trying to add tokens to ugi", e);
                        }
                    }
                }
            }
        }
    }
}
Also used : TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) Token(org.apache.hadoop.security.token.Token) IAutoCredentials(org.apache.storm.security.auth.IAutoCredentials) Credentials(org.apache.hadoop.security.Credentials)

Example 15 with Credentials

use of org.apache.hadoop.security.Credentials in project storm by apache.

the class AutoHBase method getCredentials.

/*
 *
 * @param credentials map with creds.
 * @return instance of org.apache.hadoop.security.Credentials.
 * this class's populateCredentials must have been called before.
 */
@SuppressWarnings("unchecked")
protected Object getCredentials(Map<String, String> credentials) {
    Credentials credential = null;
    if (credentials != null && credentials.containsKey(getCredentialKey())) {
        try {
            byte[] credBytes = DatatypeConverter.parseBase64Binary(credentials.get(getCredentialKey()));
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(credBytes));
            credential = new Credentials();
            credential.readFields(in);
            LOG.info("Got hbase credentials from credentials Map.");
        } catch (Exception e) {
            LOG.error("Could not obtain credentials from credentials map.", e);
        }
    }
    return credential;
}
Also used : IAutoCredentials(org.apache.storm.security.auth.IAutoCredentials) Credentials(org.apache.hadoop.security.Credentials)

Aggregations

Credentials (org.apache.hadoop.security.Credentials)351 Test (org.junit.Test)141 Token (org.apache.hadoop.security.token.Token)101 IOException (java.io.IOException)91 Text (org.apache.hadoop.io.Text)85 Configuration (org.apache.hadoop.conf.Configuration)75 Path (org.apache.hadoop.fs.Path)73 HashMap (java.util.HashMap)61 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)58 ByteBuffer (java.nio.ByteBuffer)55 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)49 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)47 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)45 File (java.io.File)37 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)35 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)35 TokenIdentifier (org.apache.hadoop.security.token.TokenIdentifier)32 InetSocketAddress (java.net.InetSocketAddress)31 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)31 FileSystem (org.apache.hadoop.fs.FileSystem)29