/// <summary>Get all the unique principals present in the keytabfile.</summary> /// <param name="keytabFileName"> /// /// Name of the keytab file to be read. /// </param> /// <returns>list of unique principals in the keytab.</returns> /// <exception cref="System.IO.IOException"> /// /// If keytab entries cannot be read from the file. /// </exception> internal static string[] GetPrincipalNames(string keytabFileName) { Org.Apache.Directory.Server.Kerberos.Shared.Keytab.Keytab keytab = Org.Apache.Directory.Server.Kerberos.Shared.Keytab.Keytab .Read(new FilePath(keytabFileName)); ICollection <string> principals = new HashSet <string>(); IList <KeytabEntry> entries = keytab.GetEntries(); foreach (KeytabEntry entry in entries) { principals.AddItem(entry.GetPrincipalName().Replace("\\", "/")); } return(Collections.ToArray(principals, new string[0])); }
public virtual void TestKeytabGen() { MiniKdc kdc = GetKdc(); FilePath workDir = GetWorkDir(); kdc.CreatePrincipal(new FilePath(workDir, "keytab"), "foo/bar", "bar/foo"); Org.Apache.Directory.Server.Kerberos.Shared.Keytab.Keytab kt = Org.Apache.Directory.Server.Kerberos.Shared.Keytab.Keytab .Read(new FilePath(workDir, "keytab")); ICollection <string> principals = new HashSet <string>(); foreach (KeytabEntry entry in kt.GetEntries()) { principals.AddItem(entry.GetPrincipalName()); } //here principals use \ instead of / //because org.apache.directory.server.kerberos.shared.keytab.KeytabDecoder // .getPrincipalName(IoBuffer buffer) use \\ when generates principal Assert.Equal(new HashSet <string>(Arrays.AsList("foo\\bar@" + kdc .GetRealm(), "bar\\foo@" + kdc.GetRealm())), principals); }