use of com.zimbra.cs.security.kerberos.Krb5Keytab in project zm-mailbox by Zimbra.
the class GssAuthenticator method initialize.
@Override
public boolean initialize() throws IOException {
Krb5Keytab keytab = getKeytab(LC.krb5_keytab.value());
if (keytab == null) {
sendFailed("mechanism not supported");
return false;
}
debug("keytab file = %s", keytab.getFile());
final String host;
if (LC.krb5_service_principal_from_interface_address.booleanValue()) {
String localSocketHostname = localAddress.getCanonicalHostName().toLowerCase();
if (localSocketHostname.length() == 0 || Character.isDigit(localSocketHostname.charAt(0)))
localSocketHostname = LC.zimbra_server_hostname.value();
host = localSocketHostname;
} else {
host = LC.zimbra_server_hostname.value();
}
KerberosPrincipal kp = new KerberosPrincipal(getProtocol() + '/' + host);
debug("kerberos principal = %s", kp);
Subject subject = getSubject(keytab, kp);
if (subject == null) {
sendFailed();
return false;
}
debug("subject = %s", subject);
final Map<String, String> props = getSaslProperties();
if (DEBUG && props != null) {
String qop = props.get(Sasl.QOP);
debug("Sent QOP = " + (qop != null ? qop : "auth"));
}
try {
mSaslServer = (SaslServer) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws SaslException {
return Sasl.createSaslServer(getMechanism(), getProtocol(), host, props, new GssCallbackHandler());
}
});
} catch (PrivilegedActionException e) {
sendFailed();
getLog().warn("Could not create SaslServer", e.getCause());
return false;
}
return true;
}
Aggregations