The GAMUser object of the GeneXus Access Manager (GAM) Library provides methods to obtain the user's Roles.
They are as follows:
- (Boolean) GAMUser.CheckRole(String: RoleName)
- (Boolean) GAMUser.CheckRoleById(Numeric: RoleId)
- (Boolean) GAMUser.CheckRoleByGUID(GUID: RoleGUID)
- (Boolean) GAMUser.CheckRoleByExternalId(String: RoleExternalId)
The following methods of the GAMRepository object are the same as the previous ones:
- (Boolean) GAMRepository.CheckRole(String: RoleName)
- (Boolean) GAMRepository.CheckRoleById(Numeric: RoleId)
- (Boolean) GAMRepository.CheckRoleByGUID(GUID: RoleGUID)
- (Boolean) GAMRepository.CheckRoleByExternalId(String: RoleExternalId)
These methods return true when the role is associated with the user or when the role is a descendant of a role associated with the user.
The following code is present in the Start Event of the GAMMasterpage object:
If GAMUser.CheckRoleByExternalId(!"is_gam_administrator")
Header1.Object= GAMHeader.Create(ContHolder1.Pgmname)
//OK
Else
GAMExampleNotAuthorized.Link()
Endif
Returns a collection of Roles which have been associated with the User.
GAMUser.GetRoles(out:GAMError Collection): GAMRole Collection
Returns a collection of Roles which have been associated with the User and their descendants.
GAMUser.GetRoles(out:GAMError Collection): GAMRole Collection
These methods do not consider the Require Access Permissions Application Property. That is, you can manage roles in your application but not permissions because they are independent of each other.
HowTo: Get all users which have a given set of Roles