简体   繁体   中英

Passing BASIC authentication data into a spring ws client

I have a web service whose server uses basic http authentication to grant access

Web service itself has its own authentication username and password

WS is accessible using SOAP UI after setting the required parameters

I am not developing a UI client which would use the spring to access the web service

my question is How to I send the HTTP authentication that is entered by the user while opening the page to the web server so that he gives me access to the webservice

The current spring ws documentation has an exmple of this here (chapter 6.1) : http://docs.spring.io/spring-ws/site/reference/html/client.html#client-transports

I quote the interesting part of the configuration:

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
  <constructor-arg ref="messageFactory"/>
  <property name="messageSender">
    <bean class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
        <property name="credentials">
            <bean class="org.apache.http.auth.UsernamePasswordCredentials">
                <constructor-arg value="john:secret"/>
            </bean>
        </property>
    </bean>
  </property>
  <property name="defaultUri" value="http://example.com/WebService"/>
</bean>

Last version of Spring WS I used was some time ago (1.x), but you can tap into pretty much anything the Apache Commons HTTPClient API has to offer using Spring WS. When using the WSTemplate system, then the overriding point is the WSMessageSender. But the suggested method above allows to do all directly from Spring configuration.

In your scenario, you could provide an implementation of the UsernamePasswordCredentials that either has a callback to ask the user for the credentials, or have them injected otherwise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM