wss4j和axis2实现WS-Security(2)
转自:http://hi.baidu.com/zhaopengletter/blog/item/44a3bdfa9eda29244e4aea48.html
?
???? <parameter name="InflowSecurity">
?????? <action>
???????? <items>Timestamp Signature</items>
???????? <signaturePropFile>keys/client.properties</signaturePropFile>
?????? </action>
???? </parameter>
注意一下红色的部分他是当客户端向服务器端发送数据时,首先访问com.neusoft.wss4j.rempart.demo.services.PWCBHandler这个类,得到访问权限和加密信息的文件密码,然后通过加密信息的文件密码和keys/client.properties文件找到加密需要的文件client.jks把信息加密发送给服务器端,粉色部分是通过keys/client.properties文件找到解密需要的文件client.jks来解密服务器端返回的加密信息。
Keys文件下的client.properties内容如下:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=apache
org.apache.ws.security.crypto.merlin.file=keys/client.jks
?
五、总??结
整理一下思路
1 客户端发送消息给服务器端:如果客户端想请求服务器端首先读取客户端配置文件axis2.xml文件,得到访问的用户<user>client</user>然后找到com.neusoft.wss4j.rempart.demo.services.PWCBHandler类,看用户是否有访问服务的权限,如果有则把client.jks文件的密码给用户client,client通过密码在axis2.xml文件中找到<signaturePropFile>keys/client.properties</signaturePropFile>找到client.properties文件,在client.properties文件中找到client.jks文件,使用该文件的client私钥从而实现把传送的信息加密,然后把加密的信息发送到服务器端。
2 服务器端接收客户端发送来的消息:服务器端接收到消息,然后读取service.xml文件找到<signaturePropFile>keys/service.properties</signaturePropFile>从而找到service.properties文件,通过该文件找到service.jks文件使用该文件的client的公钥
解密客户端传送来的信息。
3 服务器端返回信息给客户端: 获得客户端传送过来的明文信息后,从service.xml文件
得到加密的用户<user>service</user>通过
<passwordCallbackClass>
com.neusoft.wss4j.rempart.demo.services.PWCBHandler
</passwordCallbackClass>
找到验证类PWCBHandler得到加密需要的service.jks的加密密码apache
通过<signaturePropFile>
????keys/service.properties
????</signaturePropFile>找到service.properties文件,通过该文件找到service.jks文件,通过该文件的service的私钥把需要发送给客户端的信息加密。然后发送给客户端
4 客户端接收服务器端返回的消息:客户端端接收到消息,然后读取axis2.xml文件找到<signaturePropFile>keys/service.properties</signaturePropFile>从而找到client.properties文件,通过该文件找到client.jks文件使用该文件的service的公钥
解密服务器端返回来的信息。