User


Contents

Overview

A User object represents someone who can log into the system. When a Person needs to access the system they are given a username and password – a row in the users table. User has a column with a foreign key to the associated person id. This means that one Person can have multiple User accounts for multiple logins.

Users are given permissions through Roles. Each Role has a set of Privileges assigned to it. Those atomic privileges are used in the code to restrict access to different parts of the API.

To check whether the current user has permissions, use Context.hasPrivilege().

Users

A User object represents a Person who can log into the system.

Properties on a User:

  • userId: the database's integer used to identify the object.
  • person: the Person associated with the user.
  • systemId: a unique identifier assigned to each user.
  • username: the username for the user.
  • email: the email address for the user.
  • roles: a list of roles attributed to the user.
  • userProperties: the properties of the user.


UserService
// Creates user with given password.
public User createUser(User user, String password);

// Gets user by given userId.
public User getUser(Integer userId);

// Gets user by given uuid.
public User getUserByUuid(String uuid);

// Gets user by given username.
public User getUserByUsername(String username);

// Verifies that the username and system id are unique.
public boolean hasDuplicateUsername(User user);

// Updates a given user in the database.
public User saveUser(User user);

// Deactivates a user account so that it can no longer log in.
public User retireUser(User user, String reason);

// Save the given privilege in the database.
public Privilege savePrivilege(Privilege privilege);

// Gets role for given role name.
public Role getRole(String r);

// Gets privilege for given name.
public Privilege getPrivilege(String p);

// Gets list of users by first and last name.
public List<User> getUsersByName(String givenName, String familyName, boolean includeRetired);

Example:

User user = Context.getUserService().getUser(Integer.valueOf(userId));
user.setUsername("Johnny");
Context.getUserService().saveUser(user);

The User class source code can be seen here.

The UserService class source code can be seen here.

A module demonstrating how to use this class can be seen here.

Role

Roles are hierarchical. A role inherits privileges from its parent. A user can have multiple roles, and a role can have multiple privileges.

Properties on a Role:

  • role: the role assigned to the user.
  • privileges: the privileges for this role.
  • inheritedRoles: the roles that extend or inherit this role.
  • childRoles: roles that are children of this role.

The Role class source code can be seen here.

Privilege

Privilege is a property of a Role.

Properties on a Privilege:

  • privilege: the name of the privilege.

The Privilege class source code can be seen here.

User Property

A set of key value pairs. Used to store user specific data. Something like:

User user2 = Context.getUserService().getUser(Integer.valueOf(userId));
user2.getUserProperty(String) //get the value defined by the given string/key, returns a String
user2.getUserProperties() //get all properties for that user in key-value pairs, returns a Map<String, String>
user2.setUserProperty(String, String) //overwrites given user property key with the given value, and adds it to the user's properties

Visualization

Here is a class diagram for User and related classes.

Future updates to this visualization can be made on draw.io here, or using the XML file here.