Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fcrepo 3919 - Make solr endpoint credentials configurable #200

Merged
merged 11 commits into from
Sep 12, 2024
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ indexes objects into an external Solr server.
| 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.ldpath.service.baseUrl | The LDPath service base url | http://localhost:9085/ldpath |
| 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 | |


### Repository Indexer (Triplestore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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 @@ -97,6 +103,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 @@ -8,10 +8,13 @@
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.support.builder.Namespaces;
import org.apache.camel.builder.PredicateBuilder;
import org.apache.camel.Predicate;
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 org.apache.commons.lang3.StringUtils;
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 @@ -58,7 +61,10 @@ 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();
final Predicate useSolrAuth = PredicateBuilder.constant(
"true".equals(!StringUtils.isEmpty(solrUsername) && !StringUtils.isEmpty(solrPassword)));
Surfrdan marked this conversation as resolved.
Show resolved Hide resolved
/*
* A generic error handler (specific to this RouteBuilder)
*/
Expand All @@ -74,8 +80,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 All @@ -101,8 +107,8 @@ public void configure() throws Exception {
header(FCREPO_URI).isEqualTo(constant(uri))))
.collect(toList()))))
.choice()
.when(and(simple(config.isIndexingPredicate() + " != 'true'"),
simple(config.isCheckHasIndexingTransformation() + " != 'true'")))
.when(and(simple(config.isIndexingPredicate() + " != 'true'"),
simple(config.isCheckHasIndexingTransformation() + " != 'true'")))
.setHeader(INDEXING_TRANSFORMATION).simple(config.getDefaultTransform())
.to("direct:update.solr")
.otherwise()
Expand Down Expand Up @@ -172,6 +178,7 @@ public void configure() throws Exception {
.otherwise()
.log(LoggingLevel.INFO, logger, "Skipping ${header.CamelFcrepoUri}");


/*
* Send the transformed resource to Solr
*/
Expand All @@ -180,6 +187,12 @@ public void configure() throws Exception {
.removeHeaders("CamelHttp*")
.setHeader(HTTP_METHOD).constant("POST")
.setHeader(HTTP_QUERY).simple("commitWithin=" + config.getCommitWithin())
.choice()
.when(useSolrAuth)
.process(new AddBasicAuthProcessor(solrUsername, solrPassword))
.log(LoggingLevel.DEBUG, logger, "Authenticating solr with: " + solrUsername + ":" + solrPassword)
.otherwise()
.log(LoggingLevel.DEBUG, logger, "No Solr Auth provided")
Surfrdan marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading