org.apache.directory.server.kerberos.shared.keytab.Keytab类的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(13.6k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中org.apache.directory.server.kerberos.shared.keytab.Keytab类的一些代码示例,展示了Keytab类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Keytab类的具体详情如下:
包路径:org.apache.directory.server.kerberos.shared.keytab.Keytab
类名称:Keytab

Keytab介绍

暂无

代码示例

代码示例来源:origin: io.hops/hadoop-auth

/**
 * 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.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]);
 }

代码示例来源:origin: com.github.jiayuhan-it/hadoop-minikdc

/**
  * Creates  multiple principals in the KDC and adds them to a keytab file.
  *
  * @param keytabFile keytab file to add the created principal.s
  * @param principals principals to add to the KDC, do not include the domain.
  * @throws Exception thrown if the principals or the keytab file could not be
  * 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);
 }
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/**
 * Creates a keytab file for authenticating with a given principal.
 *
 * @param user Username to login with (i.e. cassandra).
 * @param password Password to authenticate with.
 * @param principal Principal representing the server (i.e. cassandra@DATASTAX.COM).
 * @return Generated keytab file for this user.
 */
public File createKeytab(String user, String password, String principal) throws IOException {
 File keytabFile = new File(confDir, user + ".keytab");
 Keytab keytab = Keytab.getInstance();
 KerberosTime timeStamp = new KerberosTime(System.currentTimeMillis());
 Map<EncryptionType, EncryptionKey> keys =
   KerberosKeyFactory.getKerberosKeys(principal, password);
 KeytabEntry keytabEntry =
   new KeytabEntry(
     principal, 0, timeStamp, (byte) 0, keys.get(EncryptionType.AES128_CTS_HMAC_SHA1_96));
 keytab.setEntries(Collections.singletonList(keytabEntry));
 keytab.write(keytabFile);
 return keytabFile;
}

代码示例来源:origin: io.hops/hadoop-minikdc

/**
  * Creates  multiple principals in the KDC and adds them to a keytab file.
  *
  * @param keytabFile keytab file to add the created principal.s
  * @param principals principals to add to the KDC, do not include the domain.
  * @throws Exception thrown if the principals or the keytab file could not be
  * 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);
 }
}

代码示例来源:origin: io.hops/hadoop-auth

private void createKeyTab(String fileName, String[] principalNames)
   throws IOException {
  //create a test keytab file
  List<KeytabEntry> lstEntries = new ArrayList<KeytabEntry>();
  for (String principal : principalNames){
   // create 3 versions of the key to ensure methods don't return
   // duplicate principals
   for (int kvno=1; kvno <= 3; kvno++) {
    EncryptionKey key = new EncryptionKey(
      EncryptionType.UNKNOWN, "samplekey1".getBytes(), kvno);
    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));
 }
}

代码示例来源:origin: apache/hadoop-common

/**
  * Creates  multiple principals in the KDC and adds them to a keytab file.
  *
  * @param keytabFile keytab file to add the created principal.s
  * @param principals principals to add to the KDC, do not include the domain.
  * @throws Exception thrown if the principals or the keytab file could not be
  * 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);
 }
}

代码示例来源:origin: apache/hadoop-common

private void createKeyTab(String fileName, String[] principalNames)
   throws IOException {
  //create a test keytab file
  List<KeytabEntry> lstEntries = new ArrayList<KeytabEntry>();
  for (String principal : principalNames){
   // create 3 versions of the key to ensure methods don't return
   // duplicate principals
   for (int kvno=1; kvno <= 3; kvno++) {
    EncryptionKey key = new EncryptionKey(
      EncryptionType.UNKNOWN, "samplekey1".getBytes(), kvno);
    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));
 }
}

代码示例来源:origin: com.hortonworks.registries/common-auth

/**
 * 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.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]);
}

代码示例来源:origin: hopshadoop/hops

/**
  * Creates  multiple principals in the KDC and adds them to a keytab file.
  *
  * @param keytabFile keytab file to add the created principal.s
  * @param principals principals to add to the KDC, do not include the domain.
  * @throws Exception thrown if the principals or the keytab file could not be
  * 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);
 }
}

代码示例来源:origin: hopshadoop/hops

private void createKeyTab(String fileName, String[] principalNames)
   throws IOException {
  //create a test keytab file
  List<KeytabEntry> lstEntries = new ArrayList<KeytabEntry>();
  for (String principal : principalNames){
   // create 3 versions of the key to ensure methods don't return
   // duplicate principals
   for (int kvno=1; kvno <= 3; kvno++) {
    EncryptionKey key = new EncryptionKey(
      EncryptionType.UNKNOWN, "samplekey1".getBytes(), kvno);
    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));
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * 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.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]);
 }

代码示例来源:origin: apache/activemq-artemis

public void createPrincipal(File keytabFile, String... principals) throws Exception {
 String generatedPassword = "notSecret!";
 Keytab keytab = new Keytab();
 List<KeytabEntry> entries = new ArrayList<>();
 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);
}

代码示例来源:origin: hortonworks/registry

private void createKeyTab(String fileName, String[] principalNames)
      throws IOException {
    //create a test keytab file
    List<KeytabEntry> lstEntries = new ArrayList<KeytabEntry>();
    for (String principal : principalNames) {
      // create 3 versions of the key to ensure methods don't return
      // duplicate principals
      for (int kvno = 1; kvno <= 3; kvno++) {
        EncryptionKey key = new EncryptionKey(
            EncryptionType.UNKNOWN, "samplekey1".getBytes(), kvno);
        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));
  }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-auth

/**
 * 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.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]);
 }

代码示例来源:origin: apache/hadoop-common

/**
 * 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.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]);
 }

代码示例来源:origin: hopshadoop/hops

/**
 * 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.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]);
 }

代码示例来源:origin: hortonworks/registry

/**
 * 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.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]);
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * 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");
 List<KeytabEntry> entries = Keytab.read(kt).getEntries();
 println("keytab entry count: %d", entries.size());
 for (KeytabEntry entry : entries) {
  EncryptionKey key = entry.getKey();
  println(" %s: version=%d expires=%s encryption=%s",
    entry.getPrincipalName(),
    entry.getKeyVersion(),
    entry.getTimeStamp(),
    key.getKeyType());
 }
 endln();
}

相关文章