예제 #1
0
  @Test
  public void testKeytab() {
    assertThat(keytab).isNotNull();

    List<PrincipalName> principals = keytab.getPrincipals();
    PrincipalName principal = principals.get(0);
    List<KeytabEntry> entries = keytab.getKeytabEntries(principal);
    for (KeytabEntry ke : entries) {
      assertThat(ke.getKvno() == 1).isTrue();
    }
  }
예제 #2
0
  /**
   * Remove all the old keys of the specified principal in the specified keytab file.
   *
   * @param keytabFile The keytab file
   * @param principalName The principal name
   * @throws KrbException
   */
  static void removeOldKeytabEntriesOf(File keytabFile, String principalName) throws KrbException {
    Keytab keytab = loadKeytab(keytabFile);

    List<KeytabEntry> entries = keytab.getKeytabEntries(new PrincipalName(principalName));

    int maxKvno = 0;
    for (KeytabEntry entry : entries) {
      if (maxKvno < entry.getKvno()) {
        maxKvno = entry.getKvno();
      }
    }

    for (KeytabEntry entry : entries) {
      if (entry.getKvno() < maxKvno) {
        keytab.removeKeytabEntry(entry);
      }
    }

    storeKeytab(keytab, keytabFile);
  }