本文整理了Java中org.apache.kerby.kerberos.kerb.keytab.Keytab.loadKeytab()
方法的一些代码示例,展示了Keytab.loadKeytab()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Keytab.loadKeytab()
方法的具体详情如下:
包路径:org.apache.kerby.kerberos.kerb.keytab.Keytab
类名称:Keytab
方法名:loadKeytab
暂无
代码示例来源:origin: apache/zookeeper
@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);
}
代码示例来源:origin: org.apache.hadoop/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");
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();
}
代码示例来源:origin: org.apache.kerby/kerb-admin
/**
* Load keytab from keytab file.
*
* @param keytabFile The keytab file
* @return The keytab load from keytab file
* @throws KrbException If there is a problem loading the keytab
*/
public 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;
}
代码示例来源:origin: apache/directory-kerby
/**
* Load keytab from keytab file.
*
* @param keytabFile The keytab file
* @return The keytab load from keytab file
* @throws KrbException If there is a problem loading the keytab
*/
public 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;
}
代码示例来源:origin: apache/directory-kerby
/**
* 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<>();
List<PrincipalName> entries = keytab.getPrincipals();
for (PrincipalName entry : entries) {
principals.add(entry.getName().replace("\\", "/"));
}
return principals.toArray(new String[0]);
}
代码示例来源:origin: org.apache.hadoop/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.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]);
}
代码示例来源:origin: org.apache.kerby/kerb-admin
/**
* 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 If there is a problem creating or loading the keytab
*/
public 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 "
+ keytabFile.getAbsolutePath(), e);
}
return keytab;
}
代码示例来源:origin: apache/directory-kerby
/**
* 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 If there is a problem creating or loading the keytab
*/
public 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 "
+ keytabFile.getAbsolutePath(), e);
}
return keytab;
}
代码示例来源:origin: org.apache.kerby/kerb-client
private Keytab getKeytab() {
File keytabFile = null;
KOptions kOptions = getRequestOptions();
if (kOptions.contains(KrbOption.KEYTAB_FILE)) {
keytabFile = kOptions.getFileOption(KrbOption.KEYTAB_FILE);
}
if (kOptions.contains(KrbOption.USE_DFT_KEYTAB)) {
final String clientKeytabEnv = System.getenv("KRB5_CLIENT_KTNAME");
final String clientKeytabDft = getContext().getConfig().getString(
"default_client_keytab_name");
if (clientKeytabEnv != null) {
keytabFile = new File(clientKeytabEnv);
} else if (clientKeytabDft != null) {
keytabFile = new File(clientKeytabDft);
} else {
System.err.println("Default client keytab file not found.");
}
}
Keytab keytab = null;
try {
keytab = Keytab.loadKeytab(keytabFile);
} catch (IOException e) {
System.err.println("Can not load keytab from file" + keytabFile.getAbsolutePath());
}
return keytab;
}
代码示例来源:origin: org.apache.kerby/client-tool
Keytab keytab = Keytab.loadKeytab(keytabFile);
List<PrincipalName> principals = keytab.getPrincipals();
for (PrincipalName principal : principals) {
代码示例来源:origin: apache/directory-kerby
private Keytab getKeytab() {
File keytabFile = null;
KOptions kOptions = getRequestOptions();
if (kOptions.contains(KrbOption.KEYTAB_FILE)) {
keytabFile = kOptions.getFileOption(KrbOption.KEYTAB_FILE);
}
if (kOptions.contains(KrbOption.USE_DFT_KEYTAB)) {
final String clientKeytabEnv = System.getenv("KRB5_CLIENT_KTNAME");
final String clientKeytabDft = getContext().getConfig().getString(
"default_client_keytab_name");
if (clientKeytabEnv != null) {
keytabFile = new File(clientKeytabEnv);
} else if (clientKeytabDft != null) {
keytabFile = new File(clientKeytabDft);
} else {
System.err.println("Default client keytab file not found.");
}
}
Keytab keytab = null;
try {
keytab = Keytab.loadKeytab(keytabFile);
} catch (IOException e) {
System.err.println("Can not load keytab from file" + keytabFile.getAbsolutePath());
}
return keytab;
}
代码示例来源:origin: apache/directory-kerby
Keytab keytab = Keytab.loadKeytab(keytabFile);
List<PrincipalName> principals = keytab.getPrincipals();
for (PrincipalName principal : principals) {
内容来源于网络,如有侵权,请联系作者删除!