本文整理汇总了Java中org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory类的典型用法代码示例。如果您正苦于以下问题:Java KerberosKeyFactory类的具体用法?Java KerberosKeyFactory怎么用?Java KerberosKeyFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KerberosKeyFactory类属于org.apache.directory.server.kerberos.shared.crypto.encryption包,在下文中一共展示了KerberosKeyFactory类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPrincipal
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
/**
* 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);
}
示例2: createPrincipal
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
/**
* Creates multiple principals in the KDC and adds them to a keytab file.
*
* @param keytabFile keytab file to add the created principals.
* @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 synchronized 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);
}
示例3: createKeytab
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
public void createKeytab(final String principalName, final String passPhrase, final File keytabFile) throws IOException {
final KerberosTime timeStamp = new KerberosTime();
final int principalType = 1; // KRB5_NT_PRINCIPAL
final Keytab keytab = keytabFile.exists() ? Keytab.read(keytabFile) : Keytab.getInstance();
final List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
for (final 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));
}
entries.addAll(keytab.getEntries());
keytab.setEntries(entries);
keytab.write(keytabFile);
log.debug("Keytab with " + keytab.getEntries().size() + " entries written to " + keytabFile.getAbsolutePath());
}
示例4: generateKeytab
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
private File generateKeytab(String username, String passPhrase,
PrincipalNameType principalNameType) throws KerberosException {
File keytabFile = keytabDirectory.resolve(username + "-" + UUID.randomUUID() + ".ktb").toFile();
keytabFile.getParentFile().mkdirs();
final KerberosTime timeStamp = new KerberosTime(System.currentTimeMillis());
final Keytab keytab = Keytab.getInstance();
String principal = kerberosServer.getPrincipal(username);
final List<KeytabEntry> entries = new ArrayList<>();
for (Map.Entry<EncryptionType, EncryptionKey> keyEntry : KerberosKeyFactory.getKerberosKeys(
principal, passPhrase).entrySet()) {
final EncryptionKey key = keyEntry.getValue();
final byte keyVersion = (byte) key.getKeyVersion();
entries.add(new KeytabEntry(principal, principalNameType.getValue(), timeStamp, keyVersion, key));
}
keytab.setEntries(entries);
try {
keytab.write(keytabFile);
} catch (IOException e) {
throw new KerberosException("Failed to save keytab to file " + keytabFile, e);
}
LOGGER.info("Generated keytab " + keytabFile + " for user " + username);
return keytabFile;
}
示例5: createPrincipal
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
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);
}
示例6: getSupportedEncTypes
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
/**
* Returns comma-separated list of JDK-supported encryption type names for use in krb5.conf.
*
* @return
*/
private String getSupportedEncTypes() {
final List<String> enctypesList = new ArrayList<String>();
for (EncryptionType encType : KerberosKeyFactory.getKerberosKeys("[email protected]", "dummy").keySet()) {
enctypesList.add(encType.getName());
}
return StringUtils.join(enctypesList, ',');
}
示例7: createKeytab
import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; //导入依赖的package包/类
/**
* Creates a keytab file for given principal.
*
* @param principalName
* @param passPhrase
* @param keytabFile
* @throws IOException
*/
protected void createKeytab(final String principalName, final String passPhrase, final File keytabFile) throws IOException {
LOGGER.trace("Principal name: " + principalName);
final KerberosTime timeStamp = new KerberosTime();
DataOutputStream dos = null;
try {
dos = new DataOutputStream(new FileOutputStream(keytabFile));
dos.write(Keytab.VERSION_0X502_BYTES);
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));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream entryDos = new DataOutputStream(baos);
// handle principal name
String[] spnSplit = principalName.split("@");
String nameComponent = spnSplit[0];
String realm = spnSplit[1];
String[] nameComponents = nameComponent.split("/");
try {
// increment for v1
entryDos.writeShort((short) nameComponents.length);
entryDos.writeUTF(realm);
// write components
for (String component : nameComponents) {
entryDos.writeUTF(component);
}
entryDos.writeInt(1); // principal type: KRB5_NT_PRINCIPAL
entryDos.writeInt((int) (timeStamp.getTime() / 1000));
entryDos.write(keyVersion);
entryDos.writeShort((short) key.getKeyType().getValue());
byte[] data = key.getKeyValue();
entryDos.writeShort((short) data.length);
entryDos.write(data);
} finally {
IOUtils.closeQuietly(entryDos);
}
final byte[] entryBytes = baos.toByteArray();
dos.writeInt(entryBytes.length);
dos.write(entryBytes);
}
// } catch (IOException ioe) {
} finally {
IOUtils.closeQuietly(dos);
}
}