In this blog, I discuss what is ‘user-role’ in SUSI.AI, what are the various roles and how SUSI admins can modify/update a user’s roles.
What is User Role?
A UserRole defines the servlet access right. Not all users are allowed to access all the data and services. For example, To list all the users, minimal user role expected is ADMIN. This classification of users are inspired by the wikipedia User Access Levels, see https://en.wikipedia.org/wiki/Wikipedia:User_access_levels.While querying SUSI, Users are classified into 7 different categories, namely :
- BOT
- ANONYMOUS
- USER
- REVIEWER
- ACCOUNTCREATOR
- ADMIN
- BUREAUCRAT
* Please see that these are as of the date of publish of this blog. These are subject to change, which is very unlikely.
If SUSI is active as a bot on some bot integrated platform (like line or kik), the user role assigned to it will be that of BOT. This user role just has technical access to the server.
All the users who are not logged in but interacting with SUSI are ANONYMOUS users. These are only subject to chat, login and signup. They may use forgot password service and reset password services as well.
Once a user login to the server, a token is generated and sent back to client to maintain the identity, hence acknowledging them as USER(s).
Users with role assigned as “REVIEWERS” are expected to manage the Skill CMS. There might be some dispute or conflict in a skill. REVIEWERS then take the access of skill data and finalise the conflict there itself for smooth functionality.
ADMIN users are those who have special rights with them. These are more like moderators with much special rights than any other user.
At the top level of the hierarchy are the BUREAUCRATS. These users have more rights than anyone. They can change role of any other user, override decision of any ADMIN user as well. Both admins and bureaucrats have the access to all the settings file on the server. They not only can look at the list, but also download and upload them. Now these users also have right to upgrade or downgrade any other user as well.
All these user roles are defined in UserRole.java file.
In each request received by the server, the user role of user making the request is compared with the minimal user role in getMinimalUserRole() method. This method is defined in AbstractAPIHandler which validates if a user is allowed to access a particular servlet or not.
private void process(HttpServletRequest request, HttpServletResponse response, Query query) throws ServletException, IOException {
// object initialisation and comparsions
// user authorization: we use the identification of the user to get the assigned authorization
Authorization authorization = DAO.getAuthorization(identity);
if (authorization.getUserRole().ordinal() < minimalUserRole.ordinal()) {
response.sendError(401, "Base user role not sufficient. Your base user role is '" + authorization.getUserRole().name() + "', your user role is '" + authorization.getUserRole().getName() + "'");
return;
}
// evaluations based on other request parameters.
}
Now that we know about what User Roles actually are, let us look at how the servlet which allows the users {with at least ADMIN login} to change user role of some other user works.
In the request, 2 parameters are expected. These are :
- user : email id of the user whose role has to be changed.
- role : new role which will be assigned to this user.
Using a switch case, we identify the user role which is requested. If role is found to be null or any other value apart from “bot”, “anonymous”, “user”, “reviewer”, “accountcreator”, “admin” or “bureaucrat”, an error with error code 400 and error message “Bad User role” is thrown.
In the next steps, server generates client identity in order to get the corresponding Authorization object. If the user is not found in the database, again an error is thrown with error code 400 and error message “role not found
ClientCredential credential = new ClientCredential(ClientCredential.Type.passwd_login, userTobeUpgraded);
ClientIdentity identity = new ClientIdentity(ClientIdentity.Type.email, credential.getName());
if (!DAO.hasAuthorization(identity)) {
throw new APIException(400, "Username not found");
}
By now, server is clear with the user identity and new role to be assigned. Since the user role is defined in authorization.json file, we overwrite the existing user role and finally server sends back the new user role of the use
Authorization auth = DAO.getAuthorization(identity);
try {
auth.setUserRole(userRole);
} catch (IllegalArgumentException e) {
throw new APIException(400, "role not found");
}
// Print Response
result.put("newDetails", auth.getJSON());
result.put("accepted", true);
result.put("message", "User role changed successfully!!");
return new ServiceResponse(result);
You must be logged in to post a comment.