Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 09-02-2016 09:49 PM
Right now, Ranger provides two roles - "Admin" and "User". When I added a new user in OS, Ranger usersync created its login credentials for Ranger UI but the role appointed is User. I am trying the following REST API to change the role to Admin so that it can create new policies:
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -u admin:admin http://sandbox.hortonworks.com:6080/service/xusers/users -d '{"name":"tom","role":["ROLE_SYS_ADMIN"]}'
There is no output or any error. Please help
Created 09-02-2016 11:22 PM
There is a great article already on this site describing how to do this.
Here is how I was able to do this:
First capture the current users information:
curl -s -u admin:admin -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://127.0.0.1:6080/service/xusers/users/8 > /tmp/curl.out
File contents:
{"id":8,"createDate":"2016-03-14T14:41:05Z","updateDate":"2016-09-02T23:07:10Z","owner":"rangerusersync","updatedBy":"Admin","name":"HDP","firstName":"HDP","lastName":"HDP","emailAddress":"[email protected]", "password":"*****","description":"HDP - add from Unix box","groupIdList":[6],"groupNameList":["root"],"status":0,"isVisible":1,"userSource":0,"userRoleList":["ROLE_USER"]}
Modified to include mandatory fields and values to update:
{"id":8,"name":"HDP","firstName":"HDP","lastName":"HDP","emailAddress":"[email protected]","description":"HDP - add from Unix box","userRoleList":["ROLE_SYS_ADM"]}
Update the users information and read it back:
curl -u admin:admin -v -i -s -X PUT -H "Accept: application/json" -H "Content-Type: application/json" http://127.0.0.1:6080/service/xusers/secure/users/8 -d @/tmp/curl.out curl -s -u admin:admin -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://127.0.0.1:6080/service/xusers/users/8
{"id":8,"createDate":"2016-03-14T14:41:05Z","updateDate":"2016-09-02T23:08:49Z","owner":"rangerusersync","updatedBy":"Admin","name":"HDP","firstName":"HDP","lastName":"HDP","emailAddress":"[email protected]","password":"*****","description":"HDP - add from Unix box","groupIdList":[6],"groupNameList":["root"],"status":0,"isVisible":1,"userSource":0,"userRoleList":["ROLE_SYS_ADM"]}
Created 09-02-2016 10:21 PM
Please use /service/users end point and for update use PUT.
curl -u admin:admin -X PUT -H "Accept: application/json" -H "Content-Type: application/json" http://`hostname -f`:6080/service/users -d @test.json
where test.json is your json pay-load.
Created 09-02-2016 10:32 PM
Thanks @Ramesh Mani, Just tried this, still nothing happened. I guess there is a problem with json payload. I am using '{"name":"tom","userRoleList":"ROLE_SYS_ADMIN"}'
Created 09-02-2016 11:22 PM
There is a great article already on this site describing how to do this.
Here is how I was able to do this:
First capture the current users information:
curl -s -u admin:admin -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://127.0.0.1:6080/service/xusers/users/8 > /tmp/curl.out
File contents:
{"id":8,"createDate":"2016-03-14T14:41:05Z","updateDate":"2016-09-02T23:07:10Z","owner":"rangerusersync","updatedBy":"Admin","name":"HDP","firstName":"HDP","lastName":"HDP","emailAddress":"[email protected]", "password":"*****","description":"HDP - add from Unix box","groupIdList":[6],"groupNameList":["root"],"status":0,"isVisible":1,"userSource":0,"userRoleList":["ROLE_USER"]}
Modified to include mandatory fields and values to update:
{"id":8,"name":"HDP","firstName":"HDP","lastName":"HDP","emailAddress":"[email protected]","description":"HDP - add from Unix box","userRoleList":["ROLE_SYS_ADM"]}
Update the users information and read it back:
curl -u admin:admin -v -i -s -X PUT -H "Accept: application/json" -H "Content-Type: application/json" http://127.0.0.1:6080/service/xusers/secure/users/8 -d @/tmp/curl.out curl -s -u admin:admin -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://127.0.0.1:6080/service/xusers/users/8
{"id":8,"createDate":"2016-03-14T14:41:05Z","updateDate":"2016-09-02T23:08:49Z","owner":"rangerusersync","updatedBy":"Admin","name":"HDP","firstName":"HDP","lastName":"HDP","emailAddress":"[email protected]","password":"*****","description":"HDP - add from Unix box","groupIdList":[6],"groupNameList":["root"],"status":0,"isVisible":1,"userSource":0,"userRoleList":["ROLE_SYS_ADM"]}
Created 09-03-2016 12:14 AM
It worked, thanks a lot @jhorsch. I was missing some mandatory fields in json payload, that should be the reason for the error.