title: WS-Security UsernameToken with Apache CXF
body: <p>I have a java application that interacts with a SOAP service. I used the WSDL to generate a java client via CXF, but I need to authenticate my calls using ws-security. I am looking for a code-only way to do this, and I don't have any xml configurations. This is what I have tried:</p>
  
  <pre><code>Map ctx = ((BindingProvider)port).getRequestContext();
  ctx.put("ws-security.username", "joe");
  ctx.put("ws-security.password", "joespassword");
  port.makeSoapCall();
  </code></pre>
  
  <p>But I get a parse error for invalid WS-Security header. What is the right way to do this?</p>
  
  <p>In SOAP UI, I can do this easily by right-clicking the soap header, clicking "Add WSS UsernameToken", and selecting "Password Text"</p>