Пример #1
1
  @Test
  public void testToThrift() throws DestroyFailedException {
    // verify thrift serialization
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(new MockInstance());
    assertEquals("test", tCreds.getPrincipal());
    assertEquals(PasswordToken.class.getName(), tCreds.getTokenClassName());
    assertArrayEquals(
        AuthenticationTokenSerializer.serialize(new PasswordToken("testing")), tCreds.getToken());

    // verify that we can't serialize if it's destroyed
    creds.getToken().destroy();
    try {
      creds.toThrift(new MockInstance());
      fail();
    } catch (Exception e) {
      assertTrue(e instanceof RuntimeException);
      assertTrue(e.getCause() instanceof AccumuloSecurityException);
      assertTrue(
          AccumuloSecurityException.class
              .cast(e.getCause())
              .getSecurityErrorCode()
              .equals(SecurityErrorCode.TOKEN_EXPIRED));
    }
  }
 /**
  * Gets the serialized token from either the configuration or the token file.
  *
  * @since 1.5.0
  * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobContext)} instead.
  */
 @Deprecated
 protected static byte[] getToken(JobContext context) {
   return AuthenticationTokenSerializer.serialize(getAuthenticationToken(context));
 }