apache cxf中的java消费wcf服务

xghobddn  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(322)

我有一个wcf web服务,其ws-security策略是用c#编写的。此服务对x509证书使用加密和签名策略。
此外,我还使用ApacheCXF用java编写了一个客户机。我的客户端代码如下所示:

  1. URL wsdlURL = Service.WSDL_LOCATION;
  2. if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
  3. File wsdlFile = new File(args[0]);
  4. try {
  5. if (wsdlFile.exists()) {
  6. wsdlURL = wsdlFile.toURI().toURL();
  7. } else {
  8. wsdlURL = new URL(args[0]);
  9. }
  10. } catch (MalformedURLException e) {
  11. e.printStackTrace();
  12. }
  13. }
  14. Map<String, Object> outProps = new HashMap<String, Object>();
  15. outProps.put("action", "Timestamp Signature Encrypt");
  16. outProps.put("passwordType", "PasswordDigest");
  17. outProps.put("signatureUser", "user1");
  18. outProps.put("passwordCallbackClass", "cxfSign.PasswordCallback");
  19. outProps.put("encryptionUser", "user2");
  20. outProps.put("encryptionPropFile", "Client_Encrypt.properties");
  21. outProps.put("encryptionKeyIssuerSerial", "serial");
  22. /* I don't know how to set this part */
  23. outProps.put("encryptionParts", "???");
  24. outProps.put("signaturePropFile", "Client_Sign.properties");
  25. outProps.put("signatureKeyIssuerSerial", "serial2");
  26. /* I don't know how to set this part */
  27. outProps.put("signatureParts", "???");
  28. outProps.put("encryptionKeyTransportAlgorithm",
  29. "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
  30. outProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
  31. Map<String, Object> inProps = new HashMap<String, Object>();
  32. inProps.put("action", "Timestamp Signature Encrypt");
  33. inProps.put("passwordType", "PasswordText");
  34. inProps.put("passwordCallbackClass", "cxfSign.PasswordCallback");
  35. inProps.put("decryptionPropFile", "Client_Sign.properties");
  36. inProps.put("encryptionKeyIssuerSerial", "7ee54c1e1474ce64429fd47d24bf294c3422b7dd");
  37. inProps.put("signaturePropFile", "Client_Encrypt.properties");
  38. inProps.put("signatureKeyIssuerSerial", "6f36d23c8d8ad90b62380d465ca70099d4762201");
  39. inProps.put("encryptionKeyTransportAlgorithm",
  40. "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
  41. inProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
  42. DefaultCryptoCoverageChecker coverageChecker = new DefaultCryptoCoverageChecker();
  43. coverageChecker.setSignBody(true);
  44. coverageChecker.setSignTimestamp(true);
  45. coverageChecker.setEncryptBody(true);
  46. Service ss = new Service(wsdlURL, SERVICE_NAME);
  47. IService port = ss.getCustomBindingIService();
  48. Client client = ClientProxy.getClient(port);
  49. client.getInInterceptors().add(new WSS4JInInterceptor(inProps));
  50. client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
  51. client.getInInterceptors().add(coverageChecker);
  52. {
  53. // calling the method
  54. }

我已尝试正确设置signatureparts和encryptionparts。我需要签署正文和一些标题属性,并加密整个正文。我尝试了一些模式,但出现以下错误:

  1. General security error (WSEncryptBody/WSSignEnvelope: Element to encrypt/sign not found: http://schemas.xmlsoap.org/soap/envelope/, Body)

有人知道如何解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题