Skip to content

Commit

Permalink
Fcrepo 3919 - Make solr endpoint credentials configurable (#200)
Browse files Browse the repository at this point in the history
* Initial commit of solr basic auth functionality

* reducing log level of solr indexer when using auth

* FCREPO-3834 Enable Camel toolbox to send xml records to Solr indexing service (#191)

* replacing ldpath service with XSLT processing solr indexer

* no longer need HTTP_URI

* added properties for new solr xsl transforms to docker-compose properties file

* returning config to original state rather than my dev stack

* adding fields to solr xsl

---------

Co-authored-by: Dan Field <[email protected]>

* [maven-release-plugin] prepare release fcrepo-camel-toolbox-6.1.0

* [maven-release-plugin] prepare for next development iteration

* Stop using onSpinWait (#203)

Alters Thread.onSpinWait to use latch and await to avoid using CPU cycles to wait.
Also adds additional debug/trace logging to Solr route
Adds the default transform as the default on the property for Solr indexing
Adds some additional documentation on Solr indexing.

* Alterations at Jared's request on PR

* Initial commit of solr basic auth functionality

* reducing log level of solr indexer when using auth

* Alterations at Jared's request on PR

---------

Co-authored-by: Jared Whiklo <[email protected]>
  • Loading branch information
Surfrdan and whikloj authored Sep 12, 2024
1 parent 40041f9 commit 1361b02
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ indexes objects into an external Solr server.
| solr.commitWithin | Milliseconds within which commits should occur | 10000 |
| solr.indexing.predicate | When true, check that resource is of type http://fedora.info/definitions/v4/indexing#Indexable; otherwise do not index it.| false |
| solr.filter.containers | A comma-separate list of containers that should be ignored by the indexer| http://localhost:8080/fcrepo/rest/audit |
| solr.username | Optional username for a Solr server protected with Basic Auth. Must be used in combination with solr.password | |
| solr.password | Optional password for a Solr server protected with Basic Auth. Must be used in combination with solr.username | |


**Note**: You must start with the `file://` protocol when defining the path to a custom XSLT for either the `solr.fcrepo.defaultTransform`
or within the resource using the `http://fedora.info/definitions/v4/indexing#hasIndexingTransformation` predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ static class SolrIndexingEnabled extends ConditionOnPropertyTrue {
@Value("${solr.baseUrl:http://localhost:8983/solr/collection1}")
private String solrBaseUrl;

@Value("${solr.username:}")
private String solrUsername;

@Value("${solr.password:}")
private String solrPassword;

public boolean isCheckHasIndexingTransformation() {
return checkHasIndexingTransformation;
}
Expand Down Expand Up @@ -90,6 +96,13 @@ public String getSolrBaseUrl() {
return solrBaseUrl;
}

public String getSolrUsername() {
return solrUsername;
}

public String getSolrPassword() {
return solrPassword;
}

@Bean(name = "http")
public HttpComponent http() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.support.builder.Namespaces;
import org.fcrepo.camel.processor.EventProcessor;
import org.fcrepo.camel.common.processor.AddBasicAuthProcessor;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import static java.util.stream.Collectors.toList;
import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.HTTP_METHOD;
Expand Down Expand Up @@ -64,7 +64,8 @@ public void configure() throws Exception {
ns.add("indexing", "http://fedora.info/definitions/v4/indexing#");
ns.add("ldp", "http://www.w3.org/ns/ldp#");


final String solrUsername = config.getSolrUsername();
final String solrPassword = config.getSolrPassword();
/*
* A generic error handler (specific to this RouteBuilder)
*/
Expand All @@ -80,8 +81,8 @@ public void configure() throws Exception {
.routeId("FcrepoSolrRouter")
.process(new EventProcessor())
.choice()
.when(or(header(FCREPO_EVENT_TYPE).contains(RESOURCE_DELETION),
header(FCREPO_EVENT_TYPE).contains(DELETE)))
.when(or(header(FCREPO_EVENT_TYPE).contains(RESOURCE_DELETION),
header(FCREPO_EVENT_TYPE).contains(DELETE)))
.log(LoggingLevel.TRACE, "Received message from Fedora routing to delete.solr")
.to("direct:delete.solr")
.otherwise()
Expand Down Expand Up @@ -167,6 +168,8 @@ public void configure() throws Exception {
.otherwise()
.log(LoggingLevel.INFO, logger, "Skipping ${header.CamelFcrepoUri}");



/*
* Send the transformed resource to Solr
*/
Expand All @@ -176,6 +179,8 @@ public void configure() throws Exception {
.setHeader(CONTENT_TYPE).constant("text/xml")
.setHeader(HTTP_METHOD).constant("POST")
.setHeader(HTTP_QUERY).simple("commitWithin=" + config.getCommitWithin())
.process(new AddBasicAuthProcessor(solrUsername, solrPassword))
.log(LoggingLevel.DEBUG, logger, "Authenticating to solr with user: " + solrUsername )
.to(config.getSolrBaseUrl() + "/update?useSystemProperties=true");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public static void beforeClass() {
System.setProperty("solr.baseUrl", solrURL);
System.setProperty("solr.reindex.stream", "seda:reindex");
System.setProperty("solr.fcrepo.checkHasIndexingTransformation", "true");
System.setProperty("solr.username", "solr");
System.setProperty("solr.password", "solrRocks");

}

Expand Down

0 comments on commit 1361b02

Please sign in to comment.