Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-Data-Solr How to provide authentication data

how do i proivde authentication data for spring data solr server? Here is what i have in configuration

 <solr:solr-server id="solrServer" url="http://xxxxxxxx:8983/solr" />

  <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate" scope="singleton">
    <constructor-arg ref="solrServer" />
  </bean>

  <bean id="searchRepository" class="com.bankofamerica.atmtech.repository.SolrJournalRepository">
    <property name="solrOperations" ref="solrTemplate" />
  </bean>

   <bean id="App" class="App">
    <property name="repo" ref="searchRepository" />
  </bean>

I don't see any property where i can set it.

like image 393
user3799300 Avatar asked Mar 16 '26 12:03

user3799300


1 Answers

You cannot set Credentials directly but have to go through the factory.

@Bean
SolrTemplate solrTemplate() {
  return new SolrTemplate(solrServerFactory());
}

@Bean
SolrServerFactory solrServerFactory() {

  Credentials credentials = new UsernamePasswordCredentials("foo", "bar");
  return new HttpSolrServerFactory(solrServer(), "collection1", credentials , "BASIC");
}

@Bean
SolrServer solrServer() {
  return new HttpSolrServer("http://localhost:8983/solr");
}

I guess some kind of SolrAuthenticationProvider picked up and applied if present in application context would make sense in this case.

like image 91
Christoph Strobl Avatar answered Mar 18 '26 07:03

Christoph Strobl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!