Connecting the rails sunspot application to the tomcat / solr server with authorization

Ok, so I have a separate server with solr, and this is great for the application. Using regular sunspot.yml, we have something like:

production: solr: hostname: domain port: 8080 log_level: WARNING path: path/to/data 

The problem is that I wanted to get permission for my tomcat application. It looks like as long as you know the domain and port, you can just go and visit solr / admin. So in my tomcat web.xml I added:

 <security-constraint> <web-resource-collection> <web-resource-name> Solr authenticated application </web-resource-name> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>role</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>REALM</realm-name> </login-config> <security-role> <description>ROLE NAME</description> <role-name>role</role-name> </security-role> 

This will require someone to visit the username and password of solr / admin before gaining access. The problem is, how can I say this in my rails application? After that, I get the expected "Unauthorized" response when my rails application tries to access the solr server. I know that it will probably go into the sunspot.yml file, but what do I need to add?

+4
source share
2 answers

I am not sure if Sunspot configuration supports Basic Auth username and password through YAML. These parameters are combined together to be assigned to Sunspot.config.solr.url and then transmitted to RSolr. To fix this simple request, a stretch request https://github.com/outoftime/sunspot .

You might be better off either by assigning Sunspot.config.solr.url directly in the initializer, or by specifying the URL through an environment variable. Sunspot supports the SOLR_URL and WEBSOLR_URL environment variables, and you must save the Basic Auth username and password.

To test this in your development environment:

 rake sunspot:reindex SOLR_URL=http://admin: foobar@localhost :8983/solr rails server SOLR_URL=http://admin: foobar@localhost :8983/solr 
+7
source

https://github.com/justinko/sunspot-rails-http-basic-auth

gem install this. its basic HTTP authentication for sunspot_rails. You can then enter the username and password in sunspot.yml, which is generated.

+1
source

Source: https://habr.com/ru/post/1347099/


All Articles