Package org.apache.directory.server.kerberos.shared.keytab

Examples of org.apache.directory.server.kerberos.shared.keytab.Keytab


        KeytabEntry keytabEntry = new KeytabEntry(
            principal, 1 , new KerberosTime(), (byte) 1, key);
        lstEntries.add(keytabEntry);     
      }
    }
    Keytab keytab = Keytab.getInstance();
    keytab.setEntries(lstEntries);
    keytab.write(new File(testKeytab));
  }
View Full Code Here


   * created.
   */
  public void createPrincipal(File keytabFile, String ... principals)
          throws Exception {
    String generatedPassword = UUID.randomUUID().toString();
    Keytab keytab = new Keytab();
    List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
    for (String principal : principals) {
      createPrincipal(principal, generatedPassword);
      principal = principal + "@" + getRealm();
      KerberosTime timestamp = new KerberosTime();
      for (Map.Entry<EncryptionType, EncryptionKey> entry : KerberosKeyFactory
              .getKerberosKeys(principal, generatedPassword).entrySet()) {
        EncryptionKey ekey = entry.getValue();
        byte keyVersion = (byte) ekey.getKeyVersion();
        entries.add(new KeytabEntry(principal, 1L, timestamp, keyVersion,
                ekey));
      }
    }
    keytab.setEntries(entries);
    keytab.write(keytabFile);
  }
View Full Code Here

   * @return list of unique principals in the keytab.
   * @throws IOException
   *          If keytab entries cannot be read from the file.
   */
  static final String[] getPrincipalNames(String keytabFileName) throws IOException {
      Keytab keytab = Keytab.read(new File(keytabFileName));
      Set<String> principals = new HashSet<String>();
      List<KeytabEntry> entries = keytab.getEntries();
      for (KeytabEntry entry: entries){
        principals.add(entry.getPrincipalName().replace("\\", "/"));
      }
      return principals.toArray(new String[0]);
    }
View Full Code Here

    public static void createKeytab(final String principalName, final String passPhrase, final File keytabFile)
            throws IOException {
        final KerberosTime timeStamp = new KerberosTime();
        final long principalType = 1L; // KRB5_NT_PRINCIPAL

        final Keytab keytab = Keytab.getInstance();
        final List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
        for (Map.Entry<EncryptionType, EncryptionKey> keyEntry : KerberosKeyFactory.getKerberosKeys(principalName, passPhrase)
                .entrySet()) {
            final EncryptionKey key = keyEntry.getValue();
            final byte keyVersion = (byte) key.getKeyVersion();
            entries.add(new KeytabEntry(principalName, principalType, timeStamp, keyVersion, key));
        }
        keytab.setEntries(entries);
        keytab.write(keytabFile);
    }
View Full Code Here

   * created.
   */
  public void createPrincipal(File keytabFile, String ... principals)
          throws Exception {
    String generatedPassword = UUID.randomUUID().toString();
    Keytab keytab = new Keytab();
    List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
    for (String principal : principals) {
      createPrincipal(principal, generatedPassword);
      principal = principal + "@" + getRealm();
      KerberosTime timestamp = new KerberosTime();
      for (Map.Entry<EncryptionType, EncryptionKey> entry : KerberosKeyFactory
              .getKerberosKeys(principal, generatedPassword).entrySet()) {
        EncryptionKey ekey = entry.getValue();
        byte keyVersion = (byte) ekey.getKeyVersion();
        entries.add(new KeytabEntry(principal, 1L, timestamp, keyVersion,
                ekey));
      }
    }
    keytab.setEntries(entries);
    keytab.write(keytabFile);
  }
View Full Code Here

  public void testKeytabGen() throws Exception {
    MiniKdc kdc = getKdc();
    File workDir = getWorkDir();

    kdc.createPrincipal(new File(workDir, "keytab"), "foo/bar", "bar/foo");
    Keytab kt = Keytab.read(new File(workDir, "keytab"));
    Set<String> principals = new HashSet<String>();
    for (KeytabEntry entry : kt.getEntries()) {
      principals.add(entry.getPrincipalName());
    }
    //here principals use \ instead of /
    //because org.apache.directory.server.kerberos.shared.keytab.KeytabDecoder
    // .getPrincipalName(IoBuffer buffer) use \\ when generates principal
View Full Code Here

   * created.
   */
  public void createPrincipal(File keytabFile, String ... principals)
          throws Exception {
    String generatedPassword = UUID.randomUUID().toString();
    Keytab keytab = new Keytab();
    List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
    for (String principal : principals) {
      createPrincipal(principal, generatedPassword);
      principal = principal + "@" + getRealm();
      KerberosTime timestamp = new KerberosTime();
      for (Map.Entry<EncryptionType, EncryptionKey> entry : KerberosKeyFactory
              .getKerberosKeys(principal, generatedPassword).entrySet()) {
        EncryptionKey ekey = entry.getValue();
        byte keyVersion = (byte) ekey.getKeyVersion();
        entries.add(new KeytabEntry(principal, 1L, timestamp, keyVersion,
                ekey));
      }
    }
    keytab.setEntries(entries);
    keytab.write(keytabFile);
  }
View Full Code Here

TOP

Related Classes of org.apache.directory.server.kerberos.shared.keytab.Keytab

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.