我採用的是cxf
加密端用的 WSS4J
服務端查詢數據庫 信息 而後發佈服務 客戶端調用 服務端 實現數據保護加密服務的功能
WSS4J有三種驗證方式本項目採用 最簡單的一種 UsernameToken用戶名密碼驗證
Cxf mss4j加密模塊 系統集成說明:所需環境 Spring
由於cxf是很是方便與spring集成的 而且支持註解
client_Spring.xml放到src/main/resources下
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd">
<bean id="clientPasswordCallback" class="com.prisys.ws.client.ClientPasswordCallback"></bean>
<bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<!-- 用戶認證(明文密碼) -->
<entry key="action" value="UsernameToken"/>
<entry key="user" value="client"/>
<entry key="passwordType" value="PasswordText"/>
<entry key="passwordCallbackRef" value-ref="clientPasswordCallback"/>
</map>
</constructor-arg>
</bean>
<jaxws:client id="client" address="http://localhost:9080/SOA_Server/webservice/gtinfo"
serviceClass="com.prisys.ws.service.CxfClientSOA">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
<ref bean="wss4jOutInterceptor"/>
</jaxws:outInterceptors>
</jaxws:client>
<jaxws:client id="updateFile" address="http://localhost:9080/SOA_Server/webservice/updateFile"
serviceClass="com.prisys.ws.service.CxfClientSOA">
</jaxws:client>
<!-- 對全部的服務配置超時機制 只對服務名爲{http://service.ws.cxfdemo.com/}HelloWorldService的服務生效. -->
<http-conf:conduit name="*.http-conduit">
<!-- ConnectionTimeout獲取鏈接超時 ReceiveTimeout獲取結果超時-->
<http-conf:client ConnectionTimeout="15000" ReceiveTimeout="30000"/>
</http-conf:conduit>
</beans>
Pom.xml:
<!-- CXF START -->
<!-- CXF依賴 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>2.7.9</version>
</dependency>
<!-- CXF END -->
加密支持類 :
package com.prisys.ws.client;
import java.io.IOException;
import java.util.Date;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
public class ClientPasswordCallback implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
System.out.println(new Date());
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
callback.setPassword("這裏填你本身想填的密碼");
}
}
其餘按照cxf正常發佈模式就行了 須要源碼的 進羣討論 186408628