2013-02-23 164 views
1

在couchdb中,如果數據庫受到保護,它將根據「authentication_redirect」配置設置重定向到「/_utils/session.html」。Couchdb身份驗證/授權

如果我有幾個數據庫,如DB1,DB2,等我要的是CouchDB的重定向到/db1/logon.html爲DB1 & /db2/logon.html對於DB2,等等。

是它可能使couchdb根據正在訪問的數據庫重定向到特定的登錄文件?

回答

1

我能想到做到這一點的唯一方法是使用像重寫:

{from: '/db1/*', to: '../../../db1/*'}, 
{from: '/db2/*', to: '../../../db2/*'} 

在你的主數據庫調用它主要從本地主機被服務:5984。

配置需要的是在蒲團

httpd secure_rewrites false 
vhosts localhost:5984 /main/_design/edit/_rewrite 

如下與此唯一的問題是,你將不得不把secure_rewrites關閉這可能會弄亂你的安全。

這是未經測試的,但應該是關閉。

7

您可以傳遞一個?fail =參數。告訴couchdb在哪裏發送驗證失敗的用戶。蒲團使用它是這樣的;

成功認證;

curl -sv 'localhost:5984/_session?next=/foo&fail=/bar' -d 'name=foo&password=bar' 

< HTTP/1.1 302 Moved Temporarily 
< Location: http://localhost:5984/foo 
{"ok":true,"name":null,"roles":["_admin"]} 

失敗的驗證;

curl -Haccept:text/html -sv 'localhost:5984/_session?next=/foo&fail=/bar' -d 'name=foo&password=baz' 
< HTTP/1.1 302 Moved Temporarily 
< Location: http://localhost:5984/bar 
{"error":"unauthorized","reason":"Name or password is incorrect."}