diff --git a/src/Koogle.Application/DependencyInjection.cs b/src/Koogle.Application/DependencyInjection.cs index 9d8578f..c9f7b99 100644 --- a/src/Koogle.Application/DependencyInjection.cs +++ b/src/Koogle.Application/DependencyInjection.cs @@ -1,5 +1,6 @@ using Koogle.Application.Interfaces; using Koogle.Application.Services; +using Koogle.Domain.Interfaces; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.DependencyInjection; using System; @@ -29,6 +30,7 @@ namespace Koogle.Application services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); return services; } diff --git a/src/Koogle.Domain/Interfaces/IEmailService.cs b/src/Koogle.Application/Interfaces/IEmailService.cs similarity index 94% rename from src/Koogle.Domain/Interfaces/IEmailService.cs rename to src/Koogle.Application/Interfaces/IEmailService.cs index bd62575..922701f 100644 --- a/src/Koogle.Domain/Interfaces/IEmailService.cs +++ b/src/Koogle.Application/Interfaces/IEmailService.cs @@ -1,8 +1,4 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Koogle.Domain.Interfaces +namespace Koogle.Application.Interfaces { /// /// Service interface for email notifications. diff --git a/src/Koogle.Infrastructure/Services/StubEmailService.cs b/src/Koogle.Application/Services/StubEmailService.cs similarity index 95% rename from src/Koogle.Infrastructure/Services/StubEmailService.cs rename to src/Koogle.Application/Services/StubEmailService.cs index 1f6c4c2..6fecb51 100644 --- a/src/Koogle.Infrastructure/Services/StubEmailService.cs +++ b/src/Koogle.Application/Services/StubEmailService.cs @@ -1,10 +1,8 @@ +using Koogle.Application.Interfaces; using Koogle.Domain.Interfaces; using Microsoft.Extensions.Logging; -using System; -using System.Threading; -using System.Threading.Tasks; -namespace Koogle.Infrastructure.Services; +namespace Koogle.Application.Services; /// /// Stub email service that logs instead of sending emails. diff --git a/src/Koogle.Domain/Interfaces/ICurrentUserService.cs b/src/Koogle.Domain/Interfaces/ICurrentUserService.cs deleted file mode 100644 index f2bd5e1..0000000 --- a/src/Koogle.Domain/Interfaces/ICurrentUserService.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Koogle.Domain.Interfaces -{ - public interface ICurrentUserService - { - /// - /// Die ID des aktuell angemeldeten Benutzers. - /// Gibt Guid.Empty zurück, wenn kein Benutzer angemeldet ist. - /// - int UserId { get; } - - /// - /// Gibt an, ob ein Benutzer authentifiziert ist. - /// - bool IsAuthenticated { get; } - } -} diff --git a/src/Koogle.Infrastructure/DependencyInjection.cs b/src/Koogle.Infrastructure/DependencyInjection.cs index 67fb679..08dde99 100644 --- a/src/Koogle.Infrastructure/DependencyInjection.cs +++ b/src/Koogle.Infrastructure/DependencyInjection.cs @@ -1,10 +1,8 @@ using Koogle.Domain.Interfaces; -using Koogle.Infrastrcuture.Services; using Koogle.Infrastructure.Data; using Koogle.Infrastructure.Identity; using Koogle.Infrastructure.Repositories; using Koogle.Infrastructure.Security; -using Koogle.Infrastructure.Services; using KoogleApp.Data; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; @@ -75,9 +73,6 @@ public static class DependencyInjection // HTTP Context Accessor (für CurrentUserService) services.AddHttpContextAccessor(); - // Current UserProfile Service - services.AddScoped(); - // Repositories services.AddScoped(); services.AddScoped(); @@ -86,7 +81,7 @@ public static class DependencyInjection services.AddScoped(); // Services - services.AddScoped(); + //services.AddScoped(); services.AddCascadingAuthenticationState(); diff --git a/src/Koogle.Infrastructure/Services/CurrentUserService.cs b/src/Koogle.Infrastructure/Services/CurrentUserService.cs deleted file mode 100644 index 46a9615..0000000 --- a/src/Koogle.Infrastructure/Services/CurrentUserService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Koogle.Domain.Interfaces; -using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Koogle.Infrastrcuture.Services; - -public class CurrentUserService : ICurrentUserService -{ - private readonly IHttpContextAccessor _httpContextAccessor; - - /// - /// Erstellt eine neue Instanz des CurrentUserService. - /// - /// Der HTTP-Kontext-Accessor. - public CurrentUserService(IHttpContextAccessor httpContextAccessor) - { - _httpContextAccessor = httpContextAccessor; - } - - /// - public int UserId - { - get - { - //var userIdClaim = _httpContextAccessor.HttpContext?.UserProfile?.FindFirst(ClaimTypes.NameIdentifier)?.Value - // ?? _httpContextAccessor.HttpContext?.UserProfile?.FindFirst("sub")?.Value - // ?? _httpContextAccessor.HttpContext?.UserProfile?.FindFirst("oid")?.Value; - var userIdClaim = _httpContextAccessor.HttpContext?.User?.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier")?.Value; - - return 0; - //if (string.IsNullOrEmpty(userIdClaim)) - // return Guid.Empty; - - //// Versuche zuerst als Guid zu parsen (für interne UserProfile-IDs) - //if (Guid.TryParse(userIdClaim, out var userId)) - // return userId; - - //// Falls es eine Azure AD Object ID ist, generiere eine deterministische Guid daraus - //return GenerateDeterministicGuid(userIdClaim); - } - } - - /// - public bool IsAuthenticated => - _httpContextAccessor.HttpContext?.User?.Identity?.IsAuthenticated ?? false; - - /// - /// Generiert eine deterministische Guid aus einem String. - /// - private static Guid GenerateDeterministicGuid(string input) - { - using var md5 = System.Security.Cryptography.MD5.Create(); - var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)); - return new Guid(hash); - } -} \ No newline at end of file diff --git a/src/Koogle.Web/Components/Pages/Account/AccessDenied.razor b/src/Koogle.Web/Components/Pages/Account/AccessDenied.razor new file mode 100644 index 0000000..11054f6 --- /dev/null +++ b/src/Koogle.Web/Components/Pages/Account/AccessDenied.razor @@ -0,0 +1,9 @@ +@page "/account/accessdenied" + +

AccessDenied

+ + + +@code { + +}