javax.xml.soap.SOAPException:java.security.ProviderException:无法派生密钥

时间:2018-08-20 14:26:39

标签: java soap ws-security

我正在将SOAP请求发送到端点。我正在使用Axis2。下面的代码在我的环境中运行良好,但是在Linux安装程序上却给出了例外。 Linux安装程序在客户端和服务器之间使用消息代理。

public SOAPMessage createSOAPMessage(SOAPMessage request, String endpoint) throws Exception {


    ConfigurationContext configurationContext = getConfigurationContext();

    // initialize URL
    URL url;
    try {
        url = new URL(endpoint);
    } catch (MalformedURLException e) {
        throw new Exception("Invalid Endpoint: " + endpoint + ", " + e.getMessage(), e);
    }

    // initialize and set Options
    Options options = new Options();
    options.setTo(new EndpointReference(url.toString()));

    try {
        serviceClient = new ServiceClient(configurationContext, null);
        operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
    } catch (AxisFault e) {
        throw new SOAPException(e.getMessage(), e);
    }

    options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, 
            request.getProperty(SOAPMessage.CHARACTER_SET_ENCODING));
    operationClient.setOptions(options);
    MessageContext requestMsgCtx = new MessageContext();
    SOAPEnvelope envelope = SAAJUtil.toOMSOAPEnvelope(request.getSOAPPart().getDocumentElement());
    requestMsgCtx.setProperty(HTTPConstants.CHUNKED, "false");

    Map<String,String> httpHeaders = null;
    for (Iterator it = request.getMimeHeaders().getAllHeaders(); it.hasNext(); ) {
        MimeHeader header = (MimeHeader)it.next();
        String name = header.getName().toLowerCase();
        if (name.equals("soapaction")) {
            requestMsgCtx.setSoapAction(header.getValue());
        } else {
            if (httpHeaders == null) {
                httpHeaders = new HashMap<String,String>();
            }
            httpHeaders.put(header.getName(), header.getValue());
        }
    }

    if (httpHeaders != null) {
        requestMsgCtx.setProperty(HTTPConstants.HTTP_HEADERS, httpHeaders);
    }

    MessageContext responseMsgCtx;

    try {
        requestMsgCtx.setEnvelope(envelope);
        operationClient.addMessageContext(requestMsgCtx);
        operationClient.execute(true);
        responseMsgCtx = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    } catch (AxisFault ex) {
        throw new SOAPException(ex.getMessage(), ex);
    }

    return getSOAPMessage(responseMsgCtx.getEnvelope());
}

错误是:

  

javax.xml.soap.SOAPException:java.security.ProviderException:无法派生密钥

两个环境都使用WS-security和Java 1.8u51。我仔细检查了证书,它看起来不错。

请咨询。

1 个答案:

答案 0 :(得分:1)

问题是由于在Linux机器上的JVM中加载了Bouncy Castle jar。有弹性的城堡罐子是我们项目的一部分。我们使用以下代码行列出了JVM中用于Linux设置的证券库,而有弹性的城堡就是其中之一。我们从环境中删除了jar,它开始工作。请注意,Linux计算机上的Java版本是1.8u51。

try {
        Provider pArray[] = Security.getProviders();
        if (log.isDebugEnabled()) {
            log.debug("Availble number of Providers are -> " + pArray.length);
        }

        for (int i = 0; i < pArray.length; i++) {
            Provider p = pArray[i];
            if (log.isDebugEnabled()) {
                log.debug(p + ", Info-> " + p.getInfo() + ", Class -> " + p.getClass().getName());
            }
            for (Enumeration e = p.keys(); e.hasMoreElements();) {
                if (log.isDebugEnabled()) {
                    log.debug("\t" + e.nextElement());
                }
            }
        }
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("List all security provider failed. " + e);
        }
    }

我们可以尝试将Java升级到最新的Java 8版本,而不是删除jar。