使用 SSL 客户端身份验证的 Jetty 信任库身份验证
我正在尝试制作一个使用客户端密钥进行客户端身份验证的网络应用程序。我想我已经解决了整个信任库问题,因此我可以对客户端进行实际身份验证。但是我不想要求客户端身份验证。我只想测试它并启用功能(如果已启用)。
我可以使用 .wantClientAuth 来请求它,但如果它不存在则允许连接。但我找不到任何属性来确定请求是否已通过身份验证。
这个应该存在,不然wantClientAuth的目的是什么。我该如何使用它?
I'm trying to make a web-app with using client keys for client authentication. I think I've figured out the whole truststore problem so I can get the client actually authenticated. However I don't want to require client auth. I just want to test for it and enable features if it's enabled.
I can use .wantClientAuth which will request it, but allow connection if it doesn't exist. But I can't find any property to find out if the request has been authenticated.
This should exist, otherwise what is the purpose of wantClientAuth. How do I use it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有在这里运行设置,现在无法对其进行测试,但不应该
request.getUserPrincipal()
和
request.getAuthType()
给你你想要的。请参阅 http://www.docjar.com/docs/api/ javax/servlet/http/HttpServletRequest.html
(假设您可以在您工作的上下文中访问 servlet 请求)
I don't have the setup running here, to test it right now, but shouldn't
request.getUserPrincipal()
and
request.getAuthType()
give you what you want.See http://www.docjar.com/docs/api/javax/servlet/http/HttpServletRequest.html
(That assumes you have access to the servlet request in the context in which you're working)
如果您使用 servlet API,请使用 Tim 的方法。以下是一些其他想法,具体取决于您的调用上下文。
握手完成后,您可以在 SSLSession 上调用 getCertChain。如果为空,则客户端未使用客户端证书进行身份验证。
请参阅此处的自定义方法:
http://www.javadocexamples .com/java_source/org/mortbay/jetty/security/SslSocketConnector.java.html
或者,您可以在 HttpsURLConnection 上调用 getLocalPrincipal 或 getLocalCertificates。如果它们为空,则没有客户端证书。
If you're using the servlet API use Tim's method. Here are some other ideas depending your calling context..
After the handshake completes you could call getCertChain on the SSLSession. If it's null then the client didn't authenticate with a client cert.
See the customize method here:
http://www.javadocexamples.com/java_source/org/mortbay/jetty/security/SslSocketConnector.java.html
Alternatively you could call getLocalPrincipal or getLocalCertificates on the HttpsURLConnection. If they're null then there is no client cert.