问题
I am trying to achieve a mutually authenticated REST API server using spark-java and from the documentation I see:
secure(keystoreFilePath, keystorePassword, truststoreFilePath, truststorePassword);
... which looks like exactly what I need. However I am only able to do one way authentication of the server, the client certificate never seems to be verified against the truststore. I'm using version 2.1, any advise or pointers would be greatly appreciated.
回答1:
It seems that Spark in version 2.6.0 has added what you need. Now, there is a second version of secure
:
/** (...) * @param needsClientCert Whether to require client certificate to be supplied in * request (...) */ public synchronized Service secure(String keystoreFile, String keystorePassword, String truststoreFile, String truststorePassword, boolean needsClientCert)
It sets setNeedClientAuth(true)
and setWantClientAuth(true)
on the underlying Jetty webserver SslContextFactory object.
来源:https://stackoverflow.com/questions/41665721/mutual-authentication-with-spark-java