Skip to content

Commit 5bf2c48

Browse files
authored
Merge pull request #23 from BenediktSeidlSWM/auth
Support solr basic authentication
2 parents 3d6d90e + 6d921d3 commit 5bf2c48

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Example:
2828
"config": {
2929
"search_backend": "solr",
3030
"solr_service_url": "http://localhost:8983/solr/gdi/select",
31+
"solr_service_auth": {
32+
"username": "solr",
33+
"password": "SolrRocks"
34+
},
3135
"search_result_sort": "score desc, sort asc",
3236
"word_split_re": "[\\s,.:;\"]+",
3337
"search_result_limit": 50,

schemas/qwc-search-service.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
"description": "SOLR service URL",
2929
"type": "string"
3030
},
31+
"solr_service_auth": {
32+
"description": "SOLR service basic authentication. Default: None",
33+
"type": "object",
34+
"properties": {
35+
"username": {
36+
"description": "Username for SOLR service authentication",
37+
"type": "string"
38+
},
39+
"password": {
40+
"description": "Password for SOLR service authentication",
41+
"type": "string"
42+
}
43+
}
44+
},
3145
"search_result_sort": {
3246
"description": "Search result ordering for solr search results. Default: search_result_sort",
3347
"type": "string"

src/solr_search_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def __init__(self, tenant, logger):
3333

3434
self.solr_service_url = config.get(
3535
'solr_service_url', 'http://localhost:8983/solr/gdi/select')
36+
37+
self.solr_service_auth = config.get('solr_service_auth', None)
38+
39+
if self.solr_service_auth:
40+
self.solr_service_auth = (self.solr_service_auth.get('username'),
41+
self.solr_service_auth.get('password'))
42+
3643
self.word_split_re = re.compile(
3744
config.get('word_split_re', r'[\s,.:;"]+')
3845
)
@@ -85,6 +92,7 @@ def query(self, tokens, filterword, filter_ids, limit, solr_facets):
8592
self.solr_service_url,
8693
params="omitHeader=true&facet=true&facet.field=facet&sort=" +
8794
self.search_result_sort + "&rows={}&{}&{}".format(limit, q, fq),
95+
auth=self.solr_service_auth,
8896
timeout=10)
8997
self.logger.debug("Sending Solr query %s" % response.url)
9098
self.logger.info("Search words: %s", ','.join(tokens))

0 commit comments

Comments
 (0)