Getting a X509Certificate from a SOAP Security Header

后端 未结 1 1279
抹茶落季
抹茶落季 2021-01-21 17:47

Everybody, Hello!

I have a simple stub client for the cxf web-service (spring app). It uses a WSS4JOutInterceptor with action = \"Signature\" So that, the

相关标签:
1条回答
  • 2021-01-21 17:55

    The solution is to use a BinarySecurityToken header's element:

    SoapMessage soapMessage = (SoapMessage) message;
    SOAPMessage doc = getSOAPMessage(soapMessage);
    
    Element elem = WSSecurityUtil.getSecurityHeader(doc.getSOAPPart(), "");
    // get a BinarySignature tag
    Node binarySignatureTag = elem.getFirstChild();
    BinarySecurity token = new X509Security((Element) binarySignatureTag);
    
    // a X509Certificate construction
    InputStream in = new ByteArrayInputStream(token.getToken());
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
    

    as you can see, you also need to use the org.apache.ws.security package.

    0 讨论(0)
提交回复
热议问题