2016-08-02 53 views

回答

2

首先去你webdefault.xml目前在etc目录。在你的web.xml中放入下面的行。

<login-config> 
     <auth-method>BASIC</auth-method> 
     <realm-name>samplerealm</realm-name> 
    </login-config> 

<security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Secure resources</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>user</role-name> 
     </auth-constraint> 
    </security-constraint> 

etc文件夹中创建一个samplerealm.txt文件,并添加follwing内容到该文件user1: user1pass,user。这里user1是你的用户名,user1pass是你刚才在web.xml中定义的角色user的密码。之后去到jetty.xml文件在您etc文件夹,查找下面略低于该行线<Configure id="Server" class="org.eclipse.jetty.server.Server">粘贴以下代码:

<Call name="addBean"> 
    <Arg> 
     <New class="org.eclipse.jetty.security.HashLoginService"> 
     <Set name="name">samplerealm</Set> 
     <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/samplerealm.txt</Set> 
     <Set name="refreshInterval">0</Set> 
     </New> 
    </Arg> 
    </Call> 

之后,停止并重新启动Solr的服务器。当您现在访问solr页面时,它会要求您提供凭据。如您的示例realm.txt文件中所声明的,将user1作为您的用户名并将user1pass作为密码。稍后,您可以根据需要更改密码。这就是你如何在Solr中进行http基本认证。它工作100%。让我知道如果这有助于:)

+0

谢谢,它按需工作 –

+0

耶! :) 乐于帮助 。 –

+0

我不明白我是否必须更新web.xml或webdefault.xml。在webdefault.xml中已经有它需要删除它吗? – Alessandra