当前位置: 代码迷 >> Java Web开发 >> cxf ws-security 加密和签名有关问题?
  详细解决方案

cxf ws-security 加密和签名有关问题?

热度:7782   发布时间:2013-02-25 21:19:24.0
cxf ws-security 加密和签名问题???
存在问题:服务器端的WSS4J拦截器不执行,其它运行正常!配置代码如下:

一.客户端:
1.applicationContext-client.xml
<?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"
xsi:schemaLocation="  
  http://www.springframework.org/schema/beans  
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://cxf.apache.org/jaxws  
  http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg type="java.util.Map">
<map>
<entry key="action" value="Signature" />
<entry key="user" value="apmclient" />
<entry key="passwordCallbackClass"
value="client.ClientPasswordCallback" />
<entry key="signaturePropFile" value="client_sign.properties"></entry>
</map>
</constructor-arg>
</bean>
<jaxws:client id="service"
address="http://localhost:8080/SIPService1/service/AlgorithmService" serviceClass="service.IAlgorithmService">
<jaxws:outInterceptors>
<ref bean="wss4jOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>

</beans>

2.client_sign.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=keystorePass
#org.apache.ws.security.crypto.merlin.alias.password=apmclientpass
org.apache.ws.security.crypto.merlin.keystore.alias=apmclient
org.apache.ws.security.crypto.merlin.file=clientStore.jks

3.客户端的拦截类(正常执行)
public class ClientPasswordCallback implements CallbackHandler {

public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
pc.setPassword("apmclientpass");
pc.setIdentifier("admin");
System.out.println("-----------client---------------"+pc.getIdentifier());
}
}

}

4.调用代码
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "client/applicationContext-client.xml" });

IAlgorithmService service = (IAlgorithmService) context
.getBean("service");

InputInfo inputInfo = new InputInfo();
inputInfo.setSentenceA("我住在北京");

OutputInfo oi = service.getAnalyticStructure(inputInfo);
System.out.println("-----------" + oi.getSubject());
System.out.println("-----------" + oi.getPredicate());
System.out.println("-----------" + oi.getObject());
System.out.println("-----------" + oi.getSubjectAttribute());
System.out.println("-----------" + oi.getObjectAttribute());
System.out.println("-----------" + oi.getAdverbial());
System.out.println("-----------" + oi.getComplement());
System.out.println("-----------" + oi.getTimeAdverbial());
System.out.println("-----------" + oi.getLocationAdverbial());
  相关解决方案