Apache camel cxf设置Nonce并在SOAP wsse标头中创建

Apache camel cxf设置Nonce并在SOAP wsse标头中创建,apache-camel,cxf,jbossfuse,wsse,Apache Camel,Cxf,Jbossfuse,Wsse,我想使用CXF在WSSE安全头中注入Nonce并创建元素 <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-uti

我想使用CXF在WSSE安全头中注入Nonce并创建元素

<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>

==用户名==
==密码==
==编码字符串===
2016-05-20T10:51:24.795Z
我正在使用org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor类来填充cxf头。但这只会填充wsse:Usernamewsse:Password。我想要wsse:Noncewsse:Created以及我的标题。 我应该采取哪种方法在我的安全标头中填充上述元素

下面是我用来填充的代码

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);
Map properties=newhashmap();
put(WSHandlerConstants.ACTION,“UsernameToken”);
put(WSHandlerConstants.USER,“用户名文本”);
properties.put(WSHandlerConstants.PASSWORD_类型,“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
properties.put(WSHandlerConstants.MUST_理解“true”);
put(WSHandlerConstants.PW_CALLBACK_REF,新的CustomWSPasswordCallback(passwordText));
WSS4JOutInterceptor WSS4JOutInterceptor=新的WSS4JOutInterceptor();
wss4jOutInterceptor.setProperties(属性);
我感谢你的帮助

谢谢,
Ashish Mishra

如果您正在使用WSS4J<2.0,请将此添加到您的属性中:

properties.put(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN);
如果使用WSS4J>=2.0,则应为:

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

如果您使用的是WSS4J<2.0,请将其添加到属性中:

properties.put(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN);
如果使用WSS4J>=2.0,则应为:

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

通过在我的属性映射中添加以下属性,我成功地在WSSE头中注入了Nonce并创建了元素

properties.put(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN);
这对我有用

有关更多信息,请参考

谢谢各位。
Ashish Mishra

我通过在我的属性映射中添加下面的属性,成功地在WSSE头中注入了Nonce并创建了元素

properties.put(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN);
这对我有用

有关更多信息,请参考

谢谢各位。
Ashish Mishra

感谢您的回复。我的WSS4J<2.0,因此上面的内容对我不起作用。但是你可以帮我找到事情的真相。我把我的答案贴在下面。谢谢这篇文章帮助我解决了同样的问题,谢谢!但是,我注意到WSHandlerConstants从org.apache.wss4j.common.ConfigurationConstants继承了这些常量-最好直接从ConfigurationConstants引用它们,因为这将适用于wss4j拦截器的Stax或Dom实现。上面的实现强制您将DOM模块放在构建路径上。感谢您的回复。我的WSS4J<2.0,因此上面的内容对我不起作用。但是你可以帮我找到事情的真相。我把我的答案贴在下面。谢谢这篇文章帮助我解决了同样的问题,谢谢!但是,我注意到WSHandlerConstants从org.apache.wss4j.common.ConfigurationConstants继承了这些常量-最好直接从ConfigurationConstants引用它们,因为这将适用于wss4j拦截器的Stax或Dom实现。上面的实现强制您将DOM模块放在构建路径上。