查詢字元串上基本身份驗證的 IIS 重寫規則
我正在嘗試通過基本身份驗證自動將使用者登錄到 Xwiki 安裝。這是因為幫助儲存在 wiki 中,但我們希望檢索過程對使用者透明。
我們將使用者推送到一個 url(通過
<a>標籤),例如:http://username:password@xwiki.example.org/xwiki/bin/view/Main?basicauth=1這在除 Internet Explorer 之外的所有瀏覽器中都可以正常工作(請參閱:
http://support.microsoft.com/kb/834489。不幸的是,我們 80% 的使用者群使用 Internet Explorer,並且不能讓他們手動輸入憑據。目前,我們在 Xwiki 前面安裝了 IIS 7.5,並將所有請求代理到另一台伺服器上的 Tomcat 實例。這工作正常。為了解決我的問題,我想我可以使用 IIS 重寫規則來轉換這樣的 url:
http://xwiki.example.org/xwiki/bin/view/Main?basicauth=1&_username=username&_password=password進入這個:
http://username:password@xwiki.example.org/xwiki/bin/view/Main?basicauth=1&_username=username&_password=password這個想法是 IIS 會將 _username/_password 查詢字元串參數替換為 URL 並將其傳遞給 Tomcat,而 Xwiki 將忽略額外的參數。
我創建了一個 URL 重寫規則,例如:
<rule name="BasicAuthRewrite" enabled="true"> <match url="https?://(.+)&?_username=(.+)&_password=(.+)" /> <action type="Rewrite" url="http://{R:2}:{R:3}@xwiki.example.org/{R:1}" /> </rule>當我在 IIS 中進行“測試模式”並提供我的 url 時,所有反向引用 ({R:x}) 都與我想要的數據相匹配。但是,當我在瀏覽器中訪問 URL 時,重寫規則無法呼叫。
有什麼方法可以實現我想要的行為?
可以在 IIS 上使用 URL 重寫進行基本身份驗證。您應該添加伺服器變數 HTTP_Authorization 值 Basic 後跟使用者名:base64 中的密碼。記得在允許的變數中添加變數
因此,對於密碼為 open sesame 的使用者 Aladdin,您的格式將是 Aladdin:open sesame 和 base64 編碼的 QWxhZGRpbjpvcGVuIHNlc2FtZQ==。
轉化為授權:基本 QWxhZGRpbjpvcGVuIHNlc2FtZQ==
<rule name="SomeName" stopProcessing="true"> <match url="url/to/match" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> <action type="Rewrite" url="http://www.redirecturl.com/" appendQueryString="true" /> <serverVariables> <set name="HTTP_Authorization" value="Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" /> </serverVariables> </rule>
