This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roleRequest = new RetrieveRolePrivilegesRoleRequest { RoleId = new Guid("securityRoleId") }; | |
var roleReponse = service.Execute(roleRequest); |
roleResponse.RolePrivileges will contain a long list of privilege IDs which are not very useful on their own. You can get the name of all of these privileges like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var privilegeQuery = new QueryExpression { EntityName = "privilege", ColumnSet = new ColumnSet(true) }; | |
var filter = new FilterExpression(LogicalOperator.Or); | |
foreach (var p in roleResponse.RolePrivileges) | |
filter.AddCondition("privilegeid", ConditionOperator.Equal, p.PrivilegeId); | |
privilegeQuery.Criteria = filter; | |
var privileges = service.RetrieveMultiple(privilegeQuery); |
To go one step further, you can filter your privileges by the entity they refer to like so:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contactPrivileges = privileges.Entities.ToList() | |
.Where(p => p.GetAttributeValue<string>("name").ToLower() | |
.Contains("contact")) | |
.ToList(); |
No comments:
Post a Comment