2

I have configured authentication to access solr-admin. I want to provide authentication to all spring-data-solr calls. Below is my configuration, (we have to use spring-data-solr version = 1.5.x.RELEASE)

     <solr:solr-server id="solrServer" url="solrUrl"/>

    <bean id="solrCredentials" class="org.apache.http.auth.UsernamePasswordCredentials">
        <constructor-arg index="0" name="userName" value="username"/>
        <constructor-arg index="1" name="password" value="password"/>
    </bean>

    <bean id="solrServerFactory" class="org.springframework.data.solr.server.support.HttpSolrServerFactory">
        <constructor-arg index="0" name="solrServer" ref="solrServer"/>
        <constructor-arg index="1" name="core"><null/></constructor-arg>
        <constructor-arg index="2" name="credentials" ref="solrCredentials"/>
        <constructor-arg index="3" name="authPolicy" value="BASIC"/>
    </bean>

    <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
        <constructor-arg index="0" name="solrServerFactory" ref="solrServerFactory"/>
    </bean>

    <solr:repositories base-package="com.cisco.iep.content.repository" multicore-support="true" solr-template-ref="solrTemplate"/>

And

public interface CustomSolrCrudRepository<T> extends SolrCrudRepository<T, String> {
// some methods
 }

Problem is, when everytime any class has an @Autowired dependency over the CustomSolrCrudRepository, bean creation flow navigates through SolrRepositoryFactoryBean.afterPropertiesSet(), where it initialises solrServer but not solrOperations. Having provided solrTemplate in the xml configuration, I was expecting solrOperations to get initialised. But it's value is null.

Hence, SolrRepositoryFactory creates a solr template, with new keyboard in SolrRepositoryFactory.createTemplate() and no auth configuration is applied and all my solr calls are resulting in 401 error.

How do I enforce SolrRepositoryFactoryBean to use solrTemplate defined in the xml configuration, am I missing anything here ? Although, spring creates a solrTemplate bean eventually as per above xml configuration, but none of the classes use this bean for any solr related calls. Any help is much appreciated.

0 Answers0