Announcement Announcement Module
Collapse
No announcement yet.
How to pass login credentials in soap header? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass login credentials in soap header?

    I am using Spring WS.

    How to pass login crdentials in soap header?

    could you pls give sample code?

  • #2
    Assuming you are using WebServiceTemplate from spring-ws, you can use an interceptor

    Code:
      <bean id="hdmWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <property name="messageSender" ref="messageSender" />
        <property name="marshaller">
          <oxm:jaxb2-marshaller id="nbiMarshaller" contextPath="com.motive.remotehdm.nbiservice._1" />
        </property>
        <property name="unmarshaller">
          <oxm:jaxb2-marshaller id="nbiUnmarshaller" contextPath="com.motive.remotehdm.nbiservice._1" />
        </property>
        <property name="interceptors">
          <list>
            <ref bean="hdmWsSecurityInterceptor"/>
          </list>
        </property>
      </bean>
    Code:
      <bean id="hdmWsSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
        <property name="securementActions" value="UsernameToken"/>
              <!-- These properties are set at runtime from app properties db table
              property name="securementUsername" value="Ernie"/>
              <property name="securementPassword" value="Bert"/ -->
        <property name="securementMustUnderstand" value="false"/>
      </bean>

    then you can set the username & password statically in the context file as in the commented block above. Or you can set it programatically (which i do to allow such configuration to be set dynamically).

    Code:
        @Inject
        @Named("hdmWsSecurityInterceptor")
        Wss4jSecurityInterceptor secInterceptor;
    
            secInterceptor.setSecurementUsername(propSvc.getProperty(HDM_WS_USER));
            secInterceptor.setSecurementPassword(propSvc.getProperty(HDM_WS_PWD));
            wsTemplate.marshalSendAndReceive(propSvc.getProperty(HDM_WS_URI), req);

    Comment

    Working...
    X