Saturday, 26 January 2013

1) Download the Apache Solr 3.6 and build the example.

2) Edit  /example/etc/jetty.xml

<Set name="UserRealms">
<Array type="org.mortbay.jetty.security.UserRealm">
<Item>
<New class="org.mortbay.jetty.security.HashUserRealm">
                   <Set name="name">Test Realm</Set>
                   <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
</New>
       </Item>
</Array>
</Set>

3) Edit /example/etc/webdefault.xml

<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>core1-role</role-name>
       </auth-constraint>
</security-constraint>

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

4) Create new file /example/etc/realm.properties

    guest: guest, core1-role
5) Start the server and verfiy on http://localhost:8983/solr/. You will get the following screen to input the credentials (Fig. 1)

    java -jar start.jar

http://localhost:8983/solr/



6) Configuring the SolrJ to create connection with the Solr Server using Basic
Authentication Realm:

…...
CommonsHttpSolrServer solr = new CommonsHttpSolrServer("http://localhost:8983/solr");
Credentials defaultcreds = new UsernamePasswordCredentials("guest", "guest");
solr.getHttpClient().getState().setCredentials(new AuthScope("localhost", 8983,
AuthScope.ANY_REALM), defaultcreds);
solr.getHttpClient().getParams().setAuthenticationPreemptive(true);
…..
Categories: , , , , ,

0 comments:

Post a Comment

Find me on Facebook! Follow me on Twitter!