我已经创建了_users数据库以及_security文档,并根据https://cloudant.com/for-developers/faq/auth/适当地设置了安全性。
然后,我用角色"_reader“创建了一个用户”测试“,但是当我尝试登录到Cloudant时,它不识别用户。
_users数据库包含一个文档:
{
"_id": "test",
"_rev": "1-96973497bc9c89989c4beed02e3f0b96",
"name": "test",
"roles": [
"_reader"
],
"type": "user",
"password": "password"
}然后,我试图使用上面创建的用户名"test“和密码" password”查看一个设计文档,但是它没有工作。
在设计文档所在的数据库的安全文档中,我有:
{ "couchdb_auth_only": true, "members": { "names": [ "test" ], "roles": [ "_reader" ] } }有什么建议吗?
谢谢!
发布于 2015-10-16 04:42:09
我还没有用Cloudant对此进行测试,而且还没有通过加密专家验证该方法的安全性(请这样做),但希望它能为您指明正确的方向:
首先,需要生成一个salt和一个password_sha:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
public class CouchPassword {
public static void main(String[] args) throws NoSuchAlgorithmException {
String password = "123456"; // your password
String salt = genSalt();
password = password + salt;
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(password.getBytes());
byte byteData[] = md.digest();
System.out.println("Password SHA: " + byteToHexString(byteData) );
System.out.println("Generated Salt: " + salt);
}
public static String genSalt() {
Random ranGen = new SecureRandom();
byte[] salt = new byte[16];
ranGen.nextBytes(salt);
return byteToHexString(salt);
}
public static String byteToHexString(byte[] b) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
sb.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
}
// There are libraries to help with generating SHAs and Hex Strings
// but I have choosen not to use those here so the answer is more standalone.将上述密码字符串设置为所需的值,然后执行。例如。
Password SHA: 316ccb0df3c8bbd8f568347827803682d2c93849
Generated Salt: bba45713ef54016c8ef4b56b6b147936创建_user和_security文档(选项1):
// _user
{
"_id" : "org.couchdb.user:joe",
"type" : "user",
"name" : "joe",
"roles" : ["standarduser"],
"password_sha" : "316ccb0df3c8bbd8f568347827803682d2c93849",
"salt" : "bba45713ef54016c8ef4b56b6b147936"
}从_users文档映射到_security文档中定义的角色的角色。
// _security
{
"couchdb_auth_only": true,
"members": {
"names": [],
"roles": ["standarduser"]
},
"admins": {}
}来自CouchDB文档
在我的示例中,我的用户joe被赋予角色standarduser,它映射到数据库的数据库成员。
创建_user和_security文档(选项2):
请注意,我本可以指定roles,而不是使用member.names
// _user document
{
"_id" : "org.couchdb.user:joe",
"type" : "user",
"name" : "joe",
"password_sha" : "316ccb0df3c8bbd8f568347827803682d2c93849",
"salt" : "bba45713ef54016c8ef4b56b6b147936"
}
// _security document
{
"couchdb_auth_only": true,
"members": {
"names": ["joe"],
"roles": []
},
"admins": {}
}警告
确保member.names和member.roles参数都不是空的,因为这将授予每个人读和写访问权:
{
"couchdb_auth_only": true,
"members": {
"names": [],
"roles": []
},
"admins": {}
}没有成员,任何用户都可以编写常规文档(任何非设计文档)并从数据库读取文档。 来源:http://wiki.apache.org/couchdb/Security_Features_Overview
发布于 2015-10-20 14:22:34
朱莉-在Apache CouchDB中,您目前必须使用验证函数来启用只读访问.(没有一个“转键”用户角色会给你我认为你想要的东西。)
特别是,我发现这个线程很有用:https://stackoverflow.com/a/10713843/1459475
它链接到正式的CouchDB书籍中关于验证函数:http://guide.couchdb.org/draft/validation.html以及JavaScript示例和解释:update.js couchdb#an-易于验证-功能的部分。
在Cloudant中,使用API键进行只读访问要简单一些,但是仍然可以使用开箱即用的CouchDB实现只读访问。只是不像你想的那样。祝好运!
https://stackoverflow.com/questions/33152085
复制相似问题