WSO2 Identity Server - How to assign an existing role to a WSO2 IS user?

自闭症网瘾萝莉.ら 提交于 2019-12-01 11:49:02

I assume you have the SCIM Id for the role and it is 'c83dc72c-15c2-40f2-bddd-4acb086b9e17'. And user store is configured properly so the user and role is in the same user store.

If the above conditions are true, you can do the following to achieve the task.

  1. Create the user with curl command (here you are using SCIM)
  2. Update the group with the PUT method with the user's SCIM ID.

For example,

curl -v -k --user admin:admin -X PUT -d "{"displayName": 'Engineer' ,"members": [{"value":"334d988a-5e68-4594-8b96-356adeec29f1","display": "venura"}, {"value":"p09okhyt-5e68-4594-8mkj-356ade12we34","display": "testUser"}]}" --header "Content-Type:application/json" https://localhost:9443/wso2/scim/Groups/c83dc72c-15c2-40f2-bddd-4acb086b9e17

For more details please check the below link [1] in order to get a clear idea on how you can use PUT to update the role/ group.

[1] http://hasini-gunasinghe.blogspot.com/2012/11/wso2-identity-server-as-scim-service.html

Use PATCH operation:

Nodejs Sample code for SCIM2 (WSO2 Identity server 5.6):

//roleId is GUID generated after creating group. 
// token is the bearer token generated via client credential or password credential

function assignRoleToUser(token, user, roleId) {
var groupId = roleId;
var rp = require('request-promise');
var options = {
    uri: <identity_provider_hostname:port/scim2/Groups> + '/' + groupId,
    method: 'PATCH',
    json: true,
    headers: {
        'Content-Type': 'application/json',
        'Authorization': token
    },
    body:
    {
        schemas: ['urn:ietf:params:scim:api:messages:2.0:PatchOp'],
        Operations: [
            {
                op: 'add',
                value: {
                    members: [
                        {
                            display: user.userName,
                            value: user.id
                        }
                    ]

                }
            }]
    }
};
return rp(options);

}

Only drawback of this API is that, it returns array containing all members of that group after success. Not optimized if group has thousands or millions of users.

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