Search code examples
apachehadooppolicyapache-ranger

How to add users to Apache Ranger via REST API


As in the title, how to manually add a user to Apache Ranger via REST API.

Could you post an example of curl call?

Could you post in addiction an url where i can find the docs for:

   http:<ip>:6080/service/xusers/???

Solution

    • Global note for all queries: Sometimes you have to remove /secure

    Get a User

    curl -u admin:admin -v -i -s -X GET http://xxx:6080/service/xusers/secure/users/$ID_USER
    

    Replace $ID_USER by your userId

    • Note: Sometimes you have to remove /secure

    Get all User

    curl -u admin:admin -v -i -s -X GET http://xxx:6080/service/xusers/secure/users
    

    Delete a User

    curl -u admin:admin -v -i -s -X DELETE http://xxx:6080/service/xusers/secure/users/$ID_USER
    

    Replace $ID_USER by your userId

    Add/POST a User

    curl -u admin:admin -v -i -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://xxx:6080/service/xusers/secure/users -d @userfile.json
    
    • Note: Sometimes you have to remove /secure

    • Note 2: userfile.json should be like this:

    { "name":"user1", "firstName":"user1", "lastName": "user1", "loginId": "user1", "emailAddress" : null, "description" : "user1 desc", "password" : "user1pass", "groupIdList":[2,12], "status":1, "isVisible":1, "userRoleList": [ "ROLE_SYS_ADMIN" ], "userSource": 0 }

    • userRoleList can be "ROLE_SYS_ADMIN" Or "ROLE_USER"
    • If you remove password, the user will be an external user.