如果服务端使用了ws-security进行用户验证时,客户端访问时需要在报文头部添加用户名和密码,用户令牌验证只允许在报文头部添加验证。采用axis2生成java代码,以下为实现代码:
//stub为生成的代码
stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,"http:.....?wsdl");
//安全头报文生成
SOAPHeaderElement sl = setSoapHeader();
stub.setHeader(sl);
stub.method(arg0, arg1);
private static SOAPHeaderElement setSoapHeader() throws ParserConfigurationException{
// create document of w3c
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
// create Element
String address= "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
Element security = document.createElementNS("namespace", "Security");
security.setAttribute("xmlns:wsse", address);
Element usernameToken = document.createElementNS("namespace", "UsernameToken");
Element username = document.createElementNS("namespace", "Username");
Element password = document.createElementNS("namespace", "Password");
password.setAttribute("Type",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
// add Element
usernameToken.appendChild(username);
usernameToken.appendChild(password);
security.appendChild(usernameToken);
// set value
Text usernameValue = document.createTextNode("aaaa");
username.appendChild(usernameValue);
Text passwordValue = document.createTextNode("aaaa");
password.appendChild(passwordValue);
// create SOAPHeaderElement
SOAPHeaderElement ppElement = new SOAPHeaderElement(security);
ppElement.setPrefix("wsse");
return ppElement;
}
分享到:
相关推荐
纯java调用ws-security+CXF实现的webservice安全接口
内含: ISNetworksProvider.jar tsik.jar ws-security.jar 和wss4j的所有包
axis2-idea-plugin-1.7.9
axis2客户端调用服务端,带用户身份认证
axis2客户端调用axis1服务接口 调用方式 使用RPC方式调用WebService,为了防止冲突可以增加 // 与weblogic的lib冲突配置 System.setProperty("javax.xml.stream.XMLInputFactory", ...
这个文档详细描述了本人实现axis2+rampart ,有截图和详细配置
axis2-eclipse-codegen-plugin-1.6.2.zip和axis2-eclipse-service-plugin-1.6.2.zip,解压即可使用
共四个文件,都是最先版的,希望可以帮助大家。axis2-eclipse-service-archiver-wizard和axis2-eclipse-codegen-wizard和axis2-1.6.1-bin和axis2-1.6.1-war
Axis2和Axis2客户端所需包 activation-1.1.jar axiom-api-1.2.7.jar axiom-impl-1.2.7.jar axis2-1.5-war.zip axis2-adb-1.4.1.jar...
axis2-java2wsdl-1.2.jar axis2-kernel-1.2.jar commons-codec-1.3.jar commons-httpclient-3.0.1.jar commons-logging-1.1.jar stax-api-1.0.1.jar wsdl4j-1.6.2.jar wstx-asl-3.2.1.jar xmlschema-1.3.1....
目前axis2最高版本是2.0以上的版本,但是eclipse和myeclipse都不支持,无奈只能使用低版本的插件1.6.3;经实验,可以安装成功; 安装方法:右键解压到当前文件夹,Copy解压的文件到eclipse安装目录dropins下,重启...
包含webservice客户端开发所需要所有jar包, axiom-api-1.2.13.jar,axis2-adb-1.4..jar,axis2-adb-1.6.2.jar,axiom-dom-1.2.13.jar,axis2-kernel-1.6.2.jar,axis2-transport-http-1.6.2.jar,axis2-transport-...
支持开发 Axis2 的动力是探寻模块化更强、灵活性更高和更有效的体系结构,这种体系结构可以很容易地插入到其他相关 Web 服务标准和协议(如 WS-Security、WS-ReliableMessaging 等)的实现中。 Apache Axis2 是Axis...
1、axis2相关jar包如下: axiom-api-1.2.10.jar axiom-dom-1.2.10.jar axiom-impl-1.2.10.jar axis2-adb-1.5.4.jar axis2-adb-codegen-1.5.4.jar axis2-codegen-1.5.4.jar axis2-corba-1.5.4.jar axis2-fastinfoset-...
绝对可以用,里面配有myeclipse10安装AXIS2插件的步骤,希望大家工作愉快,谢谢,给好评哦
axis,jax-ws,xfire客户端调用分析,以及webservice万能客户端
axis2-eclipse-service-archiver-wizard.zip
axis2-std-1.0-bin.zip与axis2.war axis2-std-1.0-bin.zip与axis2.war
axis2包含axis2-1.4.1-war.zip和axis2-1.4.1-bin.zip,希望大家喜欢。
axis2-eclipse-codegen-plugin-1.6.2+axis2-eclipse-service-plugin-1.6.2