我正在使用Java Metro框架发布Web服务,
我将ssl握手配置为需要来自客户端的ssl证书,
如何在服务器代码中捕获ssl客户端证书详细信息?
感谢帮助
最佳答案
我找到了问题的解决方案,
以CalculatorWS为例,您必须编写以下代码以获得证书详细信息:
@WebService()
public class CalculatorWS {
// NEW
private WebServiceContext wsCtx;
@Resource
private void setWSContext(WebServiceContext wsCtx) {
this.wsCtx = wsCtx;
}
// END NEW
public CalculatorWS() {}
@WebMethod(operationName = "add", action="add")
public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
// NEW
if (this.wsCtx != null) {
MessageContext msgCtx = this.wsCtx.getMessageContext();
HttpServletRequest httpSR = (HttpServletRequest)msgCtx.get(MessageContext.SERVLET_REQUEST );
X509Certificate[] x509Cert = (X509Certificate[])httpSR.getAttribute("javax.servlet.request.X509Certificate");
}
// END NEW
...