Skip to content

Boss User Management Tutorial

Tim Gion edited this page Jan 20, 2017 · 7 revisions

Boss User Management Tutorial

Introduction

intern allows programmatic user management. Only users with either the admin role or the user-manager role may access the user management functions of the Boss API.

  • add_user()
  • get_user()
  • delete_user()
  • add_user_role()
  • get_user_roles()
  • delete_user_role()

To list the groups a user belongs to requires either the admin role or the resource-manager role.

  • get_user_groups()

Example

First, let's create a new user. We'll also retrieve the user's data after creation to demonstrate how and to show what the returned data looks like.

from intern.remote.boss import BossRemote
from intern.resource.boss.resource import *

rmt = BossRemote()

user = 'jdoe'
rmt.add_user(user, 'John', 'Doe', 'jd@home.com', 'secure_password')

user_data = rmt.get_user(user)
print(user_data)

Notice that the Boss does not return the user's password, as you would expect.

Important: in your browser, open https://api.theboss.io/v0.7/collection/ and login as jdoe using the password set in rmt.add_user() above. The user must login, at least once, before roles or group operations may be performed.

Next, let's demonstrate how to add a role to a user. See the Boss documentation for more about user roles. We'll make John a resource-manager. The resource-manager role lets a user manage the data model. This includes creation and deletion as well as assigning permissions to various objects in the data model.

rmt.add_user_role(user, 'resource-manager')

print(rmt.get_user_roles(user))

Notice that we also retrieved the roles assigned to John using rmt.get_user_roles().

Now let's pretend that we didn't want to make John a resource-manager, so let's remove that role.

rmt.delete_user_role(user, 'resource-manager')

print(rmt.get_user_roles(user))

Access to resources is based on group membership. Access control is covered in detail in the [Boss Project Auth](https://github.com/jhuapl-boss/intern/wiki/Boss Project Auth Tutorial) tutorial.

Finally, let's remove John from the Boss.

rmt.delete_user(user)