-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ODS-6129] Improve Identities Service Extensibility (#953)
- Loading branch information
1 parent
4b5d6f2
commit 18635d6
Showing
17 changed files
with
292 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Application/EdFi.Ods.Features.IdentityManagement/Models/IIdentityServiceWithDefaultModels.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
namespace EdFi.Ods.Features.IdentityManagement.Models; | ||
|
||
/// <summary> | ||
/// Defines an interface that closes the generic types of the <see cref="IIdentityService{TCreateRequest,TSearchRequest,TSearchResponse,TIdentityResponse}" /> | ||
/// with the default Identities request/response models. | ||
/// </summary> | ||
public interface IIdentityServiceWithDefaultModels | ||
: IIdentityService<IdentityCreateRequest, IdentitySearchRequest, IdentitySearchResponse<IdentityResponse>, | ||
IdentityResponse> { }; |
13 changes: 13 additions & 0 deletions
13
...ion/EdFi.Ods.Features.IdentityManagement/Models/IIdentityServiceWithDefaultModelsAsync.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
namespace EdFi.Ods.Features.IdentityManagement.Models; | ||
|
||
/// <summary> | ||
/// Defines an interface that closes the generic types of the <see cref="IIdentityServiceAsync{TSearchRequest,TSearchResponse,TIdentityResponse}" /> | ||
/// with the default Identities request/response models. | ||
/// </summary> | ||
public interface IIdentityServiceWithDefaultModelsAsync | ||
: IIdentityServiceAsync<IdentitySearchRequest, IdentitySearchResponse<IdentityResponse>, IdentityResponse> { }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ public class IdentityResponseStatus<TResponse> | |
|
||
public IEnumerable<IdentityError> Errors { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
Application/EdFi.Ods.Features.IdentityManagement/Models/IdentitySearchResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
namespace EdFi.Ods.Features.IdentityManagement.Models | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
namespace EdFi.Ods.Features.IdentityManagement.Models | ||
{ | ||
public class IdentitySearchResponse | ||
public class IdentitySearchResponse<TIdentityResponse> | ||
where TIdentityResponse : IdentityResponse | ||
{ | ||
public SearchResponseStatus Status { get; set; } | ||
|
||
public IdentitySearchResponses[] SearchResponses { get; set; } | ||
public IdentitySearchResponses<TIdentityResponse>[] SearchResponses { get; set; } | ||
} | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
Application/EdFi.Ods.Features.IdentityManagement/Models/IdentitySearchResponses.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
namespace EdFi.Ods.Features.IdentityManagement.Models | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
namespace EdFi.Ods.Features.IdentityManagement.Models | ||
{ | ||
public class IdentitySearchResponses | ||
public class IdentitySearchResponses<TIdentityResponse> | ||
where TIdentityResponse : IdentityResponse | ||
{ | ||
public IdentityResponse[] Responses { get; set; } | ||
public TIdentityResponse[] Responses { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Application/EdFi.Ods.Features/IdentityManagement/IdentitiesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using EdFi.Ods.Features.Controllers; | ||
using EdFi.Ods.Features.IdentityManagement.Models; | ||
|
||
namespace EdFi.Ods.Features.IdentityManagement; | ||
|
||
/// <summary> | ||
/// Closes the Identities base controller around the default request/response model types to enable ASP.NET to find | ||
/// and instantiate it. | ||
/// </summary> | ||
/// <remarks>You can extend the default Identities request/response models by registering replacement services | ||
/// with different (derived) model types, and then providing a new controller that derives from the <see cref="IdentitiesControllerBase{TCreateRequest,TSearchRequest,TSearchResponse,TIdentityResponse}"/> | ||
/// class and closes the generic type definition so that ASP.NET will locate and instantiate it (instead of the | ||
/// out-of-the-box <see cref="IdentitiesController" />. | ||
/// </remarks> | ||
public class IdentitiesController | ||
: IdentitiesControllerBase<IdentityCreateRequest, IdentitySearchRequest, IdentitySearchResponse<IdentityResponse>, | ||
IdentityResponse> | ||
{ | ||
public IdentitiesController( | ||
IIdentityServiceWithDefaultModels identitySubsystem, | ||
IIdentityServiceWithDefaultModelsAsync identitySubsystemAsync) | ||
: base(identitySubsystem, identitySubsystemAsync) { } | ||
} |
57 changes: 57 additions & 0 deletions
57
Application/EdFi.Ods.Features/IdentityManagement/IdentitiesControllerOverrideConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Linq; | ||
using System.Reflection; | ||
using EdFi.Ods.Common; | ||
using EdFi.Ods.Features.Controllers; | ||
using Microsoft.AspNetCore.Mvc.ApplicationModels; | ||
|
||
namespace EdFi.Ods.Features.IdentityManagement; | ||
|
||
/// <summary> | ||
/// Implements a convention that looks for multiple controllers derived from the abstract <see cref="IdentitiesControllerBase{TCreateRequest, TSearchRequest, TSearchResponse, TIdentityResponse}" /> | ||
/// base controller class, and removes the <see cref="ControllerModel" /> entry for the default out-of-the-box <see cref="IdentitiesController" /> | ||
/// to prevent <see cref="AmbiguousMatchException" /> from occurring when resolving requests for identity management routes. | ||
/// </summary> | ||
public class IdentitiesControllerOverrideConvention : IApplicationModelConvention | ||
{ | ||
public void Apply(ApplicationModel application) | ||
{ | ||
// Find all Identities controllers (should only be either 1 or 2, if custom implementation provided) | ||
var identitiesControllers = application.Controllers.Where( | ||
m => | ||
{ | ||
// Eliminate most controllers using the namespace | ||
if (!m.ControllerType.Namespace.StartsWith(Namespaces.Api.Controllers)) | ||
{ | ||
// Identities controllers (should) inherit from the IdentitiesControllerBase class that is generic | ||
if (m.ControllerType.BaseType is { IsGenericType: true }) | ||
{ | ||
// Is it an identities controller? | ||
if (m.ControllerType.BaseType.GetGenericTypeDefinition() == typeof(IdentitiesControllerBase<,,,>)) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
}) | ||
.ToArray(); | ||
|
||
// Determine if we will have an ambiguous match, and remove the UnimplementedIdentitiesController from the model | ||
if (identitiesControllers.Length > 1) | ||
{ | ||
foreach (var controllerModel in identitiesControllers) | ||
{ | ||
if (controllerModel.ControllerType == typeof(IdentitiesController).GetTypeInfo()) | ||
{ | ||
application.Controllers.Remove(controllerModel); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.