apache cxf中的java消费wcf服务

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

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

URL wsdlURL = Service.WSDL_LOCATION;
    if (args.length > 0 && args[0] != null && !"".equals(args[0])) { 
        File wsdlFile = new File(args[0]);
        try {
            if (wsdlFile.exists()) {
                wsdlURL = wsdlFile.toURI().toURL();
            } else {
                wsdlURL = new URL(args[0]);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put("action", "Timestamp Signature Encrypt");
    outProps.put("passwordType", "PasswordDigest");

    outProps.put("signatureUser", "user1");
    outProps.put("passwordCallbackClass", "cxfSign.PasswordCallback");

    outProps.put("encryptionUser", "user2");
    outProps.put("encryptionPropFile", "Client_Encrypt.properties");
    outProps.put("encryptionKeyIssuerSerial", "serial");

    /* I don't know how to set this part */ 
    outProps.put("encryptionParts", "???");

    outProps.put("signaturePropFile", "Client_Sign.properties");
    outProps.put("signatureKeyIssuerSerial", "serial2");

    /* I don't know how to set this part */ 
    outProps.put("signatureParts", "???");

    outProps.put("encryptionKeyTransportAlgorithm",
            "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
    outProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");

    Map<String, Object> inProps = new HashMap<String, Object>();

    inProps.put("action", "Timestamp Signature Encrypt");

    inProps.put("passwordType", "PasswordText");

    inProps.put("passwordCallbackClass", "cxfSign.PasswordCallback");

    inProps.put("decryptionPropFile", "Client_Sign.properties");
    inProps.put("encryptionKeyIssuerSerial", "7ee54c1e1474ce64429fd47d24bf294c3422b7dd");

    inProps.put("signaturePropFile", "Client_Encrypt.properties");
    inProps.put("signatureKeyIssuerSerial", "6f36d23c8d8ad90b62380d465ca70099d4762201");

    inProps.put("encryptionKeyTransportAlgorithm",
            "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
    inProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");

    DefaultCryptoCoverageChecker coverageChecker = new DefaultCryptoCoverageChecker();
    coverageChecker.setSignBody(true);
    coverageChecker.setSignTimestamp(true);
    coverageChecker.setEncryptBody(true);

    Service ss = new Service(wsdlURL, SERVICE_NAME);
    IService port = ss.getCustomBindingIService();

    Client client = ClientProxy.getClient(port);
    client.getInInterceptors().add(new WSS4JInInterceptor(inProps));
    client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
    client.getInInterceptors().add(coverageChecker);

    {
     // calling the method
    }

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

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

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

暂无答案!

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

相关问题