Unable to enroll user in new org added to balance transfer sample

廉价感情. 提交于 2019-11-30 10:51:13

The issue is that the fabric-ca being used in the sample does not know about the affiliation. By default, fabric-ca only has the following affiliations:

org1.department1 org1.department2 org2.department1

The code which registers and enrolls users in the sample takes the org name and concatenates it with "department1" :

let secret = await caClient.register({
                enrollmentID: username,
                affiliation: userOrg.toLowerCase() + '.department1'
            }, adminUserObj);

So when you pass in Org3, it tries to register the user with the affiliation org3.department1 which does not exist.

Since you are using 1.1.0-alpha, you are in luck as this version of fabric-ca supports has an API for adding new affiliations. The easiest way is to use the fabric-ca-client to do this:

fabric-ca-client affiliation add org3
fabric-ca-client affiliation add org3.department1

You can look at the fabric-ca docs ( http://hyperledger-fabric-ca.readthedocs.io/ ) for more details. You'll need to first enroll the admin user which has the password "adminpw" with the fabric-ca-client and then run the above commands.

This may be useless (and very late), but I'd like to add to Gari's answer. You can also add affiliations using the node client SDK's AffiliationService class.
To do this in the balance transfer code, modify helper.js with:

let adminUserObj = await client.setUserContext({
                        username: admins[0].username, 
                        password: admins[0].secret});

let caClient = client.getCertificateAuthority();
let affiliationService = caClient.newAffiliationService();

let registeredAffiliations = await affiliationService.getAll(adminUserObj);
if(!registeredAffiliations.result.affiliations.some(
    x => x.name == userOrg.toLowerCase())){
        let affiliation = 'org3.department1'; 
        await affiliationService.create({
                        name: affiliation, 
                        force: true}, adminUserObj);
}

Note:
The above code only adds the affiliations (which I think is the only thing missing in your case). To successfully enroll a user for Org3, you'll also have specify org3 in artifacts/channel/cryptogen.yaml, artifacts/channel/configtx.yaml, artifacts/docker-compose.yaml, artifacts/network-config.yaml and config.json. And create an org3.yaml file.

I built a chaincode sample app with the balance transfer sample as a base which has 3 orgs. You can take a look at it to see the necessary changes.

Please pay attention to this line in helper.js,

let secret = await caClient.register({ enrollmentID: username, affiliation: userOrg.toLowerCase() + '.department1' }, adminUserObj);

Are you sure you are lowercasing for Org3 (in config yaml files) ?

nagesh bandaru

I had seen the same problem in fabric 1.3, I have changed the names and configured my own. by removing below statement helped me

just comment the below line in 'helper.js' helped me.

//affiliation: userOrg.toLowerCase() + '.department1'

You can add more organizations and there departments by changing the fabric-ca-server-config by going to the fabric-ca docker container.

docker exec -it ca.org1.example.com bash 

Go the root@c3804e2852fd:/etc/hyperledger/fabric-ca-server# directory inside the container

Now edit fabric-ca-server-config.yaml file. Add organizations and their departments as per your choice.

Below i have added one "Manufacturer" organization. You can add Org3 like this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!