/**
   * Load keytab from keytab file.
   *
   * @param keytabFile The keytab file
   * @return The keytab load from keytab file
   * @throws KrbException
   */
  static Keytab loadKeytab(File keytabFile) throws KrbException {
    Keytab keytab;
    try {
      keytab = Keytab.loadKeytab(keytabFile);
    } catch (IOException e) {
      throw new KrbException("Failed to load keytab", e);
    }

    return keytab;
  }
  /**
   * If keytab file does not exist, create a new keytab, otherwise load keytab from keytab file.
   *
   * @param keytabFile The keytab file
   * @return The keytab load from keytab file
   * @throws KrbException
   */
  static Keytab createOrLoadKeytab(File keytabFile) throws KrbException {

    Keytab keytab;
    try {
      if (!keytabFile.exists()) {
        if (!keytabFile.createNewFile()) {
          throw new KrbException("Failed to create keytab file " + keytabFile.getAbsolutePath());
        }
        keytab = new Keytab();
      } else {
        keytab = Keytab.loadKeytab(keytabFile);
      }
    } catch (IOException e) {
      throw new KrbException("Failed to load or create keytab", e);
    }

    return keytab;
  }
示例#3
0
 public static void main(String[] args) throws IOException {
   InputStream kis = KeytabTest.class.getResourceAsStream("test.keytab");
   Keytab keytab = Keytab.loadKeytab(kis);
   System.out.println("Principals:" + keytab.getPrincipals().size());
 }
示例#4
0
 @Before
 public void setUp() throws IOException {
   InputStream kis = KeytabTest.class.getResourceAsStream("/test.keytab");
   keytab = Keytab.loadKeytab(kis);
 }