title: How to configure a websocket service in Apache Knox with basic authentication
body: <p>I managed to configure a websocket service in Knox which for test purposes is <code>ws://echo.websocket.org</code></p>
  
  <p>Here are my configuration files:</p>
  
  <p><strong>service.xml</strong></p>
  
  <pre><code>&lt;service role="ECHOWS" name="echows" version="0.0.1"&gt;
    &lt;policies&gt;
          &lt;policy role="webappsec"/&gt;
          &lt;policy role="authentication" name="Anonymous"/&gt;
          &lt;policy role="rewrite"/&gt;
          &lt;policy role="authorization"/&gt;
    &lt;/policies&gt;
    &lt;routes&gt;
      &lt;route path="/echows"&gt;
          &lt;rewrite apply="ECHOWS/echows/inbound" to="request.url"/&gt;
      &lt;/route&gt;
    &lt;/routes&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p><strong>rewrite.xml</strong></p>
  
  <pre><code>&lt;rules&gt;
    &lt;rule dir="IN" name="ECHOWS/echows/inbound" pattern="*://*:*/**/echows"&gt;
      &lt;rewrite template="{$serviceUrl[ECHOWS]}"/&gt;
    &lt;/rule&gt;
  &lt;/rules&gt;
  </code></pre>
  
  <p><strong>{topology}.xml</strong> section:</p>
  
  <pre><code>&lt;service&gt;
      &lt;role&gt;ECHOWS&lt;/role&gt;
      &lt;url&gt;ws://echo.websocket.org&lt;/url&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p>I can connect to it:</p>
  
  <pre><code>wscat -c wss://my-knox-server/gateway/default/echows
  connected (press CTRL+C to quit)
  &gt; Hello Knox!
  &lt; Hello Knox!
  </code></pre>
  
  <p>But I'd like Knox accept connection only when proper credentials are given:</p>
  
  <pre><code>wscat --auth &lt;username:password&gt; -c wss://my-knox-server/gateway/default/echows
  </code></pre>
  
  <p>My Knox configuration for http services works in this way that I have to put credentials, otherwise I get 401:</p>
  
  <pre><code>curl -i https://my-knox-server/gateway/default/my_service/ping
  HTTP/1.1 401 Unauthorized
  
  curl -i -u '&lt;user&gt;:&lt;password&gt;' https://my-knox-server/gateway/default/my_service/ping
  HTTP/1.1 200 OK
  </code></pre>
  
  <p>I'd like to achieve the same result with websockets.</p>
  
  <p>[EDIT]</p>
  
  <p>Moreover I don't fully understand the above <strong>service.xml</strong> configuration for my websocket service, since it is different than the simplest possible configuration for a http service I was able to use:</p>
  
  <pre><code>&lt;service role="MY_APP" name="my_app" version="0.0.1"&gt;
      &lt;routes&gt;
          &lt;route path="/my_app/**"/&gt;
      &lt;/routes&gt;
  &lt;/service&gt;
  </code></pre>
  
  <ol>
  <li>Why in case of a websocket service I need <code>policies</code>, and what do they mean?</li>
  <li>Why <code>&lt;routes&gt;/&lt;route&gt;</code> has an element <code>&lt;rewrite&gt;</code> and what is its semantics? Does it correspond to <code>&lt;rule&gt;/&lt;rewrite&gt;</code> from <strong>rewrite.xml</strong>? What does <code>request.url</code> mean there?</li>
  </ol>