Retrieving Available User Roles¶
Description¶
This operation returns a list of the roles associated with the user account currently logged in to the Backendless application. If the request is sent without logging in, the system will return only one role - NotAuthenticatedUser
.
Method¶
Non-blocking Method :
The method call does not block - it returns immediately. The AsyncCallback
assigns a role to a User argument and receives either the response or the fault returned by the Backendless servers.
Backendless.UserService.getUserRoles( new AsyncCallback<List<String>>());
Blocking API
List<String> Backendless.UserService.getUserRoles() throws BackendlessException;
Return Value¶
Returns an array of roles assigned to the currently logged in user
[
"roleName 1",
"roleName 2"
...
"roleName N"
]
Example¶
The example below logs in as "alice@wonderland.com"
, and retrieves the current user roles as an array containing string values.
Non-Blocking API
Before retrieving the user roles, log in as described in the Login section. Then, retrieve the user roles as follows:
//login user
Backendless.UserService.login( "alice@yourmail.com",
"wonderland",
new AsyncCallback<BackendlessUser>()
{
@Override
public void handleResponse( BackendlessUser backendlessUser )
{
// user has been logged in. Get user roles.
Backendless.UserService.getUserRoles(
new AsyncCallback<List<String>>()
{
@Override
public void handleResponse( List<String> userRoles )
{
//here we get all user roles - "userRoles".
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
// get user roles, to get the error code call backendlessFault.getCode()
}
} );
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
// login failed, to get the error code call backendlessFault.getCode()
}
} );
Blocking API
//login user
Backendless.UserService.login("alice@yourmail.com", "wonderland");
// user has been logged in. Get user roles.
List<String> roleNames = Backendless.UserService.getUserRoles();
Codeless Reference¶
Returns a list containing current user roles.
Consider the following record in the Users
data table:
The example below logs in as "alice@wonderland.com"
, and retrieves the current user roles as a list containing string values.
The output will look as shown below after the Codeless logic runs: