I wanted to update unused code that is now required in order for a Java Vert.x application to authenticate to Kerberos protected api endpoint. However the kerberos packages ( io.vertx.ext.auth.kerberos ) are no longer recognised. My application runs in a Kubernetes namespace where the the k5b5.conf file is mounted to the pod that would run a variation of below class that is simplified.
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpClient;
import io.vertx.ext.auth.AuthOptions;
import io.vertx.ext.auth.User;
import io.vertx.ext.auth.kerberos.KerberosAuthOptions;
import io.vertx.ext.auth.kerberos.KerberosOptions;
import io.vertx.ext.web.client.HttpRequest;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
public class KerberosVerticle extends AbstractVerticle {
@Override
public void start(Promise<Void> startPromise) {
WebClient webClient = createWebClient();
HttpRequest<String> request = webClient.getAbs("https://example-kerberos-protected-api.com/resource");
request.send(response -> {
if (response.succeeded()) {
System.out.println("Response: " + response.result().bodyAsString());
startPromise.complete();
} else {
response.cause().printStackTrace();
startPromise.fail(response.cause());
}
});
}
private WebClient createWebClient() {
WebClientOptions options = new WebClientOptions()
.setSsl(true)
.setUseAlpn(true)
.setTrustAll(true);
AuthOptions authOptions = new KerberosAuthOptions()
.setKrb5Config("/etc/krb5.conf"); // Path to krb5.conf file
KerberosOptions kerberosOptions = new KerberosOptions()
.setAuthOptions(authOptions);
return WebClient.create(vertx, options)
.authKerberos(kerberosOptions);
}
}
Would expect methods createWebClient to return a Vert.x Webclient instance but class fails to compile.