Class AuthorityService
- Namespace
- adas_core.Authentication
- Assembly
- adas-core.Authentication.dll
public class AuthorityService : IAuthorityService
- Inheritance
-
AuthorityService
- Implements
- Inherited Members
- Extension Methods
Constructors
AuthorityService(IAuthorityRepository, IHttpContextAccessor, ILocalAuditService)
public AuthorityService(IAuthorityRepository authorityRepository, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService)
Parameters
authorityRepositoryIAuthorityRepositoryhttpContextAccessorIHttpContextAccessorauditServiceILocalAuditService
Methods
CreateNew(string, ObjectId)
Creates a new authority for the specified user with the given role name by delegating to the authority repository.
public void CreateNew(string roleName, ObjectId userId)
Parameters
roleNamestringThe name of the role to associate with the authority.
userIdObjectIdThe unique identifier of the user for whom the authority is being created.
CreateNewUserAuthority(Authorization)
Creates a new user authority by persisting the provided authorization record and writing an audit log entry for the operation.
public Task<Authorization?> CreateNewUserAuthority(Authorization authorization)
Parameters
authorizationAuthorizationThe authorization entity to be created and stored.
Returns
- Task<Authorization>
The created Authorization entity.
DeleteAuthoritiesForUser(ObjectId)
Deletes all authorities associated with the specified user and records an audit log entry for each removed authority. Returns false if no authorities were deleted or if an exception is encountered during processing.
public Task<bool> DeleteAuthoritiesForUser(ObjectId id)
Parameters
idObjectIdThe unique identifier of the user whose authorities should be deleted.
Returns
DeleteUserAuthority(ObjectId)
Deletes a user authority by its parsed identifier and records an audit log entry when the deletion succeeds.
Returns true if the authority was found and removed, and false when the entity is not found or an exception occurs during processing.
public Task<bool> DeleteUserAuthority(ObjectId userAuthorityIdParsed)
Parameters
userAuthorityIdParsedObjectIdThe parsed identifier of the user authority to delete.
Returns
EditUserAuthority(Authorization)
Edits an existing user authority, records the change in an audit log, and returns the updated authorization.
Returns null if the update operation fails due to an exception.
public Task<Authorization?> EditUserAuthority(Authorization authorization)
Parameters
authorizationAuthorizationThe authorization entity containing the updated information to persist.
Returns
- Task<Authorization>
The updated Authorization on success, or
nullif an error occurs during the operation.
GetAllAuthorities()
Retrieves all available authorities from the underlying repository.
public Task<List<Authorization>> GetAllAuthorities()
Returns
- Task<List<Authorization>>
A task that represents the asynchronous operation, containing a list of all Authorization records.
GetUserAuthorities(ObjectId)
Retrieves the authorities of the specified user.
public Task<List<Authorization>> GetUserAuthorities(ObjectId userId)
Parameters
userIdObjectId
Returns
- Task<List<Authorization>>
A list of the user's authorities.
InsertOne(Authorization)
Inserts a new authorization into the authority repository and records an audit log entry for the operation using the current HTTP context user.
public Task InsertOne(Authorization authorization)
Parameters
authorizationAuthorizationThe authorization entity to be inserted and tracked in the audit log.
Returns
updateOne(Authorization)
Updates an existing authorization record in the repository and records an audit log entry capturing the previous and updated states for the current user.
public Task updateOne(Authorization authorization)
Parameters
authorizationAuthorizationThe authorization entity containing the identifier of the record to update and its new values.