Showing posts with label SOLR. Show all posts
Showing posts with label SOLR. Show all posts

Saturday, 10 September 2016

How to place http authentication in SOLR?

Tested with SOLR version is 4.4
Place the following code in example\etc\webdefault.xml file under <web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Solr authenticated application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Test Realm</realm-name>
</login-config>

Brief description of above parameters:
url-pattern refers to the url for which this authentication required, since, mentioned as "/*", authentication would be required for any url. Once after authentication happens, application won't ask the authentication until browser session gets destroyed.
role-name refers to the role that access exists. Similarly, we can place separate access for each functionality like search, update, delete etc
realm-name refers to the name used to display while asking for authentication, this should match with the name under set parameters of example\etc\jetty.xml file as follows:

Place the following code under <configure>
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">Test Realm</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
<Set name="refreshInterval">0</Set>
</New>
</Arg>
</Call>
Now, create / update the realm.properties file in etc folder with authentication details as follows:
<username>: <password>, <role>
Eg: user: pwd, admin
So, we can give multiple users with multiple roles and provide access on role basis.

For more information, please refer http://wiki.apache.org/solr/SolrSecurity
If needed to configure realm for TOMCAT, please use UserDatabaseRealm as explained in http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html

How to create multiple indexes in SOLR?

For multiple Indexes, either we need to use multiple SOLRs in different ports or collections/cores.

Multiple SOLR ports can be achieved as follows, we need to have multiple copies of example folder with different port number, port number can be updated in jetty.xml file under example\etc folder. So, we can access two instances separately as http://localhost:8080/solr/#/ (port number : 8080) and http://localhost:8983/solr/#/ (port number : 8983).
For multicore, we have a folder named "multicore" inside example folder. We can see core0 and core1 folders by default. These folders will have separate schema and solrconfig files. Similarly, we have have multiple cores here. The multicore folder will have a solr.xml file. Need to mention each core in this file under <cores> as follows:

<core name="core0" instanceDir="core0" />
<core name="core1" instanceDir="core1" />
<core name="core2" instanceDir="core2" />

Here, instanceDir refers to the folder name and name refers to the path. Now, need to mention the solr home while starting the solr to make multicore as home. The command is as follows:

java -Dsolr.solr.home=multicore -jar start.jar

For multiple collections, create collections(copy the existing and paste) under example\solr with changing the core.properties file, need to mention the current collection name in core.properties file (update the file to text format, place the value, update the file format to txt).

Now, we can start solr without mentioning the solr home, command is java -jar start.jar