Permalink
Browse files

Added basic authentication

  • Loading branch information...
1 parent aa281d5 commit 0aef4b4ec0fb9db00a96858d10f11a2e5c18b270 @aseldawy aseldawy committed with dcrec1 Jan 28, 2010
Showing with 12 additions and 5 deletions.
  1. +3 −1 config/solr.yml
  2. +3 −1 lib/acts_as_solr.rb
  3. +6 −3 lib/solr/connection.rb
View
@@ -5,10 +5,12 @@
development:
url: http://127.0.0.1:8982/solr
+ username: tomcat
+ password: tomcat
test:
url: http://127.0.0.1:8981/solr
production:
url: http://127.0.0.1:8983/solr
- jvm_options: -server -d64 -Xmx1024M -Xms64M
+ jvm_options: -server -d64 -Xmx1024M -Xms64M
View
@@ -53,7 +53,9 @@ def self.execute(request, core = nil)
url = 'http://localhost:8982/solr'
end
url += "/" + core if !core.nil?
- connection = Solr::Connection.new(url)
+ connection = Solr::Connection.new(url,
+ :username=>config[ENV['RAILS_ENV']]['username'],
+ :password=>config[ENV['RAILS_ENV']]['password'])
return connection.send(request)
rescue
raise "Couldn't connect to the Solr server at #{url}. #{$!}"
View
@@ -42,6 +42,8 @@ def initialize(url="http://localhost:8983/solr", opts={})
@connection = Net::HTTP.new(@url.host, @url.port)
@connection.read_timeout = opts[:timeout] if opts[:timeout]
+ @username = opts[:username] if opts[:username]
+ @password = opts[:password] if opts[:password]
end
# add a document to the index. you can pass in either a hash
@@ -153,9 +155,10 @@ def send(request)
# send the http post request to solr; for convenience there are shortcuts
# to some requests: add(), query(), commit(), delete() or send()
def post(request)
- response = @connection.post(@url.path + "/" + request.handler,
- request.to_s,
- { "Content-Type" => request.content_type })
+ req = Net::HTTP::Post.new(@url.path + "/" + request.handler,
+ { "Content-Type" => request.content_type })
+ req.basic_auth(@username, @password) if @username && @password
+ response = @connection.request(req, request.to_s)
case response
when Net::HTTPSuccess then response.body

0 comments on commit 0aef4b4

Please sign in to comment.