diff --git a/SecurityService.Client/SecurityServiceClient.cs b/SecurityService.Client/SecurityServiceClient.cs index 87f10e6a..86e708a8 100644 --- a/SecurityService.Client/SecurityServiceClient.cs +++ b/SecurityService.Client/SecurityServiceClient.cs @@ -162,7 +162,7 @@ public async Task CreateRole(CreateRoleRequest createRoleRequest, catch(Exception ex) { // An exception has occurred, add some additional information to the message - Exception exception = new Exception($"Error creating role {createRoleRequest.Name}.", ex); + Exception exception = new Exception($"Error creating role {createRoleRequest.RoleName}.", ex); throw exception; } diff --git a/SecurityService.DataTransferObjects/Requests.cs b/SecurityService.DataTransferObjects/Requests.cs index d6ed1991..ad176790 100644 --- a/SecurityService.DataTransferObjects/Requests.cs +++ b/SecurityService.DataTransferObjects/Requests.cs @@ -1,170 +1,93 @@ -using System.Text.Json.Serialization; -using Newtonsoft.Json; - namespace SecurityService.DataTransferObjects; public sealed class CreateClientRequest { - [JsonProperty("client_id")] - [JsonPropertyName("client_id")] public string ClientId { get; set; } = string.Empty; - [JsonPropertyName("secret")] public string? Secret { get; set; } - [JsonProperty("client_name")] - [JsonPropertyName("client_name")] public string ClientName { get; set; } = string.Empty; - [JsonProperty("client_description")] - [JsonPropertyName("client_description")] public string? ClientDescription { get; set; } - [JsonProperty("allowed_scopes")] - [JsonPropertyName("allowed_scopes")] public List AllowedScopes { get; set; } = new(); - [JsonProperty("allowed_grant_types")] - [JsonPropertyName("allowed_grant_types")] public List AllowedGrantTypes { get; set; } = new(); - [JsonProperty("client_uri")] - [JsonPropertyName("client_uri")] public string? ClientUri { get; set; } - [JsonProperty("client_redirect_uris")] - [JsonPropertyName("client_redirect_uris")] public List ClientRedirectUris { get; set; } = new(); - [JsonProperty("client_post_logout_redirect_uris")] - [JsonPropertyName("client_post_logout_redirect_uris")] public List ClientPostLogoutRedirectUris { get; set; } = new(); - [JsonProperty("require_consent")] - [JsonPropertyName("require_consent")] public bool RequireConsent { get; set; } - [JsonProperty("allow_offline_access")] - [JsonPropertyName("allow_offline_access")] public bool AllowOfflineAccess { get; set; } } public sealed class CreateApiScopeRequest { - [JsonProperty("name")] - [JsonPropertyName("name")] public string Name { get; set; } = string.Empty; - [JsonProperty("display_name")] - [JsonPropertyName("display_name")] public string? DisplayName { get; set; } - [JsonProperty("description")] - [JsonPropertyName("description")] public string? Description { get; set; } } public sealed class CreateApiResourceRequest { - [JsonProperty("name")] - [JsonPropertyName("name")] public string Name { get; set; } = string.Empty; - [JsonProperty("display_name")] - [JsonPropertyName("display_name")] public string? DisplayName { get; set; } - [JsonProperty("description")] - [JsonPropertyName("description")] public string? Description { get; set; } - [JsonProperty("secret")] - [JsonPropertyName("secret")] public string? Secret { get; set; } - [JsonProperty("scopes")] - [JsonPropertyName("scopes")] public List Scopes { get; set; } = new(); - [JsonProperty("user_claims")] - [JsonPropertyName("user_claims")] public List UserClaims { get; set; } = new(); } public sealed class CreateIdentityResourceRequest { - [JsonProperty("name")] - [JsonPropertyName("name")] public string Name { get; set; } = string.Empty; - - [JsonProperty("display_name")] - [JsonPropertyName("display_name")] public string? DisplayName { get; set; } - [JsonProperty("description")] - [JsonPropertyName("description")] public string? Description { get; set; } - [JsonProperty("required")] - [JsonPropertyName("required")] public bool Required { get; set; } - [JsonProperty("emphasize")] - [JsonPropertyName("emphasize")] public bool Emphasize { get; set; } - [JsonProperty("show_in_discovery_document")] - [JsonPropertyName("show_in_discovery_document")] public bool ShowInDiscoveryDocument { get; set; } = true; - [JsonProperty("claims")] - [JsonPropertyName("claims")] public List Claims { get; set; } = new(); } public sealed class CreateRoleRequest { - [JsonProperty("role_name")] - [JsonPropertyName("role_name")] - public string Name { get; set; } = string.Empty; + public string RoleName { get; set; } = string.Empty; } public sealed class CreateUserRequest { - [JsonProperty("given_name")] - [JsonPropertyName("given_name")] public string? GivenName { get; set; } - [JsonProperty("middle_name")] - [JsonPropertyName("middle_name")] public string? MiddleName { get; set; } - [JsonProperty("family_name")] - [JsonPropertyName("family_name")] public string? FamilyName { get; set; } - [JsonProperty("user_name")] - [JsonPropertyName("user_name")] public string UserName { get; set; } = string.Empty; - [JsonProperty("password")] - [JsonPropertyName("password")] public string Password { get; set; } = string.Empty; - [JsonProperty("email_address")] - [JsonPropertyName("email_address")] public string? EmailAddress { get; set; } - [JsonProperty("phone_number")] - [JsonPropertyName("phone_number")] public string? PhoneNumber { get; set; } - [JsonProperty("claims")] - [JsonPropertyName("claims")] public Dictionary Claims { get; set; } = new(); - [JsonProperty("roles")] - [JsonPropertyName("roles")] public List Roles { get; set; } = new(); } diff --git a/SecurityService.DataTransferObjects/Responses.cs b/SecurityService.DataTransferObjects/Responses.cs index efc96fdd..ea5d1dbc 100644 --- a/SecurityService.DataTransferObjects/Responses.cs +++ b/SecurityService.DataTransferObjects/Responses.cs @@ -4,203 +4,102 @@ namespace SecurityService.DataTransferObjects; public sealed class ApiResourceResponse { - [JsonProperty("name")] - [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("display_name")] - [JsonPropertyName("display_name")] public string? DisplayName { get; set; } - [JsonProperty("description")] - [JsonPropertyName("description")] public string? Description { get; set; } - [JsonProperty("scopes")] - [JsonPropertyName("scopes")] public IReadOnlyCollection Scopes { get; set; } - [JsonProperty("user_claims")] - [JsonPropertyName("user_claims")] public IReadOnlyCollection UserClaims { get; set; } } public sealed record ApiScopeResponse { - [JsonProperty("name")] - [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("display_name")] - [JsonPropertyName("display_name")] public string? DisplayName { get; set; } - [JsonProperty("description")] - [JsonPropertyName("description")] public string? Description { get; set; } } public sealed record ClientResponse { - [JsonProperty("client_id")] - [JsonPropertyName("client_id")] public string ClientId { get; set; } - [JsonProperty("client_name")] - [JsonPropertyName("client_name")] + public string ClientName { get; set; } - [JsonProperty("client_description")] - [JsonPropertyName("client_description")] public string? Description { get; set; } - [JsonProperty("client_uri")] - [JsonPropertyName("client_uri")] public string? ClientUri { get; set; } - [JsonProperty("allowed_scopes")] - [JsonPropertyName("allowed_scopes")] public IReadOnlyCollection AllowedScopes { get; set; } - [JsonProperty("allowed_grant_types")] - [JsonPropertyName("allowed_grant_types")] public IReadOnlyCollection AllowedGrantTypes { get; set; } - [JsonProperty("client_redirect_uris")] - [JsonPropertyName("client_redirect_uris")] - public IReadOnlyCollection RedirectUris { get; set; } + public IReadOnlyCollection ClientRedirectUris { get; set; } - [JsonProperty("client_post_logout_redirect_uris")] - [JsonPropertyName("client_post_logout_redirect_uris")] - public IReadOnlyCollection PostLogoutRedirectUris { get; set; } + public IReadOnlyCollection ClientPostLogoutRedirectUris { get; set; } - [JsonProperty("require_consent")] - [JsonPropertyName("require_consent")] public bool RequireConsent { get; set; } - [JsonProperty("allow_offline_access")] - [JsonPropertyName("allow_offline_access")] public bool AllowOfflineAccess { get; set; } - [JsonProperty("client_type")] - [JsonPropertyName("client_type")] public string ClientType { get; set; } } public sealed record IdentityResourceResponse { - [JsonProperty("name")] - [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("display_name")] - [JsonPropertyName("display_name")] public string? DisplayName { get; set; } - [JsonProperty("description")] - [JsonPropertyName("description")] public string? Description { get; set; } - [JsonProperty("required")] - [JsonPropertyName("required")] public bool Required { get; set; } - [JsonProperty("emphasize")] - [JsonPropertyName("emphasize")] public bool Emphasize { get; set; } - [JsonProperty("show_in_discovery_document")] - [JsonPropertyName("show_in_discovery_document")] public bool ShowInDiscoveryDocument { get; set; } - [JsonProperty("claims")] - [JsonPropertyName("claims")] public IReadOnlyCollection Claims { get; set; } } public sealed record RoleResponse { - [JsonProperty("role_id")] - [JsonPropertyName("role_id")] public String RoleId { get; set; } - - [JsonProperty("role_name")] - [JsonPropertyName("role_name")] - public string Name { get; set; } + public string RoleName { get; set; } } public sealed record UserResponse { - [JsonProperty("user_id")] - [JsonPropertyName("user_id")] public String UserId { get; set; } - [JsonProperty("user_name")] - [JsonPropertyName("user_name")] public string UserName { get; set; } - [JsonProperty("email_address")] - [JsonPropertyName("email_address")] public string? EmailAddress { get; set; } - [JsonProperty("phone_number")] - [JsonPropertyName("phone_number")] public string? PhoneNumber { get; set; } - [JsonProperty("given_name")] - [JsonPropertyName("given_name")] public string? GivenName { get; set; } - [JsonProperty("middle_name")] - [JsonPropertyName("middle_name")] public string? MiddleName { get; set; } - [JsonProperty("family_name")] - [JsonPropertyName("family_name")] public string? FamilyName { get; set; } - [JsonProperty("claims")] - [JsonPropertyName("claims")] public IReadOnlyDictionary Claims{ get; set; } - [JsonProperty("roles")] - [JsonPropertyName("roles")] public IReadOnlyCollection Roles { get; set; } - [JsonProperty("registration_date_time")] - [JsonPropertyName("registration_date_time")] public DateTime RegistrationDateTime { get; set; } } public class TokenResponse { - /// - /// The access token - /// - /// The access token. public String AccessToken { get; private set; } - - /// - /// Gets the expires. - /// - /// The expires. public DateTimeOffset Expires { get; private set; } - - /// - /// The expires - /// - /// The expires in. public Int64 ExpiresIn { get; private set; } - - /// - /// Gets the issued. - /// - /// The issued. public DateTimeOffset Issued { get; private set; } - - /// - /// The refresh token - /// - /// The refresh token. public String RefreshToken { get; private set; } - public static TokenResponse Create(String token) { dynamic auth = JsonConvert.DeserializeObject(token); diff --git a/SecurityService.IntegrationTesting.Helpers/ReqnrollExtensions.cs b/SecurityService.IntegrationTesting.Helpers/ReqnrollExtensions.cs index 8e35c98f..b303a4f7 100644 --- a/SecurityService.IntegrationTesting.Helpers/ReqnrollExtensions.cs +++ b/SecurityService.IntegrationTesting.Helpers/ReqnrollExtensions.cs @@ -219,7 +219,7 @@ public static List ToCreateRoleRequests(this DataTableRows ta foreach (DataTableRow tableRow in tableRows){ CreateRoleRequest request = new CreateRoleRequest{ - Name = ReqnrollTableHelper.GetStringRowValue(tableRow, "Role Name") + RoleName = ReqnrollTableHelper.GetStringRowValue(tableRow, "Role Name") }; requests.Add(request); } @@ -232,7 +232,7 @@ public static List ToRoleResponses(this DataTableRows tableRows){ foreach (DataTableRow tableRow in tableRows){ RoleResponse roleDetails = new RoleResponse(){ - Name = ReqnrollTableHelper.GetStringRowValue(tableRow, "Role Name") + RoleName = ReqnrollTableHelper.GetStringRowValue(tableRow, "Role Name") }; requests.Add(roleDetails); } diff --git a/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs b/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs index 40f3e5d9..57497508 100644 --- a/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs +++ b/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs @@ -249,8 +249,8 @@ public async Task WhenIGetTheIdentityResourcesIdentityResourceDetailsAreReturned roles.IsSuccess.ShouldBeTrue(); foreach (CreateRoleRequest request in requests) { - RoleResponse r = roles.Data.Single(r => r.Name == request.Name); - roleList.Add((r.Name, r.RoleId)); + RoleResponse r = roles.Data.Single(r => r.RoleName == request.RoleName); + roleList.Add((r.RoleName, r.RoleId)); } return roleList; @@ -263,7 +263,7 @@ public async Task WhenIGetTheRoleWithNameTheRoleDetailsAreReturnedAsFollows(List RoleResponse roleDetails =getRoleResult.Data; RoleResponse expectedRecord = expectedDetails.Single(); - roleDetails.Name.ShouldBe(expectedRecord.Name); + roleDetails.RoleName.ShouldBe(expectedRecord.RoleName); } public async Task WhenIGetTheRolesRolesDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken) @@ -273,9 +273,9 @@ public async Task WhenIGetTheRolesRolesDetailsAreReturnedAsFollows(List? rolesList = getRolesResult.Data; foreach (RoleResponse expectedRecord in expectedDetails) { - RoleResponse? foundRecord = rolesList.SingleOrDefault(a => a.Name == expectedRecord.Name); + RoleResponse? foundRecord = rolesList.SingleOrDefault(a => a.RoleName == expectedRecord.RoleName); foundRecord.ShouldNotBeNull(); - foundRecord.Name.ShouldBe(expectedRecord.Name); + foundRecord.RoleName.ShouldBe(expectedRecord.RoleName); } } diff --git a/SecurityService.IntegrationTests/Common/DockerHelper.cs b/SecurityService.IntegrationTests/Common/DockerHelper.cs index 56ca172b..37e801f1 100644 --- a/SecurityService.IntegrationTests/Common/DockerHelper.cs +++ b/SecurityService.IntegrationTests/Common/DockerHelper.cs @@ -30,12 +30,12 @@ public class DockerHelper : Shared.IntegrationTesting.TestContainers.DockerHelpe String Serialise(Object arg) { - return StringSerialiser.Serialise(arg); + return StringSerialiser.Serialise(arg, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); } Object Deserialise(String arg, Type type) { - return StringSerialiser.DeserializeObject(arg, type); + return StringSerialiser.DeserializeObject(arg, type, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); } public async Task StartContainersForScenarioRun(String scenarioName, DockerServices dockerServices) diff --git a/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs b/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs index 35a47a2f..34ff1742 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs @@ -82,12 +82,12 @@ public override async Task CreateSubscriptions(){ String Serialise(Object arg) { - return StringSerialiser.Serialise(arg); + return StringSerialiser.Serialise(arg, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); } Object Deserialise(String arg, Type type) { - return StringSerialiser.DeserializeObject(arg, type); + return StringSerialiser.DeserializeObject(arg, type, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); } /// diff --git a/SecurityService.UnitTests/Configuration/JsonSerializerConfigurationTests.cs b/SecurityService.UnitTests/Configuration/JsonSerializerConfigurationTests.cs index 00c4bf31..2171fdd1 100644 --- a/SecurityService.UnitTests/Configuration/JsonSerializerConfigurationTests.cs +++ b/SecurityService.UnitTests/Configuration/JsonSerializerConfigurationTests.cs @@ -14,9 +14,7 @@ public void ConfigureMinimalApi_AppliesLegacyCompatibleDefaults() JsonSerializerConfiguration.ConfigureMinimalApi(options); - options.PropertyNamingPolicy.ShouldBe(JsonNamingPolicy.CamelCase); - options.DictionaryKeyPolicy.ShouldBe(JsonNamingPolicy.CamelCase); - options.ReferenceHandler.ShouldBe(ReferenceHandler.IgnoreCycles); + options.PropertyNamingPolicy.ShouldBe(JsonNamingPolicy.SnakeCaseLower); options.WriteIndented.ShouldBeTrue(); var payload = new SerializerPayload @@ -26,7 +24,7 @@ public void ConfigureMinimalApi_AppliesLegacyCompatibleDefaults() var json = System.Text.Json.JsonSerializer.Serialize(payload, options); - json.ShouldContain("createdDate"); + json.ShouldContain("created_date"); json.ShouldContain("Z"); } diff --git a/SecurityService/Configuration/JsonSerializerConfiguration.cs b/SecurityService/Configuration/JsonSerializerConfiguration.cs index a9ff4dab..7f51806e 100644 --- a/SecurityService/Configuration/JsonSerializerConfiguration.cs +++ b/SecurityService/Configuration/JsonSerializerConfiguration.cs @@ -1,3 +1,4 @@ +using Shared.Serialisation; using System.Text.Json; using System.Text.Json.Serialization; @@ -7,10 +8,11 @@ public static class JsonSerializerConfiguration { public static void ConfigureMinimalApi(JsonSerializerOptions serializerOptions) { - serializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; - serializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; - serializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; - serializerOptions.WriteIndented = true; + var defaultOptions = SystemTextJsonSerializer.GetDefaultJsonSerializerOptions(); + serializerOptions.PropertyNamingPolicy = defaultOptions.PropertyNamingPolicy; + serializerOptions.DictionaryKeyPolicy = defaultOptions.DictionaryKeyPolicy; + serializerOptions.ReferenceHandler = defaultOptions.ReferenceHandler; + serializerOptions.WriteIndented = defaultOptions.WriteIndented; serializerOptions.Converters.Add(new UtcDateTimeJsonConverter()); serializerOptions.Converters.Add(new NullableUtcDateTimeJsonConverter()); } diff --git a/SecurityService/Factories/ModelFactory.cs b/SecurityService/Factories/ModelFactory.cs index 7d9ecce4..3c52ed1a 100644 --- a/SecurityService/Factories/ModelFactory.cs +++ b/SecurityService/Factories/ModelFactory.cs @@ -32,7 +32,7 @@ public static RoleResponse ConvertFrom(RoleDetails model) { return null; } - return new RoleResponse { RoleId = model.RoleId, Name = model.Name }; + return new RoleResponse { RoleId = model.RoleId, RoleName = model.Name }; } public static List ConvertFrom(List model) { @@ -75,9 +75,9 @@ public static ClientResponse ConvertFrom(ClientDetails model) { AllowedGrantTypes = model.AllowedGrantTypes.ToList(), ClientName = model.ClientName, Description = model.Description, - PostLogoutRedirectUris = model.PostLogoutRedirectUris.ToList(), + ClientPostLogoutRedirectUris = model.PostLogoutRedirectUris.ToList(), RequireConsent = model.RequireConsent, - RedirectUris = model.RedirectUris.ToList(), + ClientRedirectUris = model.RedirectUris.ToList(), AllowOfflineAccess = model.AllowOfflineAccess, ClientType = model.ClientType, ClientUri = model.ClientUri diff --git a/SecurityService/Handlers/RoleHandler.cs b/SecurityService/Handlers/RoleHandler.cs index a0904284..11da65f9 100644 --- a/SecurityService/Handlers/RoleHandler.cs +++ b/SecurityService/Handlers/RoleHandler.cs @@ -11,7 +11,7 @@ namespace SecurityService.Handlers; public static class RoleHandler { public static async Task CreateRole(IMediator mediator, CreateRoleRequest request, CancellationToken cancellationToken) { - SecurityServiceCommands.CreateRoleCommand command = new(request.Name); + SecurityServiceCommands.CreateRoleCommand command = new(request.RoleName); Result result = await mediator.Send(command, cancellationToken);