2017-08-03 27 views
0

我試圖在CentOS 7上的Tomcat 8.5上設置消化認證。我看過/關注了包括 - How to use digest authentication in Tomcat 8.5?在內的各種文章 - 但是在遵循所有必需的步驟之後,它不起作用。我已經爲經理和主機管理員應用程序設置了這一點,但密碼從不例外,localhost_access日誌報告401錯誤。訪問這些應用程序正在使用基本身份驗證。Tomcat 8.5消化認證

我的server.xml被配置爲這樣:通過

 <!-- Define the Login Configuration for this Application --> 
    <login-config> 
    <auth-method>DIGEST</auth-method> 
    <realm-name>UserDatabase</realm-name> 
    </login-config> 

的密碼被創建:

/opt/tomcat/bin/digest.sh -s 0 -a sha-256 -h org.apache.catalina.realm.MessageDigestCredentialHandler "username":UserDatabase:"password" 

<!-- Use the LockOutRealm to prevent attempts to guess user  passwords 
      via a brute-force attack --> 
     <Realm className="org.apache.catalina.realm.LockOutRealm"> 
     <!-- This Realm uses the UserDatabase configured in the global JNDI 
      resources under the key "UserDatabase". Any edits 
      that are performed against this UserDatabase are immediately 
      available for use by the Realm. --> 
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"> 
      <CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="SHA-256" /> 
     </Realm> 
    </Realm> 

web.xml中爲每個應用已被編輯爲這樣

tomcat-user.xml中的密碼已被此替換。

我也檢查了server.xml中的「名字」,在下面的章節相匹配,作爲在server.xml中和web.xml的lockoutrealm部分定義

 <Resource 
auth="Container" 
description="User database that can be updated and saved" 
factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
name="UserDatabase" #<--------------NOTE 
pathname="conf/tomcat-users.xml" 
type="org.apache.catalina.UserDatabase"/> 

我也重新啓動tomcat服務後這些變化,我evn重新啓動服務器 - 抓住吸管.....

當我嘗試通過瀏覽器登錄時,我不斷收到重新提示如下,如果我取消我得到標準的401錯誤屏幕

Browser login box

我知道我一定錯過了一些東西,但我已經在這一段時間了,只是看不到它是什麼。

回答

0

我有同樣的問題,運行在MacOS高塞拉利昂。 (我最終將部署到CentOS 7.)短版本,使用MD5而不是SHA。我可以使用MD5進行消化工作,如在https://tomcat.apache.org/tomcat-8.5-doc/realm-howto.html#Digested_Passwords中模糊地描述如下:

1)首先,在您的web.xml文件中定義的<領域名稱>是任意的;它是從server.xml文件中定義的獨立構造。但是,你需要知道它。

2)顯然,在<領域設置 「算法MD5 =」 在<CredentialHandler>元素屬性在server.xml中>

3)MD5運行digest.sh時,必須指定「 - 一個md5 -s 0 -i 1「。

4)通過摘要命令獲取散列的「密碼」必須是userid:realm-name:password的串聯。這使用您的web.xml中的<領域名稱>值。

我已經嘗試了上述步驟與SHA-256,沒有運氣。我最好的猜測是命令行中使用的「提供程序默認值」與內部使用的不同,並且沒有記錄。 MD5散列就是這種情況,Tomcat文檔使用「-s 0」標誌明確指出狀態,這不是默認狀態。

+0

非常感謝,它完美的作品!適用於服務器運行的Web應用程序。 – OPW