use of javax.security.auth.kerberos.KerberosPrincipal in project calcite-avatica by apache.
the class KerberosConnection method performKerberosLogin.
/**
* Performs a Kerberos login given the {@code principal} and {@code keytab}.
*
* @return The {@code Subject} and {@code LoginContext} from the successful login.
* @throws RuntimeException if the login failed
*/
Entry<LoginContext, Subject> performKerberosLogin() {
// Loosely based on Apache Kerby's JaasKrbUtil class
// Synchronized by the caller
// Create a KerberosPrincipal given the principal.
final Set<Principal> principals = new HashSet<Principal>();
principals.add(new KerberosPrincipal(principal));
final Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
try {
return login(null, jaasConf, subject);
} catch (Exception e) {
throw new RuntimeException("Failed to perform Kerberos login");
}
}
use of javax.security.auth.kerberos.KerberosPrincipal in project zm-mailbox by Zimbra.
the class Krb5Keytab method readEntry.
private void readEntry(FileChannel fc) throws IOException {
int size = readInt(fc);
if (size < 0) {
// Skip deleted entry
long newPos = fc.position() + -size;
if (newPos >= fc.size()) {
throw new EOFException();
}
fc.position(newPos);
return;
}
ByteBuffer bb = readBytes(fc, size);
try {
KerberosPrincipal kp = getPrincipal(bb);
KerberosKey key = getKey(bb, kp);
addKey(kp, key);
} catch (ArrayIndexOutOfBoundsException e) {
throw formatError("Invalid entry size " + size);
}
}
use of javax.security.auth.kerberos.KerberosPrincipal in project zm-mailbox by Zimbra.
the class Krb5Keytab method dump.
/**
* Prints contents of keytab to specified stream.
*
* @param ps The PrintStream to which the keytab contents are written
*/
public void dump(PrintStream ps) {
ps.printf("Keytab name: %s\n", file);
ps.printf("Keytab version: 0x%x\n", version);
ps.printf("KVNO Principal\n");
ps.print("---- ");
for (int i = 0; i < 75; i++) ps.print('-');
ps.println();
for (KerberosPrincipal kp : keyMap.keySet()) {
for (KerberosKey key : keyMap.get(kp)) {
ps.printf("%4d %s (%s) (0x%x)\n", key.getVersionNumber(), kp.getName(), getKeyTypeName(key.getKeyType()), new BigInteger(1, key.getEncoded()));
}
}
}
use of javax.security.auth.kerberos.KerberosPrincipal in project ddf by codice.
the class PropertyFileClaimsHandler method getUser.
/**
* Obtains the user name from the principal.
*
* @param principal Describing the current user that should be used for retrieving claims.
* @return the user name if the principal has one, null if no name is specified or if principal is
* null.
*/
public String getUser(Principal principal) {
String user = null;
if (principal instanceof KerberosPrincipal) {
KerberosPrincipal kp = (KerberosPrincipal) principal;
StringTokenizer st = new StringTokenizer(kp.getName(), "@");
user = st.nextToken();
} else if (principal instanceof X500Principal) {
X500Principal x500p = (X500Principal) principal;
StringTokenizer st = new StringTokenizer(x500p.getName(), ",");
while (st.hasMoreElements()) {
// token is in the format:
// syntaxAndUniqueId
// cn
// ou
// o
// loc
// state
// country
String[] strArr = st.nextToken().split("=");
if (strArr.length > 1 && strArr[0].equalsIgnoreCase("cn")) {
user = strArr[1];
break;
}
}
} else if (principal != null) {
user = principal.getName();
}
return user;
}
use of javax.security.auth.kerberos.KerberosPrincipal in project ddf by codice.
the class AttributeMapLoader method getUser.
/**
* Obtains the user name from the principal.
*
* @param principal Describing the current user that should be used for retrieving claims.
* @return the user name if the principal has one, null if no name is specified or if principal is
* null.
*/
public String getUser(Principal principal) {
String user = null;
if (principal instanceof KerberosPrincipal) {
KerberosPrincipal kp = (KerberosPrincipal) principal;
StringTokenizer st = new StringTokenizer(kp.getName(), "@");
st = new StringTokenizer(st.nextToken(), "/");
user = st.nextToken();
} else if (principal instanceof X500Principal) {
X500Principal x500p = (X500Principal) principal;
StringTokenizer st = new StringTokenizer(x500p.getName(), ",");
while (st.hasMoreElements()) {
// token is in the format:
// syntaxAndUniqueId
// cn
// ou
// o
// loc
// state
// country
String[] strArr = st.nextToken().split("=");
if (strArr.length > 1 && strArr[0].equalsIgnoreCase("cn")) {
user = strArr[1];
break;
}
}
} else if (principal != null) {
user = principal.getName();
}
return user;
}
Aggregations