Logger zu DirectoryController hinzugefügt
This commit is contained in:
parent
d76623155a
commit
766e8d913d
@ -19,8 +19,9 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
private readonly IDirectorySearchService _dirSearchService;
|
||||
private readonly Dictionary<string, string> _customSearchFilters;
|
||||
private readonly IStringLocalizer<Resource> _localizer;
|
||||
private readonly ILogger<DirectoryController> _logger;
|
||||
|
||||
public DirectoryController(IConfiguration configuration, IStringLocalizer<Resource> localizer, IUserService userService, IDirectorySearchService directorySearchService)
|
||||
public DirectoryController(IConfiguration configuration, IStringLocalizer<Resource> localizer, IUserService userService, IDirectorySearchService directorySearchService, ILogger<DirectoryController> logger)
|
||||
{
|
||||
_localizer = localizer;
|
||||
_userService = userService;
|
||||
@ -28,10 +29,13 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
|
||||
var customSearchFiltersSection = configuration.GetSection("DirectorySearch:CustomSearchFilters");
|
||||
_customSearchFilters = customSearchFiltersSection.Get<Dictionary<string, string>>() ?? new();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("Root/{username}")]
|
||||
public IActionResult GetRootOf(string username)
|
||||
{
|
||||
try
|
||||
{
|
||||
var root = _dirSearchService.GetSearchRootCache(username);
|
||||
|
||||
@ -46,9 +50,17 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
schemaClassName = root.SchemaClassName
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("CustomSearchFilter")]
|
||||
public IActionResult GetAllCustomFilters(string? filtername)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (filtername is null)
|
||||
{
|
||||
@ -60,9 +72,17 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
return filter is null ? NotFound() : Ok(filter);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("CreateSearchRoot")]
|
||||
public async Task<IActionResult> CreateSearchRoot([FromBody] SearchRootCreateDto searchRootCreateDto)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dirEntryUsername = searchRootCreateDto.DirEntryUsername ?? CurrentUser;
|
||||
if (dirEntryUsername is null)
|
||||
@ -74,15 +94,23 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFound]));
|
||||
|
||||
var userResult = await _userService.ReadByUsernameAsync(dirEntryUsername);
|
||||
if(!userResult.IsSuccess || userResult.Data is null)
|
||||
if (!userResult.IsSuccess || userResult.Data is null)
|
||||
return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFoundInLocalDB]));
|
||||
|
||||
_dirSearchService.SetSearchRootCache(userResult.Data.Username, searchRootCreateDto.DirEntryPassword);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("SearchByFilter/{filter}")]
|
||||
public IActionResult SearchByFilter([FromRoute] string filter, string? dirEntryUsername, params string[] propName)
|
||||
{
|
||||
try
|
||||
{
|
||||
dirEntryUsername ??= CurrentUser;
|
||||
|
||||
@ -92,9 +120,17 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
var result = _dirSearchService.FindAllByUserCache(dirEntryUsername, filter, properties: propName);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("SearchByFilterName/{filterName}")]
|
||||
public IActionResult SearchByFilterName([FromRoute] string filterName, string? dirEntryUsername, params string[] propName)
|
||||
{
|
||||
try
|
||||
{
|
||||
dirEntryUsername ??= CurrentUser;
|
||||
|
||||
@ -110,9 +146,17 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("Group")]
|
||||
public IActionResult GetGroups(string? dirEntryUsername, params string[] propName)
|
||||
{
|
||||
try
|
||||
{
|
||||
dirEntryUsername ??= CurrentUser;
|
||||
|
||||
@ -128,9 +172,17 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("User")]
|
||||
public IActionResult GetUsersByGroupName(string? dirEntryUsername, [FromQuery] string? groupName = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] propName = { "memberof", "samaccountname", "givenname", "sn", "mail" };
|
||||
dirEntryUsername ??= CurrentUser;
|
||||
@ -153,6 +205,12 @@ namespace DigitalData.UserManager.API.Controllers
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
private string? CurrentUser
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user