CXF加了ws-security后 怎么访问service里面的方法 谢谢

17 views
Skip to first unread message

stevenmo

unread,
Feb 25, 2008, 11:29:47 PM2/25/08
to cxf-zh
没加前是可以正常访问的 请问我现在需要怎么做才可以访问加了ws-security后的方法 谢谢
加了ws-security后的配置文件
<jaxws:endpoint id="helloWorld" implementor="#hellowordimpl"
address="/HelloWorld">

<jaxws:inInterceptors>
<bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor"/>
<ref bean="wss4jInConfiguration"/>
</jaxws:inInterceptors>
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>

</jaxws:endpoint>
<bean id="wss4jInConfiguration"
class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<property name="properties">
<map>
<entry key="action" value="UsernameToken"/>
<entry key="passwordType" value="PasswordText" />
<entry>
<key>
<value>passwordCallbackRef</value>
</key>
<ref bean="serverPasswordCallback"/>
</entry>
</map>
</property>
</bean>

<bean id="serverPasswordCallback"
class="com.syscanhc.webservice.cxf.callback.SecretPasswordAuth">
<property name="authenticationManager">
<ref bean="authenticationManager" />
</property>
<property name="passwordEncoder" ref="passwordEncoder"/>
</bean>

stevenmo

unread,
Feb 27, 2008, 4:10:34 AM2/27/08
to cxf-zh
参考 http://www.nabble.com/WS-Security-and-CXF-to12365374.html
mhtml:http://dl2.csdn.net/down4/20080214/14132457625.mht
客户端配置作了相应修改 系统还是继续报错 报错原因如以下所示 提示没有axis.jar 包 加了相应jar后 还继续报其它错误 实
在没办法了
请做过相关例子的兄弟姐妹指点一下 谢谢

log4j:WARN No appenders could be found for logger
(org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
2008-2-27 16:54:30
org.apache.cxf.service.factory.ReflectionServiceFactoryBean
buildServiceFromClass
信息: Creating Service {http://
cxf.webservice.syscanhc.com/}HelloWordService from class
com.syscanhc.webservice.cxf.HelloWord
2008-2-27 16:54:32 org.apache.cxf.phase.PhaseInterceptorChain
doIntercept
信息: Interceptor has thrown exception, unwinding now
org.apache.cxf.binding.soap.SoapFault: SOAPEXCEPTION
at
org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor.handleMessage(SAAJOutInterceptor.java:
83)
at
org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor.handleMessage(SAAJOutInterceptor.java:
1)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:
207)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:
73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
142)
at $Proxy26.sayHi(Unknown Source)
at com.syscanhc.webservice.cxf.test.Client.main(Client.java:45)
Caused by: javax.xml.soap.SOAPException: Failed to create
MessageFactory: org.apache.axis.soap.MessageFactoryImpl
at javax.xml.soap.MessageFactory.newInstance(MessageFactory.java:55)
at
org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor.handleMessage(SAAJOutInterceptor.java:
71)
... 8 more
Caused by: java.lang.ClassNotFoundException:
org.apache.axis.soap.MessageFactoryImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at javax.xml.soap.MessageFactory.newInstance(MessageFactory.java:50)
... 9 more
Exception in thread "main" javax.xml.ws.WebServiceException: Cannot
create SAAJ factory instance.
at
org.apache.cxf.jaxws.binding.soap.SOAPBindingImpl.getSOAPFactory(SOAPBindingImpl.java:
118)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
158)
at $Proxy26.sayHi(Unknown Source)
at com.syscanhc.webservice.cxf.test.Client.main(Client.java:45)
Caused by: javax.xml.soap.SOAPException: Failed to create
SOAPConnectionFactory: org.apache.axis.soap.SOAPFactoryImpl
at javax.xml.soap.SOAPFactory.newInstance(SOAPFactory.java:46)
at
org.apache.cxf.jaxws.binding.soap.SOAPBindingImpl.getSOAPFactory(SOAPBindingImpl.java:
113)
... 3 more
Caused by: java.lang.ClassNotFoundException:
org.apache.axis.soap.SOAPFactoryImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at javax.xml.soap.SOAPFactory.newInstance(SOAPFactory.java:41)
... 4 more
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
客户端配置:
<?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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

<bean id="client" class="com.syscanhc.webservice.cxf.HelloWord"
factory-bean="clientFactory" factory-method="create" />

<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass"
value="com.syscanhc.webservice.cxf.HelloWord" />
<property name="address"
value="http://localhost:8080/gs/webservice/HelloWorld" />
<property name="outInterceptors">
<list>
<bean
class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor" />
<ref bean="wss4jOutConfiguration" />
</list>
</property>

</bean>

<bean id="wss4jOutConfiguration"
class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<property name="properties">
<map>
<entry key="action" value="UsernameToken" />
<entry key="user" value="ws-client" />
<entry key="passwordType" value="PasswordText" />
<entry>
<key>
<value>passwordCallbackRef</value>
</key>
<ref bean="passwordCallback" />
</entry>
</map>
</property>
</bean>
<bean id="passwordCallback"
class="com.syscanhc.webservice.cxf.test.PasswordCallback" >

