微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 Apache CXF 使用 WCF 服务

如何解决从 Apache CXF 使用 WCF 服务

我有一个 WCF Web 服务,带有用 C# 编写的 ws-security 策略。 此服务对 X509 证书使用加密和签名策略。

此外,我使用 Apache CXF 用 Ja​​va 编写了一个客户端。 我的客户端代码如下:

Notification notification = new NotificationCompat.Builder(this,"channel01")
        .setSmallIcon(android.R.drawable.ic_dialog_info)
        .setContentTitle("Test")
        .setContentText("You see me!")
        .setDefaults(Notification.DEFAULT_ALL)
        .setPriority(NotificationCompat.PRIORITY_HIGH)   // heads-up
        .build();

notificationmanagerCompat notificationmanager = notificationmanagerCompat.from(this);
notificationmanager.notify(0,notification);

我已尝试正确设置signaturePartsencryptionParts。我需要对 Body 和一些 header 属性 进行签名并加密整个正文。我尝试了一些模式,但出现以下错误

    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
    }

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。