2016-08-02 40 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