title: Does Spring XwsSecurityInterceptor remove the Security element from Header?
body: <p>I have implemented Spring <a href="http://docs.spring.io/spring-ws/site/reference/html/security.html" rel="nofollow">XwsSecurityInterceptor</a> and receiving soap message with <code>&lt;wsse:UsernameToken/&gt;</code> inside the <code>&lt;wsse:Security/&gt;</code> tag (<a href="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0.pdf" rel="nofollow">OASIS WS-Security</a>). It works fine.</p>
  
  <p>Now I am trying to implement a logging interceptor to log the request/response soap messages in DB.</p>
  
  <p>I can get the Security element in <strong><code>getSource()</code></strong> method of my custom logging interceptor (which extends <code>org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor</code>):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  protected Source getSource(WebServiceMessage message) {
      SaajSoapMessage soap = (SaajSoapMessage) message;
      logger.info(Utils.getSoapEnvelopeAsString(soap));
      // this envelop contains the &lt;wsse:Security/&gt; element as expected
      // ...
      // ...
  }
  </code></pre>
  
  <p><strong>But My problem is</strong>, when I extract the envelop inside my endpoint method, I don't get the <strong><code>&lt;wsse:Security/&gt;</code></strong> element in the header anymore.</p>
  
  <pre class="lang-java prettyprint-override"><code>public JAXBElement&lt;MyResponseType&gt; getRecepientInfo(@RequestPayload JAXBElement&lt;MyRequestType&gt; request, MessageContext messageContext) {
      SaajSoapMessage soapReq = (SaajSoapMessage) messageContext.getRequest();
      logger.info(Utils.getSoapEnvelope(soapReq));
      // this envelop doesn't contain the &lt;wsse:Security/&gt; element
  }
  </code></pre>
  
  <p>Here is the code for <code>Utils.getSoapEnvelope(soap)</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static String getSoapEnvelope(SaajSoapMessage soapMessage) {
      SoapEnvelope envelope = soapMessage.getEnvelope();
      String envelopeMessge = "";
      try {
          envelopeMessge = Utils.getSourceAsString(envelope.getSource());
      } catch (Exception e) {
          // TODO handle Exception here.
      }
      return envelopeMessge;
  }
  
  public static String getSourceAsString(Source source) throws Exception{
      TransformerFactory tfactory = TransformerFactory.newInstance();
      Transformer xform = tfactory.newTransformer();
      StringWriter writer = new StringWriter();
      Result result = new StreamResult(writer);
      xform.transform(source, result);
  
      return writer.toString();
  }
  </code></pre>
  
  <p>Does spring remove the <strong><code>&lt;wsse:Security/&gt;</code></strong> element from the header after authentication has been completed? Or, I am doing something wrong here?</p>
  
  <p>How should I get the <strong><code>&lt;wsse:Security/&gt;</code></strong> element from header <strong>inside endpoint method</strong>?</p>