title: Connecting a rails application with sunspot to a tomcat/solr server with authorization
body: <p>Okay, so I have a separate server with solr and this connects perfectly fine with the app. Using the usual sunspot.yml we have something like:</p>
  
  <pre><code>production:
    solr:
      hostname: domain
      port: 8080
      log_level: WARNING
      path: path/to/data
  </code></pre>
  
  <p>The problem is I wanted to authorization to my tomcat app. It seems that as long as you know the domain and port you could just go and visit solr/admin. So in my tomcat web.xml I added:</p>
  
  <pre><code>&lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
        &lt;web-resource-name&gt; 
          Solr authenticated application
        &lt;/web-resource-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
        &lt;http-method&gt;GET&lt;/http-method&gt;
        &lt;http-method&gt;POST&lt;/http-method&gt;
      &lt;/web-resource-collection&gt;
      &lt;auth-constraint&gt;
        &lt;role-name&gt;role&lt;/role-name&gt;
      &lt;/auth-constraint&gt;
    &lt;/security-constraint&gt;
     &lt;login-config&gt;
      &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
      &lt;realm-name&gt;REALM&lt;/realm-name&gt;
    &lt;/login-config&gt;
    &lt;security-role&gt;
      &lt;description&gt;ROLE NAME&lt;/description&gt;
      &lt;role-name&gt;role&lt;/role-name&gt;
    &lt;/security-role&gt;
  </code></pre>
  
  <p>This would require anyone visiting solr/admin a username and password before being granted access. The problem is how do I tell my rails app about this? After doing this and I get an expected "Unauthorized" response when my rails app tries to access the solr server. I know it would probably go into the sunspot.yml file but what do I have to add?</p>