@BeforeClass
  public static void beforeClass() throws Exception {
    setUpKdcServer();
    setupCluster(UTIL1);
    setupCluster(UTIL2);

    try (Admin admin = UTIL1.getAdmin()) {
      admin.addReplicationPeer("1",
        ReplicationPeerConfig.newBuilder()
          .setClusterKey(ZKConfig.getZooKeeperClusterKey(UTIL2.getConfiguration()))
          .putConfiguration(HBaseKerberosUtils.KRB_PRINCIPAL,
            UTIL2.getConfiguration().get(HBaseKerberosUtils.KRB_PRINCIPAL))
          .putConfiguration(HBaseKerberosUtils.MASTER_KRB_PRINCIPAL,
            UTIL2.getConfiguration().get(HBaseKerberosUtils.MASTER_KRB_PRINCIPAL))
          .build());
    }
  }
Sets the security firstly for getting the correct default realm.
hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/replication/TestVerifyReplicationSecureClusterCredentials.java