在Tomcat7上保护Solr

时间:2013-11-20 14:36:53

标签: solr tomcat7

我尝试保护我的Solr实例,但我无法让它工作。我在许多教程中看到它的方式做了一切,但似乎solr忽略了我的web.xml。

我的步骤:

1:编辑tomcat-users.xml

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
    <role rolename="manager-gui"/>
    <user username="tomcat" password="s3cret" roles="manager-gui"/>

    <role rolename="solr-role"/>
    <user username="test" password="test" roles="solr-role"/>
</tomcat-users>

2:编辑web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Solr Lockdown</web-resource-name>
        <url-pattern>/</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>solr-role</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Solr</realm-name>
</login-config> 

3:重启tomcat7

之后我尝试访问http://xxx.xxx.xxx.xxx:8080/solr/,我无需任何密码提示即可访问。

我的错是什么?

非常感谢!

2 个答案:

答案 0 :(得分:1)

将以下行添加到web.xml可以保护solr的管理页面(至少对于solr 4.2.1,但这也适用于4.5.1)

<security-constraint>
  <!-- This protects your admin interface and grants access to role admin -->
  <web-resource-collection>
      <web-resource-name>Solr admin</web-resource-name>
      <url-pattern>/admin/*</url-pattern>
      <url-pattern>/admin.html</url-pattern>
  </web-resource-collection>
  <auth-constraint>
      <role-name>solr</role-name>
  </auth-constraint>
  <security-role>
      <role-name>solr</role-name>
  </security-role>
</security-constraint>
<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>SOLR Realm</realm-name>
</login-config>

答案 1 :(得分:0)

我不知道为什么,但我使用了错误的web.xml。 我使用/var/lib/tomcat7/webapps/solr/WEB_INF/web.xml下存储的文件,但我必须使用/etc/tomcat7/web.xml下的文件。