@Test
  @SuppressWarnings("unchecked")
  public void testJobCredentials() throws Exception {
    Job job = new VerifyReplication().createSubmittableJob(
      new Configuration(UTIL1.getConfiguration()), new String[] { peer.get(), "table" });

    Credentials credentials = job.getCredentials();
    Collection<Token<? extends TokenIdentifier>> tokens = credentials.getAllTokens();
    assertEquals(2, tokens.size());

    String clusterId1 = ZKClusterId.readClusterIdZNode(UTIL1.getZooKeeperWatcher());
    Token<AuthenticationTokenIdentifier> tokenForCluster1 =
      (Token<AuthenticationTokenIdentifier>) credentials.getToken(new Text(clusterId1));
    assertEquals(FULL_USER_PRINCIPAL, tokenForCluster1.decodeIdentifier().getUsername());

    String clusterId2 = ZKClusterId.readClusterIdZNode(UTIL2.getZooKeeperWatcher());
    Token<AuthenticationTokenIdentifier> tokenForCluster2 =
      (Token<AuthenticationTokenIdentifier>) credentials.getToken(new Text(clusterId2));
    assertEquals(FULL_USER_PRINCIPAL, tokenForCluster2.decodeIdentifier().getUsername());
  }
Sets the security firstly for getting the correct default realm.
hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/replication/TestVerifyReplicationSecureClusterCredentials.java