cxf设置Nonce并在SOAP wsse标头中创建 [英] cxf setting Nonce and created in SOAP wsse header

查看:64
本文介绍了cxf设置Nonce并在SOAP wsse标头中创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用CXF在WSSE安全标头中注入Nonce和Created元素.

I wanted to inject Nonce and Created element in WSSE security header using CXF.

<soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-6">
            <wsse:Username>==Username==</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">==Password==</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">===EncodeString===</wsse:Nonce>
            <wsu:Created>2016-05-20T10:51:24.795Z</wsu:Created>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

我正在使用org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor类填充CXF标头.但这只会填充 wsse:用户名 wsse:Password .我的标题中也需要 wsse:Nonce wsse:Created .我应该采用哪种方法来填充安全标头中的以上元素?

I'm using org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor class to populate the CXF headers. But this populates only wsse:Username and wsse:Password. I wanted wsse:Nonce and wsse:Created as well in my header. Which Approach I should take to populate above elements in my security header?

下面是我用来填充此代码的代码

Below is the code which I'm using to populate this,

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(WSHandlerConstants.ACTION, "UsernameToken");
properties.put(WSHandlerConstants.USER, "userName-Text");
properties.put(WSHandlerConstants.PASSWORD_TYPE, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
properties.put(WSHandlerConstants.MUST_UNDERSTAND, "true");
properties.put(WSHandlerConstants.PW_CALLBACK_REF, new CustomWSPasswordCallback(passwordText));

WSS4JOutInterceptor wss4jOutInterceptor = new WSS4JOutInterceptor();
wss4jOutInterceptor.setProperties(properties);

感谢您的帮助.

谢谢,阿什什·米什拉(Ashish Mishra)

Thanks, Ashish Mishra

推荐答案

如果您使用的是WSS4J<2.0:

Add this to your properties if you are using WSS4J < 2.0:

properties.put(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN);

如果使用WSS4J> = 2.0,则应为:

if using WSS4J >= 2.0 then it should be:

properties.put(WSHandlerConstants.ADD_USERNAMETOKEN_NONCE, "true");
properties.put(WSHandlerConstants.ADD_USERNAMETOKEN_CREATED, "true");

这篇关于cxf设置Nonce并在SOAP wsse标头中创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