问题
I have installed solr 7.7 standalone in my production server. I am trying to setup authentication mechanism using jetty approach. This is what I tried:
1.modified “/opt/solr/server/etc/jetty.xml
<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>
created credentials file in /opt/solr/server/etc/realm.properties
admin: admin123,core
modified /opt/solr/server/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>core</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>Test Realm</realm-name> </login-config>
After this If I restart solr service, solr is not getting started. In the logs I am getting error as:
Suppressed: java.lang.NoSuchFieldException: refreshInterval
Suppressed: java.lang.NoSuchFieldException: TYPE
Suppressed: java.lang.NoSuchMethodException: org.eclipse.jetty.security.HashLoginService.setRefreshInterval(java.lang.String)
回答1:
Create Security file:sudo vim /var/solr/data/security.json
{
"authentication":{
"blockUnknown": true,
"class":"solr.BasicAuthPlugin",
"credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}
},
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[{"name":"security-edit",
"role":"admin"}],
"user-role":{"solr":"admin"}
}}
This will create user called "solr" with password SolrRocks
Then Restart solr service:sudo service solr restart
Verification:http://<ip_address>:8983/solr/admin/authentication
来源:https://stackoverflow.com/questions/55369465/how-to-setup-authentication-mechanism-in-solr-7