I'm trying to creat a SOAP client that has to call a server that uses http basic authentication. I get the following error:
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
...
Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with http://localhost:8080/SpringMVCTest/services/ContractService?wsdl=ContractService.wsdl
My app-config.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/services/*"/>
<security:http-basic/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="wsuser1" password="pw123" authorities="wsuser" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<bean id="client" class="hu.bz.ikti.insurance.service.insurer.ContractService"
factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="hu.bz.ikti.insurance.service.insurer.ContractService"/>
<property name="address" value="http://localhost:8080/SpringMVCTest/services/ContractService?wsdl=ContractService.wsdl"/>
</bean>
</beans>
The http basic auth is configured in the servers web.xml:
<security-constraint>
<web-resource-collection>
<url-pattern>/services/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>wsuser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<role-name>webservice</role-name>
</security-role>
In tomcat-users.xml the user is added:
<user username="wsuser1" password="pw123" roles="wsuser"/>
I can open the wsdl in the browser giving username/password. What can cause this 401: Unauthorized error in the client?
According to the CXF documentation here:
https://cxf.apache.org/docs/jax-ws-configuration.html (see Configuring a Spring Client (Option 2))
The correct way to set the username and password is by using the username
and password
properties in your clientFactory
bean configuration.
그래서 이것을 clientFactory
빈 안에 추가하십시오 .
<property name="username" value="yourUsername"/>
<property name="password" value="yourPassword"/>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다