Assigning a Role to a User¶
Description¶
This operation assigns a new role to a user.
This functionality can be used only in CloudCode (Java, JS or Codeless), the reason for this restriction is that a malicious use of this API can easily compromise application's security. As a result, this API must be used from a controlled environment.
Method¶
Non-blocking Method 1: With the Callback
The method call does not block - it returns immediately. The AsyncCallback
argument receives either the response or the fault returned by the Backendless servers.
public void Backendless.UserService.assignRole( String identity,
String roleName,
AsyncCallback<Void> callback );
Blocking API
public void Backendless.UserService.assignRole( String identity, String roleName )
throws BackendlessException;
where:
Argument | Description |
---|---|
identity |
value for a user property marked as identity. String value. |
roleName |
the name of the role to assign to the user. String value. |
callback |
an object which receives either a return value or an error from the server. The class must implement the AsyncCallback<Void> interface . |
Return Value¶
None.
Example¶
The example below assigns a new role "TrialUser"
to "alice@yourmail.com"
identity.
Non-Blocking API
Backendless.UserService.assignRole( "alice@yourmail.com", "TrialUser", new AsyncCallback<Void>()
{
@Override
public void handleResponse( Void unused )
{
// on success logic
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
// exception handling logic
}
} );
Blocking API
Backendless.UserService.assignRole( "alice@yourmail.com", "TrialUser" );
where:
Argument | Description |
---|---|
identity |
A value for a column in the Users table marked as identity. By default the column marked as identity isemail , however, it can be changed to another column in Backendless Console. |
role name |
The name of а role that must be assigned. |
Important
This Codeless block is only available in CloudCode due to the security reasons. If this operation is exposed to users, then your application can be compromised.
This operation does not return a value.
Consider the following record in the Users
data table:
Suppose, the identity "alice@yourmail.com"
has the following assigned roles:
The example below assigns a new role "Team Leader"
to the "alice@yourmail.com"
identity.
The result of this operation is a new assigned role "Team Leader"
: