Kommentare zur Dokumentation hinzugefügt und Pakete konfiguriert.
This commit is contained in:
BIN
DigitalData.Core.Application/Assets/icon.png
Normal file
BIN
DigitalData.Core.Application/Assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1020 KiB |
@@ -81,6 +81,16 @@ namespace DigitalData.Core.Application
|
||||
.AddScoped<IDirectorySearchService, DirectorySearchService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the JWT service to the <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TClaimValue">The type of the claim value used in the JWT token.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <param name="tokenDescriptorFactory">A function that takes a claim value of type <typeparamref name="TClaimValue"/> and returns a <see cref="SecurityTokenDescriptor"/> used to configure the JWT token.</param>
|
||||
/// <returns>The original <see cref="IServiceCollection"/> instance, allowing further configuration.</returns>
|
||||
/// <remarks>
|
||||
/// This method adds the necessary services for handling JWT tokens. The <paramref name="tokenDescriptorFactory"/> function is used to generate the <see cref="SecurityTokenDescriptor"/> which is essential for creating the JWT tokens.
|
||||
/// </remarks>
|
||||
public static IServiceCollection AddJWTService<TClaimValue>(this IServiceCollection services, Func<TClaimValue, SecurityTokenDescriptor> tokenDescriptorFactory)
|
||||
{
|
||||
return services.AddScoped<IJWTService<TClaimValue>, JWTService<TClaimValue>>(provider => new (tokenDescriptorFactory));
|
||||
|
||||
@@ -4,8 +4,25 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Description>This package provides implementations for application services within the DigitalData.Core.Abstractions library. It includes generic CRUD operations using Entity Framework Core, AutoMapper integration for object mapping, and additional services such as JWT handling and directory search functionality, adhering to Clean Architecture principles to ensure separation of concerns and maintainability.</Description>
|
||||
<PackageId>DigitalData.Core.Application</PackageId>
|
||||
<Authors>Digital Data GmbH</Authors>
|
||||
<Company>Digital Data GmbH</Company>
|
||||
<Product>DigitalData.Core.Application</Product>
|
||||
<Copyright>Copyright 2024</Copyright>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||
<PackageTags>digital data core application clean architecture</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\DigitalData.Core.Abstractions\Assets\icon.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
|
||||
@@ -21,4 +38,11 @@
|
||||
<ProjectReference Include="..\DigitalData.Core.Abstractions\DigitalData.Core.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Assets\icon.png">
|
||||
<PackagePath>\</PackagePath>
|
||||
<Pack>True</Pack>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
namespace DigitalData.Core.Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the options for configuring directory search operations.
|
||||
/// </summary>
|
||||
public class DirectorySearchOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or initializes the name of the server to be used in the directory search.
|
||||
/// </summary>
|
||||
public string? ServerName { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or initializes the root directory path for the search.
|
||||
/// </summary>
|
||||
public string? Root { get; init; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or initializes the number of days before the user cache expires.
|
||||
/// </summary>
|
||||
public int UserCacheExpirationDays { get; init; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or initializes the custom search filters to be applied during directory searches.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> CustomSearchFilters { get; init; } = new();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,14 @@ namespace DigitalData.Core.Application
|
||||
private readonly DateTimeOffset _userCacheExpiration;
|
||||
public Dictionary<string, string> CustomSearchFilters { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DirectorySearchService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="options">The options for directory search.</param>
|
||||
/// <param name="memoryCache">The memory cache.</param>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if the server name or root directory is not configured.
|
||||
/// </exception>
|
||||
public DirectorySearchService(IOptions<DirectorySearchOptions> options, IMemoryCache memoryCache)
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
@@ -39,12 +47,27 @@ namespace DigitalData.Core.Application
|
||||
_userCacheExpiration = DateTimeOffset.Now.Date.AddDays(dayCounts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the credentials of a directory entry.
|
||||
/// </summary>
|
||||
/// <param name="dirEntryUsername">The directory entry username.</param>
|
||||
/// <param name="dirEntryPassword">The directory entry password.</param>
|
||||
/// <returns>True if the credentials are valid; otherwise, false.</returns>
|
||||
public bool ValidateCredentials(string dirEntryUsername, string dirEntryPassword)
|
||||
{
|
||||
using var context = new PrincipalContext(ContextType.Domain, ServerName, Root);
|
||||
return context.ValidateCredentials(dirEntryUsername, dirEntryPassword);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all directory entries matching the specified filter.
|
||||
/// </summary>
|
||||
/// <param name="searchRoot">The search root.</param>
|
||||
/// <param name="filter">The search filter.</param>
|
||||
/// <param name="searchScope">The search scope.</param>
|
||||
/// <param name="sizeLimit">The size limit.</param>
|
||||
/// <param name="properties">The properties to load.</param>
|
||||
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
||||
public DataResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties)
|
||||
{
|
||||
List<ResultPropertyCollection> list = new();
|
||||
@@ -74,10 +97,17 @@ namespace DigitalData.Core.Application
|
||||
return Result.Success<IEnumerable<ResultPropertyCollection>>(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all directory entries matching the specified filter, using the user cache.
|
||||
/// </summary>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="filter">The search filter.</param>
|
||||
/// <param name="searchScope">The search scope.</param>
|
||||
/// <param name="sizeLimit">The size limit.</param>
|
||||
/// <param name="properties">The properties to load.</param>
|
||||
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
||||
public DataResult<IEnumerable<ResultPropertyCollection>> FindAllByUserCache(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties)
|
||||
{
|
||||
List<ResultPropertyCollection> list = new();
|
||||
|
||||
_memoryCache.TryGetValue(username, out DirectoryEntry? searchRoot);
|
||||
|
||||
if (searchRoot is null)
|
||||
@@ -86,6 +116,11 @@ namespace DigitalData.Core.Application
|
||||
return FindAll(searchRoot, filter, searchScope, sizeLimit, properties);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the search root in the cache.
|
||||
/// </summary>
|
||||
/// <param name="dirEntryUsername">The directory entry username.</param>
|
||||
/// <param name="dirEntryPassword">The directory entry password.</param>
|
||||
public void SetSearchRootCache(string dirEntryUsername, string dirEntryPassword)
|
||||
{
|
||||
if (_userCacheExpiration == default)
|
||||
@@ -94,6 +129,12 @@ namespace DigitalData.Core.Application
|
||||
_memoryCache.Set(key: dirEntryUsername, new DirectoryEntry(path: SearchRootPath, username: dirEntryUsername, password: dirEntryPassword), absoluteExpiration: _userCacheExpiration);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the search root from the cache.
|
||||
/// </summary>
|
||||
/// <param name="dirEntryUsername">The directory entry username.</param>
|
||||
/// <returns>The cached <see cref="DirectoryEntry"/> if found; otherwise, null.</returns>
|
||||
public DirectoryEntry? GetSearchRootCache(string dirEntryUsername)
|
||||
{
|
||||
_memoryCache.TryGetValue(dirEntryUsername, out DirectoryEntry? root);
|
||||
|
||||
Reference in New Issue
Block a user