Search in sources :

Example 1 with PrincipalName

use of org.apache.kerby.kerberos.kerb.type.base.PrincipalName in project hadoop by apache.

the class KDiag method dumpKeytab.

/**
   * Dump a keytab: list all principals.
   *
   * @param keytabFile the keytab file
   * @throws IOException IO problems
   */
private void dumpKeytab(File keytabFile) throws IOException {
    title("Examining keytab %s", keytabFile);
    File kt = keytabFile.getCanonicalFile();
    verifyFileIsValid(kt, CAT_KERBEROS, "keytab");
    Keytab loadKeytab = Keytab.loadKeytab(kt);
    List<PrincipalName> principals = loadKeytab.getPrincipals();
    println("keytab principal count: %d", principals.size());
    int entrySize = 0;
    for (PrincipalName princ : principals) {
        List<KeytabEntry> entries = loadKeytab.getKeytabEntries(princ);
        entrySize = entrySize + entries.size();
        for (KeytabEntry entry : entries) {
            EncryptionKey key = entry.getKey();
            println(" %s: version=%d expires=%s encryption=%s", entry.getPrincipal(), entry.getKvno(), entry.getTimestamp(), key.getKeyType());
        }
    }
    println("keytab entry count: %d", entrySize);
    endln();
}
Also used : Keytab(org.apache.kerby.kerberos.kerb.keytab.Keytab) EncryptionKey(org.apache.kerby.kerberos.kerb.type.base.EncryptionKey) PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) File(java.io.File) KeytabEntry(org.apache.kerby.kerberos.kerb.keytab.KeytabEntry)

Example 2 with PrincipalName

use of org.apache.kerby.kerberos.kerb.type.base.PrincipalName in project hadoop by apache.

the class TestKerberosUtil method createKeyTab.

private void createKeyTab(String fileName, String[] principalNames) throws IOException {
    //create a test keytab file
    List<KeytabEntry> lstEntries = new ArrayList<KeytabEntry>();
    for (String principal : principalNames) {
        // duplicate principals
        for (int kvno = 1; kvno <= 3; kvno++) {
            EncryptionKey key = new EncryptionKey(EncryptionType.NONE, "samplekey1".getBytes(), kvno);
            KeytabEntry keytabEntry = new KeytabEntry(new PrincipalName(principal), new KerberosTime(), (byte) 1, key);
            lstEntries.add(keytabEntry);
        }
    }
    Keytab keytab = new Keytab();
    keytab.addKeytabEntries(lstEntries);
    keytab.store(new File(testKeytab));
}
Also used : Keytab(org.apache.kerby.kerberos.kerb.keytab.Keytab) ArrayList(java.util.ArrayList) KerberosTime(org.apache.kerby.kerberos.kerb.type.KerberosTime) EncryptionKey(org.apache.kerby.kerberos.kerb.type.base.EncryptionKey) PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) File(java.io.File) KeytabEntry(org.apache.kerby.kerberos.kerb.keytab.KeytabEntry)

Example 3 with PrincipalName

use of org.apache.kerby.kerberos.kerb.type.base.PrincipalName in project hadoop by apache.

the class TestMiniKdc method testKeytabGen.

@Test
public void testKeytabGen() throws Exception {
    MiniKdc kdc = getKdc();
    File workDir = getWorkDir();
    kdc.createPrincipal(new File(workDir, "keytab"), "foo/bar", "bar/foo");
    List<PrincipalName> principalNameList = Keytab.loadKeytab(new File(workDir, "keytab")).getPrincipals();
    Set<String> principals = new HashSet<String>();
    for (PrincipalName principalName : principalNameList) {
        principals.add(principalName.getName());
    }
    Assert.assertEquals(new HashSet<String>(Arrays.asList("foo/bar@" + kdc.getRealm(), "bar/foo@" + kdc.getRealm())), principals);
}
Also used : PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with PrincipalName

use of org.apache.kerby.kerberos.kerb.type.base.PrincipalName in project hadoop by apache.

the class KerberosUtil method getPrincipalNames.

/**
   * Get all the unique principals present in the keytabfile.
   * 
   * @param keytabFileName 
   *          Name of the keytab file to be read.
   * @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.loadKeytab(new File(keytabFileName));
    Set<String> principals = new HashSet<String>();
    List<PrincipalName> entries = keytab.getPrincipals();
    for (PrincipalName entry : entries) {
        principals.add(entry.getName().replace("\\", "/"));
    }
    return principals.toArray(new String[0]);
}
Also used : Keytab(org.apache.kerby.kerberos.kerb.keytab.Keytab) PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with PrincipalName

use of org.apache.kerby.kerberos.kerb.type.base.PrincipalName in project zookeeper by apache.

the class MiniKdcTest method testKeytabGen.

@Test(timeout = 60000)
public void testKeytabGen() throws Exception {
    MiniKdc kdc = getKdc();
    File workDir = getWorkDir();
    kdc.createPrincipal(new File(workDir, "keytab"), "foo/bar", "bar/foo");
    List<PrincipalName> principalNameList = Keytab.loadKeytab(new File(workDir, "keytab")).getPrincipals();
    Set<String> principals = new HashSet<String>();
    for (PrincipalName principalName : principalNameList) {
        principals.add(principalName.getName());
    }
    Assert.assertEquals(new HashSet<String>(Arrays.asList("foo/bar@" + kdc.getRealm(), "bar/foo@" + kdc.getRealm())), principals);
}
Also used : PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

File (java.io.File)5 PrincipalName (org.apache.kerby.kerberos.kerb.type.base.PrincipalName)5 HashSet (java.util.HashSet)3 Keytab (org.apache.kerby.kerberos.kerb.keytab.Keytab)3 KeytabEntry (org.apache.kerby.kerberos.kerb.keytab.KeytabEntry)2 EncryptionKey (org.apache.kerby.kerberos.kerb.type.base.EncryptionKey)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 KerberosTime (org.apache.kerby.kerberos.kerb.type.KerberosTime)1