title: How to pass the roles of a http session to a websocket?
body: <p>In my situation (tomcat) I use tomcat-users.xml to manage the link between users and roles</p>
  
  <pre><code>&lt;tomcat-users&gt;
      &lt;role rolename="role1"/&gt;
      &lt;role rolename="role2"/&gt;
      &lt;user password="tomcat" roles="tomcat" username="tomcat"/&gt;
      &lt;user password="123456" roles="role1,role2" username="user1"/&gt;
  &lt;/tomcat-users&gt;
  </code></pre>
  
  <p>and web.xml is configured like that:</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;com.WebSocketServletListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;security-constraint&gt;
      &lt;display-name&gt;Tomcat Server Configuration Security Constraint&lt;/display-name&gt;
      &lt;web-resource-collection&gt;
        &lt;web-resource-name&gt;Protected Area&lt;/web-resource-name&gt;     
        &lt;url-pattern&gt;/application.jsp&lt;/url-pattern&gt;           
      &lt;/web-resource-collection&gt;
      &lt;auth-constraint&gt;
        &lt;role-name&gt;role1&lt;/role-name&gt;
      &lt;/auth-constraint&gt;
  &lt;/security-constraint&gt;
  &lt;login-config&gt;
      &lt;auth-method&gt;FORM&lt;/auth-method&gt;
      &lt;realm-name&gt;Cloud Authentication&lt;/realm-name&gt;
      &lt;form-login-config&gt;
        &lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;
        &lt;form-error-page&gt;/error.jsp&lt;/form-error-page&gt;
      &lt;/form-login-config&gt;
  &lt;/login-config&gt;
  </code></pre>
  
  <p>The connection to the application has two steps:</p>
  
  <ol>
  <li><p>I log my application via 'login.jsp' referring me to the single page of my application 'application.jsp'. In application.jsp I can know roles of the user connected with request.isUserInRole("role1");</p></li>
  <li><p>application.jsp opens a WebSocket with the server and the webSocket create a session.java. All communications will be done through the WebSocket. The problem is in the context of the webSocket I don't know the roles of my user.</p></li>
  </ol>
  
  <p>What is the best way to recover all user information in the session of the webSocket?</p>