Java Code Examples for org.apache.hadoop.yarn.security.client.ClientToAMTokenIdentifier#getBytes()
The following examples show how to use
org.apache.hadoop.yarn.security.client.ClientToAMTokenIdentifier#getBytes() .
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: TestYARNTokenIdentifier.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testClientToAMTokenIdentifier() throws IOException { ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance( ApplicationId.newInstance(1, 1), 1); String clientName = "user"; ClientToAMTokenIdentifier token = new ClientToAMTokenIdentifier( appAttemptId, clientName); ClientToAMTokenIdentifier anotherToken = new ClientToAMTokenIdentifier(); byte[] tokenContent = token.getBytes(); DataInputBuffer dib = new DataInputBuffer(); dib.reset(tokenContent, tokenContent.length); anotherToken.readFields(dib); // verify the whole record equals with original record Assert.assertEquals("Token is not the same after serialization " + "and deserialization.", token, anotherToken); Assert.assertEquals("ApplicationAttemptId from proto is not the same with original token", anotherToken.getApplicationAttemptID(), appAttemptId); Assert.assertEquals("clientName from proto is not the same with original token", anotherToken.getClientName(), clientName); }
Example 2
Source File: TestYARNTokenIdentifier.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testClientToAMTokenIdentifier() throws IOException { ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance( ApplicationId.newInstance(1, 1), 1); String clientName = "user"; ClientToAMTokenIdentifier token = new ClientToAMTokenIdentifier( appAttemptId, clientName); ClientToAMTokenIdentifier anotherToken = new ClientToAMTokenIdentifier(); byte[] tokenContent = token.getBytes(); DataInputBuffer dib = new DataInputBuffer(); dib.reset(tokenContent, tokenContent.length); anotherToken.readFields(dib); // verify the whole record equals with original record Assert.assertEquals("Token is not the same after serialization " + "and deserialization.", token, anotherToken); Assert.assertEquals("ApplicationAttemptId from proto is not the same with original token", anotherToken.getApplicationAttemptID(), appAttemptId); Assert.assertEquals("clientName from proto is not the same with original token", anotherToken.getClientName(), clientName); }
Example 3
Source File: TestClientToAMTokens.java From hadoop with Apache License 2.0 | 4 votes |
private void verifyTamperedToken(final Configuration conf, final CustomAM am, Token<ClientToAMTokenIdentifier> token, UserGroupInformation ugi, ClientToAMTokenIdentifier maliciousID) { Token<ClientToAMTokenIdentifier> maliciousToken = new Token<ClientToAMTokenIdentifier>(maliciousID.getBytes(), token.getPassword(), token.getKind(), token.getService()); ugi.addToken(maliciousToken); try { ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try { CustomProtocol client = (CustomProtocol) RPC.getProxy(CustomProtocol.class, 1L, am.address, conf); client.ping(); fail("Connection initiation with illegally modified " + "tokens is expected to fail."); return null; } catch (YarnException ex) { fail("Cannot get a YARN remote exception as " + "it will indicate RPC success"); throw ex; } } }); } catch (Exception e) { Assert.assertEquals(RemoteException.class.getName(), e.getClass() .getName()); e = ((RemoteException)e).unwrapRemoteException(); Assert .assertEquals(SaslException.class .getCanonicalName(), e.getClass().getCanonicalName()); Assert.assertTrue(e .getMessage() .contains( "DIGEST-MD5: digest response format violation. " + "Mismatched response.")); Assert.assertFalse(am.pinged); } }
Example 4
Source File: TestClientToAMTokens.java From big-c with Apache License 2.0 | 4 votes |
private void verifyTamperedToken(final Configuration conf, final CustomAM am, Token<ClientToAMTokenIdentifier> token, UserGroupInformation ugi, ClientToAMTokenIdentifier maliciousID) { Token<ClientToAMTokenIdentifier> maliciousToken = new Token<ClientToAMTokenIdentifier>(maliciousID.getBytes(), token.getPassword(), token.getKind(), token.getService()); ugi.addToken(maliciousToken); try { ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try { CustomProtocol client = (CustomProtocol) RPC.getProxy(CustomProtocol.class, 1L, am.address, conf); client.ping(); fail("Connection initiation with illegally modified " + "tokens is expected to fail."); return null; } catch (YarnException ex) { fail("Cannot get a YARN remote exception as " + "it will indicate RPC success"); throw ex; } } }); } catch (Exception e) { Assert.assertEquals(RemoteException.class.getName(), e.getClass() .getName()); e = ((RemoteException)e).unwrapRemoteException(); Assert .assertEquals(SaslException.class .getCanonicalName(), e.getClass().getCanonicalName()); Assert.assertTrue(e .getMessage() .contains( "DIGEST-MD5: digest response format violation. " + "Mismatched response.")); Assert.assertFalse(am.pinged); } }