Spring WS / WebServiceTemplate + Wss4jSecurityInterceptor - different credentials per Request
17:13 03 Jan 2026

Problem:

I need kind of a client to communicate with WebService via SOAP in Java - Spring application. And I have one endpoint / resource and various users who have different certificates to obtain STS token.

For now, I am considering Spring WS and met the challenge that WebServiceTemplate is a Singleton bean where I can set a certificate during configuration (via Wss4jSecurityInterceptor) and, of course, cannot change it in run-time because the other threads will not be happy.

My current solutions:

  1. Override WebServiceMessageCallback and write code for building WS-Sec header manually.

  2. Creating WebServiceTemplate for each request.

I cannot find any good solutions and ways to handle and get it right with prepared tools. That is weird because the case seems not unusual.

So, the main goal is to have a configured client where I can pass certificates or username and password in run time. And that client can deal with WS-Security and build a necessary header. My questions:

  • Did anyone face the same challenge? How did you handle it?

  • Maybe someone can propose other tools / technologies / libraries which will be able to resolve that case?

java soap-client spring-ws ws-security wss4j