Get all available roles and permissions


how can I retrieve all available roles and permissions inside a service?


Hi @mauve,

It will likely depend how you are using roles and permissions. Is this all services in an AppHost or for a single endpoint? Are you using declarative validation for required roles (eg attributes like RequiresAnyRole)? Are you using UseDistinctRolesTables = true in your OrmLiteAutoRepository registration?

For all roles in your AppHost you can probably use HostContext.Metadata.GetAllRoles() and HostContext.Metadata.GetAllPermissions(), for a specific service you can get attribute information by using HostContext.Metadata.GetOperation(requestType).RequiredRoles, RequiresAnyRole, and same for Permissions.

If you can share any more info about what you are trying to achieve, might be able to suggest other methods more specific to your situation.

1 Like

helps in my case :slight_smile:

1 Like