title: How to get/set the principal and session attributes from Spring 4 stomp websocket methods
body: <p>I'm doing experiments with <a href="http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/htmlsingle/#websocket-stomp" rel="noreferrer">Spring 4 websockets and stomp</a>, and I have a hard time figuring out how to get/set the current user and other session attributes in a message handling method annotated with <code>@MessageMapping</code>.</p>
  
  <p><a href="http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/htmlsingle/#websocket-stomp-handle-annotations" rel="noreferrer">The documentation</a> says that the message handling methods can take a Principal as argument, and I found that the principal is retrieved by Spring by calling <code>getUserPrincipal()</code> on the native socket session, and then associated with the socket session, but I haven't found any way to easily customize this behavior, other than writing a servlet filter and wrap the original request into a wrapper returning the principal found in my cookie.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>How to manually set the principal to the socket session, when the client connects (I have this information thanks to a custom cookie, and I don't use Spring security)?</li>
  <li>If 1 is not possible, how to add additional attributes to the socket session when the client connects?</li>
  <li>How to access the socket session and its attributes from a message handling method?</li>
  <li>Is there a way to access the login and passcode sent by the browser at connection time. They seem to be completely ignore by Spring and not accessible.</li>
  </ol>