I am current Apache Tomcat user designing an Akka HTTP based replacement for a HTTPS web service that uses client certificates for authentication and authorization. Using Tomcat I am accustomed to retrieving the client X509Certificate with a servlet request attribute
request.getAttribute("javax.servlet.request.X509Certificate")
I need the certificate for some additional authorization checks inside the handler for select routes. How would retrieve the client certificate in this way with Akka HTTP 10.0.x?
You need to enable decorating requests with TLS session info through the config settings for the server:
akka.http.server.parsing.tls-session-info-header = on
And then extract the info for a specific request using the synthetic header akka.http.scaladsl.model.headers.Tls-Session-Info
like so:
headerValueByType[`Tls-Session-Info`]() { sessionInfo =>
val sslSession = sessionInfo.getSession()
sslSession.getPeerCertificates
... etc ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.