diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/dir.service.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/dir.service.ts index 6067929..39c7659 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/dir.service.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/dir.service.ts @@ -7,9 +7,10 @@ import { UrlService } from './url.service'; @Injectable({ providedIn: 'root' }) +// TODO: Consolidate all directory services and remove unnecessary methods. export class DirService { private baseUrl: string - constructor(private http: HttpClient, urlService : UrlService) { + constructor(private http: HttpClient, urlService: UrlService) { this.http = http; this.baseUrl = urlService.apiRoute.directory; } @@ -22,4 +23,8 @@ export class DirService { return this.http.get(this.baseUrl, { params, withCredentials: true }); } + + createSearchRoot(username: string, password: string): Observable { + return this.http.post(this.baseUrl, { username: username, password: password }, { withCredentials: true }) + } } \ No newline at end of file diff --git a/DigitalData.UserManager.API/Controllers/DirectoryController.cs b/DigitalData.UserManager.API/Controllers/DirectoryController.cs index 70b8a07..6d6d129 100644 --- a/DigitalData.UserManager.API/Controllers/DirectoryController.cs +++ b/DigitalData.UserManager.API/Controllers/DirectoryController.cs @@ -82,16 +82,16 @@ public class DirectoryController : ControllerBase } } - [HttpPost("CreateSearchRoot")] + [HttpPost] public async Task CreateSearchRoot([FromBody] SearchRootCreateDto searchRootCreateDto) { try { - var dirEntryUsername = searchRootCreateDto.DirEntryUsername ?? CurrentUser; + var dirEntryUsername = searchRootCreateDto.Username ?? CurrentUser; if (dirEntryUsername is null) return Unauthorized(); - bool isValid = _dirSearchService.ValidateCredentials(dirEntryUsername, searchRootCreateDto.DirEntryPassword); + bool isValid = _dirSearchService.ValidateCredentials(dirEntryUsername, searchRootCreateDto.Password); if (!isValid) return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFound])); @@ -100,7 +100,7 @@ public class DirectoryController : ControllerBase if (!userResult.IsSuccess || userResult.Data is null) return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFoundInLocalDB])); - _dirSearchService.SetSearchRootCache(userResult.Data.Username, searchRootCreateDto.DirEntryPassword); + _dirSearchService.SetSearchRootCache(userResult.Data.Username, searchRootCreateDto.Password); return Ok(); } catch (Exception ex) @@ -162,11 +162,12 @@ public class DirectoryController : ControllerBase } [HttpGet("Group")] - public IActionResult GetGroups(string? dirEntryUsername, params string[] propName) + [Authorize] + public IActionResult GetGroups(params string[] propName) { try { - dirEntryUsername ??= CurrentUser; + string dirEntryUsername = CurrentUser!; if (dirEntryUsername is null) return Unauthorized(); @@ -190,12 +191,12 @@ public class DirectoryController : ControllerBase } [HttpGet("User")] - public IActionResult GetUsersByGroupName(string? dirEntryUsername, [FromQuery] string? groupName = null) + public IActionResult GetUsersByGroupName([FromQuery] string? groupName = null) { try { string[] propName = { "memberof", "samaccountname", "givenname", "sn", "mail" }; - dirEntryUsername ??= CurrentUser; + string dirEntryUsername = CurrentUser!; if (dirEntryUsername is null) return Unauthorized(); diff --git a/DigitalData.UserManager.Application/DTOs/SearchRootCreateDto.cs b/DigitalData.UserManager.Application/DTOs/SearchRootCreateDto.cs index 6ab4748..9fbd14b 100644 --- a/DigitalData.UserManager.Application/DTOs/SearchRootCreateDto.cs +++ b/DigitalData.UserManager.Application/DTOs/SearchRootCreateDto.cs @@ -1,4 +1,4 @@ namespace DigitalData.UserManager.Application.DTOs { - public record SearchRootCreateDto(string? DirEntryUsername, string DirEntryPassword); + public record SearchRootCreateDto(string? Username, string Password); } \ No newline at end of file