Class PermissionService
- Namespace
- Shard.Server.Modules.Permissions
- Assembly
- Shard.Server.Modules.dll
Runtime permission service that resolves permissions through registered providers, highest priority to lowest. The first definitive provider result is returned.
public sealed class PermissionService : IPermissionService
- Inheritance
-
PermissionService
- Implements
- Inherited Members
Constructors
PermissionService(IEventBus, string?)
public PermissionService(IEventBus eventBus, string? path = null)
Parameters
Properties
ActiveProvider
The provider with the highest priority. This is the provider that will be used for permission modifications.
public PermissionProvider ActiveProvider { get; }
Property Value
HytaleProvider
public HytalePermissionProvider HytaleProvider { get; }
Property Value
Providers
public IReadOnlyList<PermissionProvider> Providers { get; }
Property Value
Methods
AddUserToGroup(Guid, string)
Add a user to a group
public bool AddUserToGroup(Guid uuid, string group)
Parameters
Returns
- bool
true if the user was added to the group; otherwise, false.
GetGroupPermissions(string)
Gets all explicitly assigned permissions for a group.
public IReadOnlyDictionary<string, bool> GetGroupPermissions(string group)
Parameters
groupstringThe group to get permissions for
Returns
- IReadOnlyDictionary<string, bool>
A read-only dictionary mapping permission nodes to their granted or denied state.
GetUserGroups(Guid)
Gets the groups currently assigned to a user.
public IReadOnlyList<string> GetUserGroups(Guid uuid)
Parameters
uuidGuidThe UUID of the user
Returns
- IReadOnlyList<string>
A read-only list of group names.
GetUserPermissions(Guid)
Gets all explicitly assigned permissions for a user.
public IReadOnlyDictionary<string, bool> GetUserPermissions(Guid uuid)
Parameters
uuidGuidThe UUID of the user
Returns
- IReadOnlyDictionary<string, bool>
A read-only dictionary mapping permission nodes to their granted or denied state.
HasPermission(Guid, string, bool)
Determines whether a user has a specific permission node or not. Highest priority provider -> Lowest Priority Provider. User permissions are checked before group-inherited permissions.
public bool HasPermission(Guid uuid, string node, bool def = false)
Parameters
uuidGuidThe UUID of the user to check
nodestringThe permission node to check
defboolThe default value to return if the user does not have the permission
Returns
RegisterProvider(PermissionProvider)
Registers a permission provider.
public void RegisterProvider(PermissionProvider provider)
Parameters
providerPermissionProviderThe provider to register.
RemoveGroupPermission(string, string)
Removes an explicitly assigned permission from a group
public void RemoveGroupPermission(string group, string node)
Parameters
RemoveUserFromGroup(Guid, string)
Removes a user from a group
public bool RemoveUserFromGroup(Guid uuid, string group)
Parameters
Returns
- bool
true if the user was removed from the group; otherwise, false.
RemoveUserPermission(Guid, string)
Removes an explicitly assigned permission
public void RemoveUserPermission(Guid uuid, string node)
Parameters
SetGroupPermission(string, string, bool)
Sets a permission for a group
public void SetGroupPermission(string group, string node, bool value)
Parameters
groupstringThe group to set the permission for
nodestringThe permission node to set
valueboolThe value to set the permission to
SetUserGroups(Guid, IEnumerable<string>)
Replaces the group assigned to a user.
public void SetUserGroups(Guid uuid, IEnumerable<string> groups)
Parameters
uuidGuidThe UUID of the user
groupsIEnumerable<string>The groups the user should belong to
SetUserPermission(Guid, string, bool)
Set or update a permission for a user
public void SetUserPermission(Guid uuid, string node, bool value)
Parameters
uuidGuidThe UUID of the user
nodestringThe permission node to set
valueboolThe value to set the permission to
UnregisterProvider(PermissionProvider)
Unregisters a permission provider.
public bool UnregisterProvider(PermissionProvider provider)
Parameters
providerPermissionProviderThe provider to unregister.
Returns
- bool
true if the provider was unregistered; otherwise, false.