Client SOAP basic auth: réponse HTTP '401: non autorisé"
Je suis en train de créer un client SOAP qui a pour appeler un serveur qui utilise l'authentification http de base.
J'obtiens l'erreur suivante:
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
Mon app-config.xml est:
<?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>
Le http basic auth est configuré sur les serveurs 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>
Dans tomcat-users.xml l'utilisateur est ajouté:
<user username="wsuser1" password="pw123" roles="wsuser"/>
Je peux ouvrir le fichier wsdl dans le navigateur de donner le nom d'utilisateur/mot de passe.
Ce qui peut provoquer cette 401: erreur non autorisée de la client?
Vous devez vous connecter pour publier un commentaire.
Selon la CXF documentation ici:
https://cxf.apache.org/docs/jax-ws-configuration.html (voir Configuration d'un Printemps Client (Option 2))
La bonne façon de définir le nom d'utilisateur et le mot de passe à l'aide de la
username
etpassword
propriétés dans votreclientFactory
configuration spring.Donc ajouter ces à l'intérieur de votre
clientFactory
bean:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'user'
j'ai ajouté le préfixe basé sur le web exemple. Peut-être que j'ai besoin d'un xsi:schemaLocation pour l'utilisateur (peut-être pour l'authentification, etc) éléments.clientFactory
bean.