Hyperledger有会员服务,它将一些初始成员保存在membersrvs.yaml文件中,例如lukas,jim等。
然后,用户必须通过向restapi / registrar发布enrollmentid和secret来登录网络。
我的问题是如何为未在CA中定义的用户创建网络的新用户?似乎管理员用户可以这样做,但如何使用管理员安全上下文调用/ registrar api?
谢谢
答案 0 :(得分:5)
更新我对Fabric 1.0 alpha版本的回答。
Fabric 1.0使用Fabric-ca进行权限检查。
Fabric CA由服务器和客户端组件组成 在配置TLS-cert之后,可以将fabric-ca server和fabric-ca客户端部署到不同的服务器。
还有3种方式:
1.启动fabric-ca服务器时,在配置文件中添加新用户
2.通过fabric-ca客户端注册新用户。必须当前注册执行注册请求的用户,以及此
注册商必须具有注册所注册用户类型的适当权限。注册商必须已注册属性“hf.Registrar.DelegateRoles”。
DelegateRoles属性指定此注册商允许注册的类型
3.使用java sdk或nodejs sdk。 sdk现在适用于面料。
这是java sdk的示例用法:
import org.hyperledger.fabric.sdk.User;
public class SampleUser implements User, Serializable {
// Sample User implementation go here
...
}
private static final String FABRIC_CA_SERVICES_LOCATION = "http://localhost:7054";
HFCAClient ca_client;
try{
ca_client = new HFCAClient(FABRIC_CA_SERVICES_LOCATION, null);
SampleUser admin = new SampleUser("name","orgName","role");
if (!admin.isEnrolled()) {
// Admin is the bootstrap user defined at fabric-ca server configure file, so we just enroll admin here.
admin.setEnrollment(ca_client.enroll(admin.getName(), "adminPassword"));
admin.setMPSID(org.getMSPID());
System.out.println("Admin enroll success");
}
SampleUser user = new SampleUser("name","orgName","role");
System.out.println("register user ...");
if (!user.isRegistered()) {
// here RegistrationRequest accepts two params, the first is userName, the second is the department of the user
RegistrationRequest rr = new RegistrationRequest(user.getName(), "org.department");
String password = ca_client.register(rr, admin);
System.out.println("register success, and get password from ca server: " + password);
// db.store(user,password)
}
catch (Exception e){
}
}
答案 1 :(得分:4)
REST api / registrar只能用于登录网络。如果您想将新用户添加到会员服务,您有两个选择: