On the apache sor config page (admin/config/search/apachesolr) i get this Error:

"401" Status: Unauthorized: UnauthorizedApache Tomcat/6.0.24 - Error report


HTTP Status 401 -


type Status report

message

description This request requires HTTP authentication ().



Apache Tomcat/6.0.24

But apache solr says that it could connect to the server without any problems.

CommentFileSizeAuthor
#6 1780200-5.patch557 bytespwolanin

Comments

pwolanin’s picture

Category: bug » support
Priority: Critical » Normal
cpliakas’s picture

Title: Search engine not working. Apache solr server returns Http status code 401 » How do I connect Apache Solr Search Integration to a Solr server that is protected by HTTP authentication?

description This request requires HTTP authentication ().

It appears that Tomcat needs HTTP authentication based on how it is configured. To me this seems like more of a Tomcat configuration question, but it also might be helpful to have a recipe for HTTP authentication with Apache Solr Search Integration Integration as well.

If you absolutely must have HTTP Authentication, you will have to set the "Authorization" header in the web request. This can be done by extending the DrupalApacheSolrService class and overriding the _makeServletRequest() method to add your header. You will then have to change the service class to your custom one either by setting the "apachesolr_service_class" variable to effect all environments or the "service_class" environment variable.

Just to spell it out further, your class could probably be something as simple as below. Note that I haven't validated the approach so it may need some work.


MyModuleSolrService extends DrupalApacheSolrService {

  protected function _makeHttpRequest($url, $method = 'GET', $headers = array(), $content = '', $timeout = FALSE) {
    $headers['Authorization'] = 'your-auth-string';
    parent::_makeHttpRequest($url, $method, $headers, $content, $timeout);
  }

}

Then you can set either the system variable or Apache Solr environment variable via drush.


// System variable approach
drush vset apachesolr_service_class MyModuleSolrService

// OR ...

// Apache Solr environment variable
drush solr-vset --id=`machine-name-of-env` service_class MyModuleSolrService

Some related topics are posted below:

One additional thought, it might make sense to make this an option that can be configured through the GUI, similar to how Search API does it. There are a lot of steps required to do this, unless I am missing something obvious.

Hope this helps,
Chris

Thili360’s picture

It worked for me too by setting the Server URL to http://username:password@example.com:9080/solr

cpliakas’s picture

Status: Active » Fixed

Thili360,

Haha. Cool! Much simpler.

Thanks for posting back,
Chris

pwolanin’s picture

Component: Code » Documentation
Category: support » feature
Status: Fixed » Active

If that's not in the docs, we should add it . I don't see anything here http://drupal.org/node/343467 nor in the README

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new557 bytes
pwolanin’s picture

Status: Needs review » Fixed

committed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.