</bean>

</beans>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
com.syscanhc.webservice.cxf.test.PasswordCallback

public class PasswordCallback implements CallbackHandler {
//protected final Log logger = LogFactory.getLog(getClass());

public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
int usage = pc.getUsage();

System.out.println("identifier: " + pc.getIdentifer());
System.out.println("usage: " + pc.getUsage());
if (usage == WSPasswordCallback.USERNAME_TOKEN) {
// username token pwd...

pc.setPassword("");
} else if (usage == WSPasswordCallback.SIGNATURE) {
// set the password for client's keystore.keyPassword
pc.setPassword("keyPassword");
}
}
}
}

willem

unread,
Feb 27, 2008, 4:52:39 AM2/27/08
to cxf-zh
Caused by: javax.xml.soap.SOAPException: Failed to create
MessageFactory: org.apache.axis.soap.MessageFactoryImpl
at
javax.xml.soap.MessageFactory.newInstance(MessageFactory.java:55)
at
org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor.handleMessage(SAAJOutInterceptor.java:

CXF 使用的是SUN 的SAAJ 实现,你的运行环境里面用的是axis的SAAJ实现。
请把你的CLASS PATH 整理一下,把SUN 的saaj jar放到CLASS PATH的前面。

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com
> xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://cxf.apache.org/jaxwshttp://cxf.apache.org/schema/jaxws.xsd">

stevenmo

unread,
Feb 27, 2008, 7:46:57 AM2/27/08
to cxf-zh
除了这个还有其它原因吗 因为我只用到apache-cxf-2.1-incubator自带的两个包 saaj-api-1.3.jar
saaj-impl-1.3.jar 系统里面没有用到axis 的任何包

Willem Jiang

unread,
Feb 27, 2008, 8:27:01 AM2/27/08
to cxf...@googlegroups.com
你是不是将应用步骤到tomcat 中了 如果是这样那你还是检查一下相关的目录

stevenmo

unread,
Feb 27, 2008, 9:07:42 AM2/27/08
to cxf-zh
找到原因了 使用的myeclipse 有个plug 自带了 jboss-saaj.jar 删掉可以了

stevenmo

unread,
Feb 27, 2008, 11:47:38 PM2/27/08
to cxf-zh
请教 willem , 在客户端的client-bean.xml wss4jOutConfiguration中 user可否动态配置 ,我希
望可以在CallbackHandler 中动态的赋值过去

willem

unread,
Feb 28, 2008, 3:49:21 AM2/28/08
to cxf-zh
你是可以在WSS4JOutInterceptor 中设置CallbackHandler,具体和你server端的设置差不多。
有关Jaxws Client的Spring配置你可以参考CXF user guide[1]

[1]http://cwiki.apache.org/CXF20DOC/jax-ws-configuration.html

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com

stevenmo

unread,
Feb 28, 2008, 8:04:35 AM2/28/08
to cxf-zh
不是CallbackHandler设置问题 我是想问怎么在CallbackHandler中动态的设置user的值 通过什么可以设置
identifer

willem

unread,
Feb 28, 2008, 9:23:42 AM2/28/08
to cxf-zh
明白你的意思了,你的问题可以通过设置Message Context来解决,而不需要通过CallbackHandler
1. 通过CXF API设置客户端请求的消息的context
2. 设置针对WSS4JOutInterceptor有效的userId

下面是具体的代码
HelloWorldPortType greeter = service.getPort(portName,
HelloWorldPortType.class);
InvocationHandler handler =
Proxy.getInvocationHandler(greeter);
BindingProvider bp = null;

if (handler instanceof BindingProvider) {
bp = (BindingProvider)handler;

Map<String, Object> requestContext =
bp.getRequestContext();

requestContext.put(WSHandlerConstants.USER,
"myAlias");
requestContext.put("password", "myAliasPassword");
}

String greeting = greeter.greetMe("HelloWorld!");

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com

On 2月28日, 下午9时04分, stevenmo <mokai...@gmail.com> wrote:
> 不是CallbackHandler设置问题 我是想问怎么在CallbackHandler中动态的设置user的值 通过什么可以设置
> identifer

stevenmo

unread,
Feb 28, 2008, 9:02:51 PM2/28/08
to cxf-zh
我问的问题比较实在 呵呵 这正是我急需的 谢谢 Willem

willem

unread,
Mar 2, 2008, 8:18:47 PM3/2/08
to cxf-zh
如果你想通过XML来配置用户名和密码的话可以参考下面的代码片断

<bean id="wss4jOut"
class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="user" value="ws-client" />
<entry key="passwordType" value="PasswordText" />
<entry key="passwordCallbackClass"
value="com.company.auth.service.ClientPasswordCallback" />
</map>
</constructor-arg>
</bean>

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com



On 2月29日, 上午10时02分, stevenmo <mokai...@gmail.com> wrote:
> 我问的问题比较实在 呵呵 这正是我急需的 谢谢 Willem
Reply all
Reply to author
Forward
0 new messages