Добавление UsernameToken в Spring-WS

Я пытаюсь вызвать WS, для которого имя пользователя и пароль должны быть переданы в заголовке безопасности Soap в UsernameToken. Ниже мой код, в котором я использовал Wss4jSecurityInterceptor

public Wss4jSecurityInterceptor securityInterceptor() {
    Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor();
    securityInterceptor.setValidationActions("UsernameToken");
    securityInterceptor.setSecurementUsername("username");
    securityInterceptor.setSecurementPassword("pwd");
    securityInterceptor.setSecurementPasswordType("PasswordText");
    securityInterceptor.setSecurementMustUnderstand(true);
    return securityInterceptor;
}

Spring WebserviceTemplate:

private WebServiceTemplate getTemplate() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("stubs");
    WebServiceTemplate template = new WebServiceTemplate();
    template.setDefaultUri(defaultUri);
    template.setMarshaller(marshaller);
    template.setUnmarshaller(marshaller);
    ClientInterceptor[] interceptors = new ClientInterceptor[] { securityInterceptor() };
    template.setInterceptors(interceptors);
    return template;
}

Как я звоню в сервис:

getTemplate().marshalSendAndReceive(request, new SoapActionCallback("ws_endpoint"));

Я не смог получить действительный заголовок безопасности, как показано ниже:

   <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken>
            <wsse:Username>username</wsse:Username>
            <wsse:Password>pwd</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>

0 ответов

Другие вопросы по тегам