Table of Contents

Class UserController

Namespace
adas_core.Controllers
Assembly
adas-core.dll
[ApiController]
[Route("users")]
public class UserController : ControllerBase
Inheritance
UserController
Inherited Members
Extension Methods

Constructors

UserController(IUserService, IAuthorityService, Lazy<IPermissionService>)

public UserController(IUserService userService, IAuthorityService authorityService, Lazy<IPermissionService> permissionService)

Parameters

userService IUserService
authorityService IAuthorityService
permissionService Lazy<IPermissionService>

Methods

DeleteUser(string)

Deletes a user identified by userId and removes the associated authority entries. Returns a successful response when the user is deleted, or throws an exception if the identifier is malformed or the deletion fails.

[HttpDelete("{userId}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> DeleteUser(string userId)

Parameters

userId string

The string representation of the user's identifier to be deleted.

Returns

Task<IActionResult>

An IActionResult indicating a successful operation via OkResult when the user is removed.

Exceptions

BadRequestException

Thrown when userId is not a valid identifier format.

ConflictException

Thrown when the user could not be deleted.

DeleteUserAuthorities(List<string>)

Deletes the specified user authorities by iterating through the provided list and removing each one.

[HttpPut("authorities")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> DeleteUserAuthorities(List<string> auths)

Parameters

auths List<string>

The list of authority identifiers to be deleted.

Returns

Task<IActionResult>

An IActionResult indicating the result of the operation; returns OkResult upon successful completion.

DeleteUserAuthorities(string, UpdatePasswordDto)

Updates the password for the specified user. Validates that the provided identifier is a valid format before delegating the password change to the user service.

[HttpPost("{id}/password")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> DeleteUserAuthorities(string id, UpdatePasswordDto updatePasswordDto)

Parameters

id string

The identifier of the user whose password will be updated.

updatePasswordDto UpdatePasswordDto

The data transfer object containing the current and new password values.

Returns

Task<IActionResult>

An IActionResult containing the result of the password update operation.

Exceptions

BadRequestException

Thrown when the provided id is not a valid identifier format.

DeleteUserAuthority(string)

Deletes a user authority identified by the specified authority identifier. Requires the caller to have the appropriate role permission and pass the resource-based authorization check.

[HttpDelete("authority/{authorityId}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> DeleteUserAuthority(string authorityId)

Parameters

authorityId string

The identifier of the authority to delete.

Returns

Task<IActionResult>

An IActionResult containing an HTTP 200 OK response upon successful deletion.

EditUser(User, bool)

Updates an existing user, optionally updating their password when updatePass is true.

[HttpPut("{updatePass}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> EditUser(User u, bool updatePass)

Parameters

u User

The user payload containing the updated information to persist.

updatePass bool

Indicates whether the password should be updated as part of the operation.

Returns

Task<IActionResult>

An IActionResult representing a successful update (200 OK).

Exceptions

ConflictException

Thrown when userService.UpdateUsersByRequest returns null, indicating the update could not be completed.

EditUserAuthority(Authorization)

Updates the authority configuration for a user, restricted to requests authorized against the "Source" entity by its display identifier.

[HttpPut("authority")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> EditUserAuthority(Authorization authorization)

Parameters

authorization Authorization

The authorization details to be applied to the user.

Returns

Task<IActionResult>

An IActionResult containing an OkResult when the authority update succeeds.

EditUserWithAuthorities(UpdateUserWithAuthDto, bool)

Updates an existing user together with their assigned authorities (permissions/roles). The updatePass flag determines whether the user's password is also updated as part of the operation.

[HttpPut("{updatePass}/authorities")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> EditUserWithAuthorities(UpdateUserWithAuthDto updateUserWithAuthDto, bool updatePass)

Parameters

updateUserWithAuthDto UpdateUserWithAuthDto

The data transfer object containing the updated user information and authority assignments.

updatePass bool

Flag indicating whether the user's password should be updated.

Returns

Task<IActionResult>

An IActionResult representing an HTTP 200 OK response on successful update.

GetAll()

Retrieves all users from the system.

[HttpGet]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetAll()

Returns

Task<IActionResult>

An IActionResult containing a UciResponse<T> with the list of User objects retrieved via the user service.

GetAllAuthorities()

Retrieves all available authorities. Requires the AuthSome role and permission to display Source entities.

[HttpGet("authorities")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetAllAuthorities()

Returns

Task<IActionResult>

An IActionResult containing a successful response with the list of Authorization objects.

GetAuthorityByUserId(string)

Retrieves the list of authorities (permissions) associated with a specific user identifier. Validates that the provided user identifier is a valid format before querying the authority service.

[HttpGet("{userId}/authority")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetAuthorityByUserId(string userId)

Parameters

userId string

The string representation of the user's identifier whose authorities are being requested.

Returns

Task<IActionResult>

An HTTP 200 response containing a UciResponse<T> with the list of Authorization objects for the user.

Exceptions

BadRequestException

Thrown when the provided userId is not a valid ObjectId format.

Login(LoginInfo)

Authenticates a user by validating the provided credentials and returns a token enriched with the user's authorities. On success, the password is cleared from the returned user payload to avoid exposing sensitive information.

[AllowAnonymous]
[HttpPost("login")]
public Task<IActionResult> Login(LoginInfo loginInfo)

Parameters

loginInfo LoginInfo

The login payload containing the username and password to authenticate.

Returns

Task<IActionResult>

An IActionResult containing a successful response with the authenticated TokenResult.

LoginPanel(LoginInfo)

Authenticates a user for the administrative panel and returns a token enriched with the user's authorities and panel-specific permissions. The user's password is cleared from the response before returning.

[AllowAnonymous]
[HttpPost("login/adm-panel")]
public Task<IActionResult> LoginPanel(LoginInfo loginInfo)

Parameters

loginInfo LoginInfo

The login credentials (username and password) used to authenticate the user.

Returns

Task<IActionResult>

A successful response containing the authentication token, the user's authorities, and the resolved panel permissions.

LoginWithAccessToken(string)

Authenticates a user by validating the provided access token and returns the associated token details, including its expiry time.

[AllowAnonymous]
[HttpGet("login")]
public Task<IActionResult> LoginWithAccessToken(string token)

Parameters

token string

The access token supplied via the query string used to perform the login.

Returns

Task<IActionResult>

An IActionResult containing a successful response with the access token information and its expiry time.

LoginWithAccessTokenPanel(string)

Handles login to the administrative panel by validating the provided access token and returning the authenticated token result along with the user's panel permissions.

[AllowAnonymous]
[HttpGet("login/adm-panel")]
public Task<IActionResult> LoginWithAccessTokenPanel(string token)

Parameters

token string

The access token used to authenticate the user for the administrative panel.

Returns

Task<IActionResult>

An IActionResult containing a successful response with the token result and the associated panel permissions.

LoginWithBearer()

Generates a new JWT bearer token for the user previously stored in the HTTP context items, enriches it with the user's authorities, and returns it in a success response.

[AllowAnonymous]
[HttpGet("token")]
public Task<IActionResult> LoginWithBearer()

Returns

Task<IActionResult>

An IActionResult containing the generated JWT token and user authorization details wrapped in a UciResponse<T>.

Exceptions

UnauthorizedException

Thrown when no user is found in HttpContext.Items["User"], indicating the user is not registered.

LoginWithBearerPanel()

Handles a GET request to the "token/adm-panel" endpoint to issue a new JWT token for the panel user resolved from the current HTTP context, enriching it with the user's authorities and panel-specific permissions.

[AllowAnonymous]
[HttpGet("token/adm-panel")]
public Task<IActionResult> LoginWithBearerPanel()

Returns

Task<IActionResult>

An IActionResult containing a successful UciResponse<T> of TokenResultPanel with the generated token, the user's authorization, and the permissions applicable to the panel.

Exceptions

UnauthorizedException

Thrown when no user is found in HttpContext.Items["User"], indicating an unauthorized user that is not registered.

LoginWithCas(string, string)

Authenticates a user via a CAS (Central Authentication Service) ticket and returns a JWT token upon success.

[AllowAnonymous]
[HttpGet("login-cas")]
public Task<IActionResult> LoginWithCas(string service, string ticket)

Parameters

service string

The service URL that initiated the CAS authentication request.

ticket string

The CAS ticket to validate against the user service.

Returns

Task<IActionResult>

A 200 OK response with a JWT token if the user is found; otherwise, a 404 Not Found response.

Exceptions

UnauthorizedException

Thrown when an error occurs during user lookup or JWT generation, indicating the user is not authorized.

Me()

Retrieves the currently authenticated user's profile from the HTTP context. Throws an unauthorized exception when no registered user is found in the request context.

[HttpGet("me")]
public IActionResult Me()

Returns

IActionResult

An IActionResult containing a successful response with the authenticated User.

Exceptions

UnauthorizedException

Thrown when the user retrieved from the HTTP context items is null, indicating the user is not registered.

NewUser(User)

Handles a POST request to create a new user by delegating to the user service and returning the created user.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> NewUser(User u)

Parameters

u User

The user data submitted in the request used to create the new user.

Returns

Task<IActionResult>

An IActionResult containing the newly created user in an HTTP 200 OK response.

NewUserAuthority(Authorization)

Creates a new user authority for the provided authorization request and returns the result.

[HttpPost("authority")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> NewUserAuthority(Authorization authorization)

Parameters

authorization Authorization

The authorization data used to create the new authority.

Returns

Task<IActionResult>

An IActionResult containing the newly created authority.

NewUserWithAuthorities(CreateUserWithAuthDto)

Creates a new user along with the associated authorities, enforcing role-based authorization and the required "Source" / "DisplayId" permission checks.

[HttpPost("authorities")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> NewUserWithAuthorities(CreateUserWithAuthDto createUserWithAuthDto)

Parameters

createUserWithAuthDto CreateUserWithAuthDto

The DTO containing the new user's information and the authorities to assign.

Returns

Task<IActionResult>

An IActionResult containing the created user returned via an HTTP 200 OK response.

PaginatedUsers(PaginationFilter)

Retrieves a paginated list of users based on the provided pagination filter configuration. Validates that the configuration payload is supplied and returns the resulting page of users.

[HttpPost("paginated")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> PaginatedUsers(PaginationFilter config)

Parameters

config PaginationFilter

The pagination filter applied to the user query, supplied in the request body.

Returns

Task<IActionResult>

An IActionResult containing the paginated users produced by the user service.

Exceptions

BadRequestException

Thrown when config is null.

RefreshToken(string)

Refreshes the authentication token using the provided refresh token. Returns a new token wrapped in a success response, allowing anonymous access for token renewal.

[AllowAnonymous]
[HttpPost("refresh-token")]
public Task<IActionResult> RefreshToken(string refreshToken)

Parameters

refreshToken string

The refresh token obtained from a previous authentication request, supplied in the request body.

Returns

Task<IActionResult>

An IActionResult containing a UciResponse<T> with the refreshed token details on success.

RefreshTokenPanel(string)

Refreshes the authentication token for the administrative panel and returns the new token along with the user's permissions.

[HttpPost("refresh-token/adm-panel")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> RefreshTokenPanel(string refreshToken)

Parameters

refreshToken string

The refresh token string provided in the request body used to obtain a new access token.

Returns

Task<IActionResult>

An IActionResult containing a UciResponse<T> with the refreshed token result and the associated permissions for the panel.