Fork me on GitHub Fork me on GitHub

user.User


<%
var carbon = require('carbon');
var tenantId = -1234;
var url = 'https://10.100.0.49:9443/admin/services/';
var server = new carbon.server.Server(url);
var userManager = new carbon.user.UserManager(server, tenantId); 
var user = new carbon.user.User(userManager, 'admin');

print("Get claims of admin : ");
print(user.getClaims('default'));
print("<br>");

print("Get Roles of Admin : ");
print(user.getRoles());
print("<br>");

var roles = ['admin'];

print("Check user has roles : ");
print(user.hasRoles(roles));
print("<br>");
%>

Overview

User object allows to do operations on specific user in Carbon user store using Jaggery.


Operations

Operation Returns Description
User(manager Object, username String)ObjectFollowing parameters should be passed to the constructor:

  • manager (Object): a Usermanager instance to be used.
  • username (String): username of the required user.
var carbon = require('carbon');
var tenantId = -1234;
var url = 'https://10.100.0.49:9443/admin/services/';
var server = new carbon.server.Server(url);
var userManager = new carbon.user.UserManager(server, tenantId);
var user = new carbon.user.User(userManager, 'admin');
getClaims(profile String)ObjectThis method returns all claims of this user object. It accepts the following parameters:

  • profile (String) :
This returns a JSON object with all claims this user has and their values.
getClaimsForSet(claims Array, profile String)ObjectThis method returns sppecified set of claims of this user object. It accepts the following parameters:

  • claims (Array) : Array of claim URIs of required claim URIs.
  • profile (String) :
This returns a JSON object with requested claims of this user has and their values.
setClaims(claims Object, profile String)NoneThis method is used to set few user claims of athis user at single time.It accepts the following parameters:

  • claims (Object) : A JSON object which contains the claims to be set and values for them..
  • profile (String) :
getRoles()ArrayThis method returns an array with all roles of this user.
hasRoles(roles Array)BooleanThis method checks if the user has set of rules or not. It accepts the following parameters:

  • roles (Array) : list of roles to be checked.
This will return 'true' if this user has all the specified roles and will return 'false' otherwise.
addRoles(roles Array)NoneThis method adds this user to specified new set of roles. It accepts the following parameters:

  • roles (Array) : list of roles which user to be added.
removeRoles(roles Array)NoneThis method removes this user from specified set of roles. It accepts the following parameters:

  • roles (Array) : list of roles which user to be removed from.
updateRoles(remove Array, add Array)NoneThis method update the list of roles of this user. It accepts the following parameters:

  • remove (Array) : list of roles to be removed.
  • add (Array) : list of new roles to be added.
isAuthorized(permission String, action String)BooleanThis method checks if this user is authorized for given action.. It accepts the following parameters:

  • permission (String) : permission path in permission tree.
  • action (String) : The action.
This methods returns 'true' if this user is authorized to do 'action' on 'permission'.