cxf配置
1.server端配置server.xml文件内容如下:
<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:util="http://www.springframework.org/schema/util"
?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://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.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="myPasswordCallback" />
?<jaxws:endpoint id="helloWorld" implementor="cxf.spring.HelloWorldImpl"
??address="/HelloWorld">
??<jaxws:inInterceptors>
???<bean value="UsernameToken" />
??????<entry key="passwordType" value="PasswordText" />
??????<entry key="passwordCallbackRef">
???????<ref bean="myPasswordCallback" />
??????</entry>
?????</map>
????</constructor-arg>
???</bean>
??</jaxws:inInterceptors>
?</jaxws:endpoint>
</beans>
?
ServerPasswordCallback.java文件内容如下:
package cxf.spring;
import java.io.IOException;
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 ServerPasswordCallback implements CallbackHandler {
?public void handle(Callback[] callbacks) throws IOException,
???UnsupportedCallbackException {
??WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
??if (pc.getIdentifier().equals("kevin")) {
???pc.setPassword("asdfff");
??}
?}
}
?
2.client端配置文件内容client.xml内容如下:
<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.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="myPasswordCallback" />
?<jaxws:client id="helloWorld" servicevalue="UsernameToken" />
??????<entry key="user" value="kevin" />
??????<entry key="passwordType" value="PasswordText" />
??????<entry key="passwordCallbackRef">
???????<ref bean="myPasswordCallback" />
??????</entry>
?????</map>
????</constructor-arg>
???</bean>
??</jaxws:outInterceptors>
?</jaxws:client>
</beans>
?
ClientPasswordCallback.java内容如下:
package cxf.spring;
import java.io.IOException;
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 pc = (WSPasswordCallback) callbacks[0];
??pc.setPassword("asdfff");
?}
}