我有一个Java应用程序,我正在添加一个JAX-WS接口,我已经让它通过HTTPS运行,但我希望能够进行双向SSL身份验证。我有密钥库和证书设置并且信任两种方式,但我可以找到用于在服务器端验证客户端证书的所有代码示例都不起作用,因为我没有在Tomcat / Glassfish中运行它,如下所示:
@Resource WebServiceContext wsCtx;
@WebMethod
public int add(@WebParam(name="i") int i, @WebParam(name="j") int j) {
MessageContext context = wsCtx.getMessageContext();
Subject clientSubject = null;
try {
clientSubject = SubjectAccessor.getRequesterSubject(context);
} catch(Exception e) {
e.printStackTrace();
}
if (clientSubject != null) {
Set publicCreds = clientSubject.getPublicCredentials(
for (Iterator it = publicCreds.iterator(); it.hasNext();) {
System.out.println("Client Cert:" + it.next());
//use our code to create the Certificate here.
break;
}
} else {
System.out.println("Client Cert not set");
}
....
获取上下文对象和检查客户端证书匹配的本机等价物是什么?谢谢!