android通过Apache CXF生成的客户端类访问webservice带请求的安全认证表头如何实现?

android通过Apache CXF生成的客户端类访问webservice带请求的安全认证表头如何实现?,第1张

UTPP令牌验证是 ws-security 规范中约定的最简单的一种验证方式,以下是5年前我用xfire 的代码,希望能对你有帮助,cxf 也是从 xfire 发展来的,估计语法上大同小异

Client client = ((XFireProxy) ProxygetInvocationHandler(service))getClient();
clientaddOutHandler(new DOMOutHandler());
Properties config = new Properties();
// Action to perform : user token
configsetProperty(WSHandlerConstantsACTION, WSHandlerConstantsUSERNAME_TOKEN);
// Password type : plain text
configsetProperty(WSHandlerConstantsPASSWORD_TYPE, WSConstantsPW_TEXT);
// for hashed password use:
//propertiessetProperty(WSHandlerConstantsPASSWORD_TYPE, WSConstantsPW_DIGEST);
// User name to send
configsetProperty(WSHandlerConstantsUSER, "serveralias");
// Callback used to retrive password for given user
configsetProperty(WSHandlerConstantsPW_CALLBACK_CLASS, PasswordHandlerclassgetName());

clientaddOutHandler(new WSS4JOutHandler(properties));

servicedoSomething()
-------------------------------------------------------------------------------------------------
public class PasswordHandler implements CallbackHandler {
private Map passwords = new HashMap();
public PasswordHandler() {
passwordsput("serveralias", "aliaspass");
passwordsput("client-344-839","client344Password");
}
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
String id = pcgetIdentifer();
pcsetPassword((String) passwordsget(id));
}
}
--------------------------------------------
要用到 wss4j 和 bcprov ,如果仅仅是令牌验证的话,可以不用 bcprov,如果做签名和消息级加密的话,就必须要用到 bcprov 或是其他的安全包了

添加SOAP头之前的请求格式如下:
[html] view plaincopy
<xml version='10' encoding='utf-8'>
<soapenv:Envelope xmlns:soapenv=">终于搞定了方法如下[] [] $strHeaderComponent_Session = "ghdsfsdf04d468f1772f95fgd1bf2b";[] $objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);[] $objHeader_Session_Outside = new SoapHeader(' >直接添加应用,系统会生成Soapheader啊,
没有吗?
生成一个webservice代理,这个代理有一个方法可以设置Soapheader,不需要添加
客户端代理类上应该有SoapHeader属性

axis2 修改 SOAPHeader:

SendSmsServiceStub stub = new SendSmsServiceStub(">

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12704187.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-27
下一篇 2023-05-27

发表评论

登录后才能评论

评论列表(0条)

保存