【问题标题】:How to setup authentication mechanism in solr 7?如何在 solr 7 中设置身份验证机制?
【发布时间】:2019-03-27 03:44:44
【问题描述】:

我已在生产服务器中安装了 solr 7.7 独立版。我正在尝试使用码头方法设置身份验证机制。这是我尝试过的:

1.修改“/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>
  1. 在 /opt/solr/server/etc/realm.properties 中创建凭据文件

    admin: admin123,core
    
  2. 修改/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>
    

在此之后如果我重新启动 solr 服务,则 solr 不会启动。在日志中,我收到以下错误:

 Suppressed: java.lang.NoSuchFieldException: refreshInterval
 Suppressed: java.lang.NoSuchFieldException: TYPE
 Suppressed: java.lang.NoSuchMethodException: org.eclipse.jetty.security.HashLoginService.setRefreshInterval(java.lang.String)

【问题讨论】:

  • 有什么理由你不是using the built-in authentication
  • 我在错误的地方创建了 security.json。这就是为什么它不起作用。现在我可以让它工作了。

标签: apache solr


【解决方案1】:

创建安全文件: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"}
}}

这将创建名为“solr”的用户,密码为 SolrRocks

然后重启solr服务:sudo service solr restart

验证:http://&lt;ip_address&gt;:8983/solr/admin/authentication

【讨论】:

  • 仍然适用于 solr 8.6.x 的出色解决方案。谢谢!
【解决方案2】:

refreshInterval 不起作用,因为在最新版本的 Jetty 中,该方法已被弃用,取而代之的是 setHotReload (boolean)。

https://archive.eclipse.org/jetty/9.3.11.v20160721/apidocs/org/eclipse/jetty/security/HashLoginService.html#setRefreshInterval-int-

Solr 7.7 使用 Jetty 9.4.14.v20181114

https://lucene.apache.org/solr/8_4_1/changes/Changes.html#v7.7.0.versions_of_major_components

如果你仍然想尝试这个而不是BasicAuthPlugin,你可以在 jett.xml 中使用以下内容 -

    <Call name="addBean">
      <Arg>
        <New class="org.eclipse.jetty.security.HashLoginService">
          <Set name="name">Login Required</Set>
          <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
          <Set name="HotReload">false</Set>
        </New>
      </Arg>
</Call>

顺便说一下,此过程存在一些问题,因为它使用HashLoginService 的“基本”身份验证,如here 所述。

【讨论】:

    猜你喜欢
    • 2015-06-27
    • 2017-05-06
    • 1970-01-01
    • 2015-07-20
    • 2019-06-28
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多