From 4647444b6c2c2ded151917202e0d44ae4300f4f2 Mon Sep 17 00:00:00 2001 From: Richard Garcia Date: Mon, 30 Mar 2026 14:22:58 -0300 Subject: [PATCH] fix: remove unused experimental scope functionality and related components --- .../Handlers/Scope/ScopeCreationHandler.cs | 30 ------- .../Mappers/ScopeMapper.cs | 19 ---- .../Payloads/Scope/ScopeCreationScheme.cs | 10 --- .../Payloads/Scope/ScopeDetailsScheme.cs | 8 -- .../Usings.cs | 1 - .../Scope/ScopeCreationValidator.cs | 17 ---- .../Constants/Permissions.cs | 5 -- .../Constants/RealmPermissions.cs | 12 +-- .../Constants/Scopes.cs | 34 -------- .../Aggregates/Realm.cs | 1 - .../Aggregates/Scope.cs | 9 -- .../Collections/IScopeCollection.cs | 14 --- .../Errors/ScopeErrors.cs | 14 --- .../Filtering/Builders/ScopeFiltersBuilder.cs | 25 ------ .../Filtering/ScopeFilters.cs | 10 --- .../Extensions/DataPersistenceExtension.cs | 1 - .../Extensions/ValidationExtension.cs | 1 - .../Usings.cs | 2 - .../Constants/Collections.cs | 1 - .../Constants/Documents.cs | 8 -- .../Persistence/ScopesCollection.cs | 46 ---------- .../Pipelines/ScopeFiltersStage.cs | 18 ---- .../Controllers/ScopesController.cs | 25 ------ .../Conventions/ScopesConventions.cs | 11 --- .../Extensions/BootstrapperExtension.cs | 11 --- .../HttpsRichardy.Federation.WebApi/Usings.cs | 1 - .../Endpoints/ScopeEndpointTests.cs | 86 ------------------- Applications/Backend/Tests/Usings.cs | 1 - Applications/Proxy/Source/ocelot.json | 23 ----- Documentation/errors-reference.md | 9 -- .../Source/Errors/ScopeErrors.cs | 14 --- 31 files changed, 1 insertion(+), 466 deletions(-) delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Application/Handlers/Scope/ScopeCreationHandler.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Application/Mappers/ScopeMapper.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeCreationScheme.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeDetailsScheme.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Application/Validators/Scope/ScopeCreationValidator.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Scopes.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Scope.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Domain/Collections/IScopeCollection.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Domain/Errors/ScopeErrors.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/Builders/ScopeFiltersBuilder.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/ScopeFilters.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Persistence/ScopesCollection.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Pipelines/ScopeFiltersStage.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Controllers/ScopesController.cs delete mode 100644 Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Conventions/ScopesConventions.cs delete mode 100644 Applications/Backend/Tests/Integration/Endpoints/ScopeEndpointTests.cs delete mode 100644 Packages/Federation.Sdk.Contracts/Source/Errors/ScopeErrors.cs diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Handlers/Scope/ScopeCreationHandler.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Handlers/Scope/ScopeCreationHandler.cs deleted file mode 100644 index d14bf18..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Handlers/Scope/ScopeCreationHandler.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace HttpsRichardy.Federation.Application.Handlers.Scope; - -public sealed class ScopeCreationHandler(IScopeCollection scopeCollection, IRealmCollection realmCollection, IRealmProvider realmProvider) : - IDispatchHandler> -{ - public async Task> HandleAsync(ScopeCreationScheme parameters, CancellationToken cancellation = default) - { - var realm = realmProvider.GetCurrentRealm(); - var filters = ScopeFilters.WithSpecifications() - .WithName(parameters.Name) - .Build(); - - var scopes = await scopeCollection.GetScopesAsync(filters, cancellation: cancellation); - var existingScope = scopes.FirstOrDefault(); - - if (existingScope is not null) - { - return Result.Failure(ScopeErrors.ScopeAlreadyExists); - } - - var scope = await scopeCollection.InsertAsync(ScopeMapper.AsScope(parameters, realm), cancellation: cancellation); - var response = ScopeMapper.AsResponse(scope); - - realm.Scopes.Add(scope); - - await realmCollection.UpdateAsync(realm, cancellation: cancellation); - - return Result.Success(response); - } -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Mappers/ScopeMapper.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Mappers/ScopeMapper.cs deleted file mode 100644 index f7bfcf1..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Mappers/ScopeMapper.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace HttpsRichardy.Federation.Application.Mappers; - -public static class ScopeMapper -{ - public static Scope AsScope(ScopeCreationScheme scope, Realm realm) => new() - { - Name = scope.Name, - Description = scope.Description, - RealmId = realm.Id, - IsGlobal = false - }; - - public static ScopeDetailsScheme AsResponse(Scope scope) => new() - { - Id = scope.Id, - Name = scope.Name, - Description = scope.Description, - }; -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeCreationScheme.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeCreationScheme.cs deleted file mode 100644 index 9e5bcb2..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeCreationScheme.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace HttpsRichardy.Federation.Application.Payloads.Scope; - -public sealed record ScopeCreationScheme : IDispatchable> -{ - public string Name { get; init; } = default!; - public string Description { get; init; } = default!; - - [JsonIgnore] - public bool IsGlobal { get; init; } -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeDetailsScheme.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeDetailsScheme.cs deleted file mode 100644 index b27a00a..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Payloads/Scope/ScopeDetailsScheme.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace HttpsRichardy.Federation.Application.Payloads.Scope; - -public sealed record ScopeDetailsScheme -{ - public string Id { get; init; } = default!; - public string Name { get; init; } = default!; - public string Description { get; init; } = default!; -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Usings.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Usings.cs index 154c608..e3eb8ba 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Usings.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Usings.cs @@ -21,7 +21,6 @@ global using HttpsRichardy.Federation.Application.Payloads.Permission; global using HttpsRichardy.Federation.Application.Payloads.Realm; global using HttpsRichardy.Federation.Application.Payloads.User; -global using HttpsRichardy.Federation.Application.Payloads.Scope; global using HttpsRichardy.Federation.Application.Payloads.Client; global using HttpsRichardy.Federation.Application.Payloads.Connect; diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Validators/Scope/ScopeCreationValidator.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Application/Validators/Scope/ScopeCreationValidator.cs deleted file mode 100644 index 2eb4770..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Application/Validators/Scope/ScopeCreationValidator.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace HttpsRichardy.Federation.Application.Validators.Scope; - -public sealed class ScopeCreationValidator : AbstractValidator -{ - public ScopeCreationValidator() - { - RuleFor(scope => scope.Name) - .NotEmpty() - .WithMessage("Scope name must not be empty.") - .MaximumLength(200) - .WithMessage("Scope name must be at most 200 characters long."); - - RuleFor(scope => scope.Description) - .MaximumLength(500) - .WithMessage("Scope description must be at most 500 characters long."); - } -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Permissions.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Permissions.cs index 30833bc..4489d3d 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Permissions.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Permissions.cs @@ -22,9 +22,4 @@ public static class Permissions public const string DeleteRealm = "federation.defaults.permissions.realm.delete"; public const string EditRealm = "federation.defaults.permissions.realm.update"; public const string ViewRealms = "federation.defaults.permissions.realm.view"; - - public const string CreateScope = "federation.defaults.permissions.scopes.create"; - public const string EditScope = "federation.defaults.permissions.scopes.update"; - public const string DeleteScope = "federation.defaults.permissions.scopes.delete"; - public const string ViewScopes = "federation.defaults.permissions.scopes.view"; } diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/RealmPermissions.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/RealmPermissions.cs index d99beb3..bf9cf67 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/RealmPermissions.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/RealmPermissions.cs @@ -19,11 +19,6 @@ public static class RealmPermissions Permissions.ViewPermissions, Permissions.EditPermission, Permissions.DeletePermission, - - Permissions.CreateScope, - Permissions.EditScope, - Permissions.DeleteGroup, - Permissions.ViewScopes ]; public static readonly HashSet SystemPermissions = @@ -47,11 +42,6 @@ public static class RealmPermissions Permissions.CreateRealm, Permissions.DeleteRealm, Permissions.EditRealm, - Permissions.ViewRealms, - - Permissions.CreateScope, - Permissions.EditScope, - Permissions.DeleteScope, - Permissions.ViewScopes + Permissions.ViewRealms ]; } diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Scopes.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Scopes.cs deleted file mode 100644 index ccd905a..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Common/Constants/Scopes.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace HttpsRichardy.Federation.Common.Constants; - -public static class Scopes -{ - public static class OpenID - { - public const string Name = "openid"; - public const string Description = "Authenticate using OpenID Connect"; - } - - public static class Profile - { - public const string Name = "profile"; - public const string Description = "Access basic profile information (name, family name, etc.)"; - } - - public static class Email - { - public const string Name = "email"; - public const string Description = "Access the user's email address"; - } - - public static class Address - { - public const string Name = "address"; - public const string Description = "Access the user's address information"; - } - - public static class Phone - { - public const string Name = "phone"; - public const string Description = "Access the user's phone number"; - } -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Realm.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Realm.cs index ce5032d..cad3228 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Realm.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Realm.cs @@ -10,5 +10,4 @@ public sealed class Realm : Aggregate public ICollection Permissions { get; set; } = []; public ICollection RedirectUris { get; set; } = []; - public ICollection Scopes { get; set; } = []; } diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Scope.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Scope.cs deleted file mode 100644 index 6c4a9c7..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Aggregates/Scope.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace HttpsRichardy.Federation.Domain.Aggregates; - -public sealed class Scope : Aggregate -{ - public string RealmId { get; set; } = default!; - public string Name { get; set; } = default!; - public string Description { get; set; } = default!; - public bool IsGlobal { get; set; } -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Collections/IScopeCollection.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Collections/IScopeCollection.cs deleted file mode 100644 index 23b490f..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Collections/IScopeCollection.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace HttpsRichardy.Federation.Domain.Collections; - -public interface IScopeCollection : IAggregateCollection -{ - public Task> GetScopesAsync( - ScopeFilters filters, - CancellationToken cancellation = default - ); - - public Task CountAsync( - ScopeFilters filters, - CancellationToken cancellation = default - ); -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Errors/ScopeErrors.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Errors/ScopeErrors.cs deleted file mode 100644 index 2fcf548..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Errors/ScopeErrors.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace HttpsRichardy.Federation.Domain.Errors; - -public static class ScopeErrors -{ - public static readonly Error ScopeAlreadyExists = new( - Code: "#ERROR-8D128", - Description: "The scope with the specified name already exists." - ); - - public static readonly Error ScopeDoesNotExists = new( - Code: "#ERROR-903F9", - Description: "The scope with the specified name does not exist." - ); -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/Builders/ScopeFiltersBuilder.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/Builders/ScopeFiltersBuilder.cs deleted file mode 100644 index 31693f0..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/Builders/ScopeFiltersBuilder.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace HttpsRichardy.Federation.Domain.Filtering.Builders; - -public sealed class ScopeFiltersBuilder : FiltersBuilderBase -{ - public ScopeFiltersBuilder WithName(string? name) - { - _filters.Name = name; - - return this; - } - - public ScopeFiltersBuilder WithRealmId(string? realmId) - { - _filters.RealmId = realmId; - - return this; - } - - public ScopeFiltersBuilder WithDescription(string? description) - { - _filters.Description = description; - - return this; - } -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/ScopeFilters.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/ScopeFilters.cs deleted file mode 100644 index b1de985..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Domain/Filtering/ScopeFilters.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace HttpsRichardy.Federation.Domain.Filtering; - -public sealed class ScopeFilters : Filters -{ - public string? RealmId { get; set; } - public string? Name { get; set; } - public string? Description { get; set; } - - public static ScopeFiltersBuilder WithSpecifications() => new(); -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/DataPersistenceExtension.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/DataPersistenceExtension.cs index f85e4e7..a5a9b13 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/DataPersistenceExtension.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/DataPersistenceExtension.cs @@ -18,7 +18,6 @@ public static void AddDataPersistence(this IServiceCollection services, ISetting services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/ValidationExtension.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/ValidationExtension.cs index e6ba5c1..c5dd27d 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/ValidationExtension.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Extensions/ValidationExtension.cs @@ -22,6 +22,5 @@ public static void AddValidators(this IServiceCollection services) services.AddTransient, AssignUserPermissionValidator>(); services.AddTransient, AssignRealmPermissionValidator>(); - services.AddTransient, ScopeCreationValidator>(); } } diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Usings.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Usings.cs index 9353404..f5010ba 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Usings.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure.IoC/Usings.cs @@ -20,7 +20,6 @@ global using HttpsRichardy.Federation.Application.Payloads.Permission; global using HttpsRichardy.Federation.Application.Payloads.Realm; global using HttpsRichardy.Federation.Application.Payloads.User; -global using HttpsRichardy.Federation.Application.Payloads.Scope; global using HttpsRichardy.Federation.Application.Validators.Permission; global using HttpsRichardy.Federation.Application.Validators.Group; @@ -28,7 +27,6 @@ global using HttpsRichardy.Federation.Application.Validators.Authorization; global using HttpsRichardy.Federation.Application.Validators.Realm; global using HttpsRichardy.Federation.Application.Validators.User; -global using HttpsRichardy.Federation.Application.Validators.Scope; global using HttpsRichardy.Federation.Application.Handlers.Identity; global using HttpsRichardy.Federation.Application.Policies; diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Collections.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Collections.cs index 90594c0..0c72913 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Collections.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Collections.cs @@ -7,6 +7,5 @@ public static class Collections public const string Groups = "federation.groups"; public const string Tokens = "federation.tokens"; public const string Realms = "federation.realms"; - public const string Scopes = "federation.scopes"; public const string Secrets = "federation.secrets"; } diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Documents.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Documents.cs index 21d10c1..a27484e 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Documents.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Constants/Documents.cs @@ -27,14 +27,6 @@ public static class Group public const string IsDeleted = nameof(Domain.Aggregates.Group.IsDeleted); } - public static class Scope - { - public const string Id = "_id"; - public const string RealmId = nameof(Domain.Aggregates.Scope.RealmId); - public const string Name = nameof(Domain.Aggregates.Scope.Name); - public const string IsDeleted = nameof(Domain.Aggregates.Group.IsDeleted); - } - public static class Realm { public const string Name = nameof(Domain.Aggregates.Realm.Name); diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Persistence/ScopesCollection.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Persistence/ScopesCollection.cs deleted file mode 100644 index e0aebfd..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Persistence/ScopesCollection.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace HttpsRichardy.Federation.Infrastructure.Persistence; - -public sealed class ScopesCollection(IMongoDatabase database) : - AggregateCollection(database, Collections.Scopes), - IScopeCollection -{ - public async Task> GetScopesAsync( - ScopeFilters filters, CancellationToken cancellation = default) - { - var pipeline = PipelineDefinitionBuilder - .For() - .As() - .FilterScopes(filters) - .Paginate(filters.Pagination) - .Sort(filters.Sort); - - var options = new AggregateOptions { AllowDiskUse = true }; - var aggregation = await _collection.AggregateAsync(pipeline, options, cancellation); - - var bsonDocuments = await aggregation.ToListAsync(cancellation); - var scopes = bsonDocuments - .Select(bson => BsonSerializer.Deserialize(bson)) - .ToList(); - - return scopes; - } - - public async Task CountAsync(ScopeFilters filters, CancellationToken cancellation = default) - { - var pipeline = PipelineDefinitionBuilder - .For() - .As() - .FilterScopes(filters) - .Count(); - - var aggregation = await _collection.AggregateAsync(pipeline, cancellationToken: cancellation); - var result = await aggregation.FirstOrDefaultAsync(cancellation); - - if (result == null) - { - return 0; - } - - return result.Count; - } -} \ No newline at end of file diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Pipelines/ScopeFiltersStage.cs b/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Pipelines/ScopeFiltersStage.cs deleted file mode 100644 index 7b8c8c9..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.Infrastructure/Pipelines/ScopeFiltersStage.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace HttpsRichardy.Federation.Infrastructure.Pipelines; - -public static class ScopeFiltersStage -{ - public static PipelineDefinition FilterScopes( - this PipelineDefinition pipeline, ScopeFilters filters) - { - var definitions = new List> - { - FilterDefinitions.MatchIfNotEmpty(Documents.Scope.Name, filters.Name), - FilterDefinitions.MatchIfNotEmpty(Documents.Scope.Id, filters.Id), - FilterDefinitions.MatchIfNotEmpty(Documents.Scope.RealmId, filters.RealmId), - FilterDefinitions.MatchBool(Documents.Scope.IsDeleted, filters.IsDeleted) - }; - - return pipeline.Match(Builders.Filter.And(definitions)); - } -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Controllers/ScopesController.cs b/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Controllers/ScopesController.cs deleted file mode 100644 index 8c5232b..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Controllers/ScopesController.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace HttpsRichardy.Federation.WebApi.Controllers; - -[ApiController] -[ApiConventionType(typeof(ScopesConventions))] -[RealmRequired] -[Route("api/v1/scopes")] -public sealed class ScopesController(IDispatcher dispatcher) : ControllerBase -{ - [HttpPost] - [Authorize(Roles = Permissions.CreateScope)] - [Stability(Stability.Experimental)] - public async Task CreateScopeAsync([FromBody] ScopeCreationScheme request, CancellationToken cancellation) - { - var result = await dispatcher.DispatchAsync(request, cancellation); - - return result switch - { - { IsSuccess: true } => - StatusCode(StatusCodes.Status201Created, result.Data), - - { IsFailure: true } when result.Error == ScopeErrors.ScopeAlreadyExists => - StatusCode(StatusCodes.Status409Conflict, result.Error), - }; - } -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Conventions/ScopesConventions.cs b/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Conventions/ScopesConventions.cs deleted file mode 100644 index 6d64be0..0000000 --- a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Conventions/ScopesConventions.cs +++ /dev/null @@ -1,11 +0,0 @@ -#pragma warning disable IDE0060 - -namespace HttpsRichardy.Federation.WebApi.Conventions; - -public static class ScopesConventions -{ - [ApiConventionNameMatch(ApiConventionNameMatchBehavior.Prefix)] - [ProducesResponseType(typeof(ScopeDetailsScheme), StatusCodes.Status201Created)] - [ProducesResponseType(typeof(Error), StatusCodes.Status409Conflict)] - public static void CreateScopeAsync(ScopeCreationScheme request, CancellationToken cancellation) { } -} diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Extensions/BootstrapperExtension.cs b/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Extensions/BootstrapperExtension.cs index 25297a5..b2d2ab4 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Extensions/BootstrapperExtension.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Extensions/BootstrapperExtension.cs @@ -9,7 +9,6 @@ public static async Task UseBootstrapperAsync(this IApplicationBuilder builder) var realmCollection = scope.ServiceProvider.GetRequiredService(); var userCollection = scope.ServiceProvider.GetRequiredService(); - var scopeRepository = scope.ServiceProvider.GetRequiredService(); var permissionCollection = scope.ServiceProvider.GetRequiredService(); var realmProvider = scope.ServiceProvider.GetRequiredService(); @@ -40,19 +39,9 @@ public static async Task UseBootstrapperAsync(this IApplicationBuilder builder) RealmId = defaultRealm.Id })]; - var scopes = new List - { - new() { Id = Identifier.Generate(), Name = Scopes.OpenID.Name, Description = Scopes.OpenID.Description, IsGlobal = true }, - new() { Id = Identifier.Generate(), Name = Scopes.Profile.Name, Description = Scopes.Profile.Description, IsGlobal = true }, - new() { Id = Identifier.Generate(), Name = Scopes.Email.Name, Description = Scopes.Email.Description, IsGlobal = true }, - new() { Id = Identifier.Generate(), Name = Scopes.Address.Name, Description = Scopes.Address.Description, IsGlobal = true }, - new() { Id = Identifier.Generate(), Name = Scopes.Phone.Name, Description = Scopes.Phone.Description, IsGlobal = true }, - }; - realmProvider.SetRealm(defaultRealm); await realmCollection.InsertAsync(defaultRealm); - await scopeRepository.InsertManyAsync(scopes); await permissionCollection.InsertManyAsync(defaultRealm.Permissions); var userFilters = UserFilters.WithSpecifications() diff --git a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Usings.cs b/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Usings.cs index 228c48a..a307eac 100644 --- a/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Usings.cs +++ b/Applications/Backend/Source/HttpsRichardy.Federation.WebApi/Usings.cs @@ -30,7 +30,6 @@ global using HttpsRichardy.Federation.Application.Payloads.Permission; global using HttpsRichardy.Federation.Application.Payloads.Realm; global using HttpsRichardy.Federation.Application.Payloads.User; -global using HttpsRichardy.Federation.Application.Payloads.Scope; global using HttpsRichardy.Federation.Application.Payloads.Connect; global using HttpsRichardy.Federation.Application.Payloads.Common; diff --git a/Applications/Backend/Tests/Integration/Endpoints/ScopeEndpointTests.cs b/Applications/Backend/Tests/Integration/Endpoints/ScopeEndpointTests.cs deleted file mode 100644 index 0cd2891..0000000 --- a/Applications/Backend/Tests/Integration/Endpoints/ScopeEndpointTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -namespace HttpsRichardy.Federation.TestSuite.Integration.Endpoints; - -public sealed class ScopesEndpointTests(IntegrationEnvironmentFixture factory) : - IClassFixture -{ - private readonly Fixture _fixture = new(); - - [Fact(DisplayName = "[e2e] - when POST /scopes with valid data should create a new scope successfully")] - public async Task WhenPostScopesWithValidData_ShouldCreateScopeSuccessfully() - { - /* arrange: prepare credentials and authenticate to get access token */ - var httpClient = factory.HttpClient.WithRealmHeader("master"); - var credentials = new AuthenticationCredentials - { - Username = "federation.testing.user", - Password = "federation.testing.password" - }; - - /* act: send POST request to authenticate endpoint */ - var response = await httpClient.PostAsJsonAsync("api/v1/identity/authenticate", credentials); - var authentication = await response.Content.ReadFromJsonAsync(); - - /* assert: ensure the authentication was successful and the result contains data */ - Assert.NotNull(authentication); - Assert.NotNull(authentication.AccessToken); - - httpClient.WithAuthorization(authentication.AccessToken); - - /* arrange: build payload for scope creation */ - var payload = _fixture.Build() - .With(scope => scope.Name, "federation.scopes.orders") - .Create(); - - var httpResponse = await httpClient.PostAsJsonAsync("api/v1/scopes", payload); - var content = await httpResponse.Content.ReadFromJsonAsync(); - - /* assert: ensure the response and content are not null */ - Assert.NotNull(httpResponse); - Assert.NotNull(content); - - /* assert: verify the response status code is 201 */ - Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode); - - /* assert: verify the returned content matches the sent payload */ - Assert.Equal(payload.Name, content.Name); - Assert.Equal(payload.Description, content.Description); - } - - [Fact(DisplayName = "[e2e] - when POST /scopes with duplicate name should return 409 Conflict")] - public async Task WhenPostScopesWithDuplicateName_ShouldReturnConflict() - { - /* arrange: prepare httpClient and authenticate */ - var httpClient = factory.HttpClient.WithRealmHeader("master"); - var credentials = new AuthenticationCredentials - { - Username = "federation.testing.user", - Password = "federation.testing.password" - }; - - /* act: send POST request to authenticate endpoint */ - var response = await httpClient.PostAsJsonAsync("api/v1/identity/authenticate", credentials); - var authentication = await response.Content.ReadFromJsonAsync(); - - /* assert: ensure authentication succeeded */ - Assert.NotNull(authentication); - Assert.NotNull(authentication.AccessToken); - - httpClient.WithAuthorization(authentication.AccessToken); - - /* arrange: build payload with a fixed scope name to simulate duplicate */ - var payload = _fixture.Build() - .With(scope => scope.Name, "federation.scopes.photos") - .Create(); - - /* act: send first POST request to create the scope (ensure it exists) */ - var httpResponse = await httpClient.PostAsJsonAsync("api/v1/scopes", payload); - - Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode); - - /* act: send second POST request with the same scope name to trigger conflict */ - var conflictResponse = await httpClient.PostAsJsonAsync("api/v1/scopes", payload); - - /* assert: ensure the response is 409 Conflict */ - Assert.Equal(HttpStatusCode.Conflict, conflictResponse.StatusCode); - } -} diff --git a/Applications/Backend/Tests/Usings.cs b/Applications/Backend/Tests/Usings.cs index dd2929e..37313aa 100644 --- a/Applications/Backend/Tests/Usings.cs +++ b/Applications/Backend/Tests/Usings.cs @@ -24,7 +24,6 @@ global using HttpsRichardy.Federation.Application.Payloads.Identity; global using HttpsRichardy.Federation.Application.Payloads.User; -global using HttpsRichardy.Federation.Application.Payloads.Scope; global using HttpsRichardy.Federation.Application.Payloads.Realm; global using HttpsRichardy.Federation.Application.Payloads.Permission; global using HttpsRichardy.Federation.Application.Payloads.Group; diff --git a/Applications/Proxy/Source/ocelot.json b/Applications/Proxy/Source/ocelot.json index 64c98cb..c0afd99 100644 --- a/Applications/Proxy/Source/ocelot.json +++ b/Applications/Proxy/Source/ocelot.json @@ -414,29 +414,6 @@ "TimeoutValue": 25000 } }, - { - "UpstreamHttpMethod": [ "POST" ], - "UpstreamPathTemplate": "/api/v1/scopes", - "DownstreamPathTemplate": "/api/v1/scopes", - "DownstreamScheme": "http", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 5286 - } - ], - "RateLimitOptions": { - "ClientIdHeader": "Client", - "EnableRateLimiting": true, - "Period": "1s", - "Limit": 5 - }, - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 5000, - "TimeoutValue": 25000 - } - }, { "UpstreamHttpMethod": [ "GET" ], "UpstreamPathTemplate": "/api/v1/users", diff --git a/Documentation/errors-reference.md b/Documentation/errors-reference.md index 7fdd14f..a145083 100644 --- a/Documentation/errors-reference.md +++ b/Documentation/errors-reference.md @@ -76,15 +76,6 @@ Federation Gateway is designed to provide clear, actionable error feedback for e --- -## SCOPE ERRORS - -| Code | Description | Cause | Resolution | -|----------------|--------------------------------------------------------------------|------------------------------------------------------------|----------------------------------------------| -| #ERROR-8D128 | The scope with the specified name already exists. | Scope name conflict. | Use a different scope name. | -| #ERROR-903F9 | The scope with the specified name does not exist. | Scope not found. | Check scope existence. | - ---- - ## USER ERRORS | Code | Description | Cause | Resolution | diff --git a/Packages/Federation.Sdk.Contracts/Source/Errors/ScopeErrors.cs b/Packages/Federation.Sdk.Contracts/Source/Errors/ScopeErrors.cs deleted file mode 100644 index c5cfda7..0000000 --- a/Packages/Federation.Sdk.Contracts/Source/Errors/ScopeErrors.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace HttpsRichardy.Federation.Sdk.Contracts.Errors; - -public static class ScopeErrors -{ - public static readonly Error ScopeAlreadyExists = new( - Code: "#ERROR-8D128", - Description: "The scope with the specified name already exists." - ); - - public static readonly Error ScopeDoesNotExists = new( - Code: "#ERROR-903F9", - Description: "The scope with the specified name does not exist." - ); -} \ No newline at end of file