Hyperledger具有会员服务,该服务将一些初始成员保留在membersrvs.yaml文件中,例如lukas,jim等。
然后,用户必须登录到网络,方法是将restaumentid和密码发布到restapi / registrar。
我的问题是如何为CA中未定义的用户为网络创建新用户?似乎admin用户可以做到这一点,但是如何使用admin安全上下文调用/ registrar api?
谢谢
更新我对Fabric 1.0 alpha版本的回答。
Fabric 1.0使用Fabric-ca进行权限检查。
Fabric CA由服务器和客户端组件组成。
配置TLS证书后,fabric-ca服务器和fabric-ca客户端可以部署到不同的服务器。
还有3种方法:
1.启动Fabric-ca服务器时,在配置文件中添加一个新用户。
2.通过fabric-ca客户端注册新用户。执行注册请求的用户必须当前已注册,并且该注册商还必须具有适当的权限来注册正在注册的用户类型。该注册商必须已注册“ hf.Registrar.DelegateRoles”属性。DelegateRoles属性指定允许该注册服务商注册的类型。
3.使用Java SDK或Node.js SDK。sdk现在可以与结构很好地配合使用。
这是java sdk的示例用法:
import org.hyperledger.fabric.sdk.User;
public class SampleUser implements User, Serializable {
// Sample User implementation go here
...
}
Run Code Online (Sandbox Code Playgroud)
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){
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4350 次 |
| 最近记录: |