From 1361b02e24bf7f10859021570ad143654501ce85 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 12 Sep 2024 16:03:48 +0100 Subject: [PATCH] Fcrepo 3919 - Make solr endpoint credentials configurable (#200) * 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 * [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 --- README.md | 3 +++ .../indexing/solr/FcrepoSolrIndexingConfig.java | 13 +++++++++++++ .../org/fcrepo/camel/indexing/solr/SolrRouter.java | 13 +++++++++---- .../org/fcrepo/camel/indexing/solr/RouteTest.java | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ffadb085..2da69504 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/FcrepoSolrIndexingConfig.java b/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/FcrepoSolrIndexingConfig.java index d2c09903..e5113478 100644 --- a/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/FcrepoSolrIndexingConfig.java +++ b/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/FcrepoSolrIndexingConfig.java @@ -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; } @@ -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() { diff --git a/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/SolrRouter.java b/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/SolrRouter.java index 3543d1f4..2ff25c99 100644 --- a/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/SolrRouter.java +++ b/fcrepo-indexing-solr/src/main/java/org/fcrepo/camel/indexing/solr/SolrRouter.java @@ -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; @@ -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) */ @@ -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() @@ -167,6 +168,8 @@ public void configure() throws Exception { .otherwise() .log(LoggingLevel.INFO, logger, "Skipping ${header.CamelFcrepoUri}"); + + /* * Send the transformed resource to Solr */ @@ -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"); } diff --git a/fcrepo-indexing-solr/src/test/java/org/fcrepo/camel/indexing/solr/RouteTest.java b/fcrepo-indexing-solr/src/test/java/org/fcrepo/camel/indexing/solr/RouteTest.java index 4249c8db..44f62467 100644 --- a/fcrepo-indexing-solr/src/test/java/org/fcrepo/camel/indexing/solr/RouteTest.java +++ b/fcrepo-indexing-solr/src/test/java/org/fcrepo/camel/indexing/solr/RouteTest.java @@ -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"); }