1. solr-webapp中的web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>solr</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>solr_admin</role-name>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Test Realm</realm-name>
</login-config>
2. solr-jetty-context.xml
<Get name="securityHandler">
<Set name="loginService">
<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>
</New>
</Set>
</Get>
注意此處realm.properties的位置是相對(duì)于jetty.home
3. realm.properties
username: password,role
注意password需要配置成MD5
例如:username=admin, password=12345
admin: MD5:827ccb0eea8a706c4c34a16891f84e7b, admin
生成上述MD5: java -cp jetty-util-9.2.13.v20150730.jar org.eclipse.jetty.util.security.Password admin 12345
修改或者添加密碼后需要重啟服務(wù)
4. Solrj訪問(wèn)時(shí)進(jìn)行相關(guān)權(quán)限設(shè)置街图。參見(jiàn)Solr5部分
http://stackoverflow.com/questions/2014700/preemptive-basic-authentication-with-apache-httpclient-4/11868040#11868040
5. 自動(dòng)更新進(jìn)行權(quán)限設(shè)置甫窟,參考http://www.cnblogs.com/donganwangshi/p/4276015.html
在sendHttpPost(StringcoreName,Stringparams)中添加
String headerKey = "Authorization";
String encoding = username+":"+password;
String headerValue = "Basic " + new BASE64Encoder().encode(encoding.getBytes());
conn.setRequestProperty(headerKey, headerValue);
其中username和password是從配置文件dataimport.properties中讀取的