diff --git a/FitConnect/FitConnect.csproj b/FitConnect/FitConnect.csproj index c131e6d93b08c118aba6c431caebe62b8a071bfd..c4077619411f1911413c68b3bb5023ffd09bc28a 100644 --- a/FitConnect/FitConnect.csproj +++ b/FitConnect/FitConnect.csproj @@ -11,28 +11,28 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="Autofac" Version="6.4.0"/> - <PackageReference Include="IdentityModel" Version="6.0.0"/> - <PackageReference Include="jose-jwt" Version="4.0.0"/> - <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0"/> - <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1"/> - <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.22.0"/> - <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.22.0"/> - <PackageReference Include="Newtonsoft.Json" Version="13.0.1"/> - <PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14"/> - <PackageReference Include="NJsonSchema" Version="10.7.2"/> - <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0"/> + <PackageReference Include="Autofac" Version="6.4.0" /> + <PackageReference Include="IdentityModel" Version="6.0.0" /> + <PackageReference Include="jose-jwt" Version="4.0.0" /> + <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> + <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" /> + <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.22.0" /> + <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.22.0" /> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + <PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" /> + <PackageReference Include="NJsonSchema" Version="10.7.2" /> + <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0" /> </ItemGroup> <ItemGroup> - <None Remove="metadata.schema.json"/> - <EmbeddedResource Include="metadata.schema.json"/> + <None Remove="metadata.schema.json" /> + <EmbeddedResource Include="metadata.schema.json" /> </ItemGroup> <ItemGroup> - <Compile Remove="FunctionalBaseClass.cs"/> - <Compile Remove="Models\OAuthAccessToken.cs"/> - <Compile Remove="DiContainer.cs"/> + <Compile Remove="FunctionalBaseClass.cs" /> + <Compile Remove="Models\OAuthAccessToken.cs" /> + <Compile Remove="DiContainer.cs" /> </ItemGroup> </Project> diff --git a/FitConnect/Services/Models/v1/Api/Problems.cs b/FitConnect/Services/Models/v1/Api/Problems.cs new file mode 100644 index 0000000000000000000000000000000000000000..13c5e5fccb37126c7f656b106dd6164f83e70587 --- /dev/null +++ b/FitConnect/Services/Models/v1/Api/Problems.cs @@ -0,0 +1,138 @@ +#nullable disable +using Newtonsoft.Json; + +namespace FitConnect.Models.v1.Api; + +public class Problems { + + public enum ProblemTypeEnum { + AttachmentMismatch, + MissingAttachments, + EncryptionIssue, + IncorrectAuthenticationTag, + InvalidEventLog, + MissingAuthenticationTag, + MissingSchema, + SchemaViolation, + SyntaxViolation, + UnsupportedSchema + } + + public enum ProblemInstanceEnum { + Submission, + Metadata, + } + + internal Problems() { + } + + public Problems(ProblemTypeEnum problemType, string title, string detail, ProblemInstanceEnum problemInstance) { + this.type = problemType switch { + ProblemTypeEnum.MissingAttachments => "https://schema.fitko.de/fit-connect/events/problems/missing-attachment", + ProblemTypeEnum.AttachmentMismatch => "https://schema.fitko.de/fit-connect/problems/attachments-mismatch", + ProblemTypeEnum.EncryptionIssue => "https://schema.fitko.de/fit-connect/problems/encryption-issue", + ProblemTypeEnum.IncorrectAuthenticationTag => "https://schema.fitko.de/fit-connect/problems/incorrect-authentication-tag", + ProblemTypeEnum.InvalidEventLog => "https://schema.fitko.de/fit-connect/problems/invalid-event-log", + ProblemTypeEnum.MissingAuthenticationTag => "https://schema.fitko.de/fit-connect/problems/missing-authentication-tag", + ProblemTypeEnum.MissingSchema => "https://schema.fitko.de/fit-connect/problems/missing-schema", + ProblemTypeEnum.SchemaViolation => "https://schema.fitko.de/fit-connect/problems/schema-violation", + ProblemTypeEnum.SyntaxViolation => "https://schema.fitko.de/fit-connect/problems/syntax-violation", + ProblemTypeEnum.UnsupportedSchema => "https://schema.fitko.de/fit-connect/problems/unsupported-schema", + _ => throw new ArgumentOutOfRangeException(nameof(problemType), problemType, null) + }; + + this.title = title; + this.detail = detail; + + this.instance = problemInstance switch { + ProblemInstanceEnum.Metadata => "metadata", + ProblemInstanceEnum.Submission => "submission", + _ => throw new ArgumentOutOfRangeException(nameof(problemInstance), problemType, null) + }; + } + + public static readonly Problems AttachmentsMismatch = + new Problems( + ProblemTypeEnum.AttachmentMismatch, + "Fehlerhafte Anlagen-Liste", + "Die Liste der Anlagen in Submission und Event-Log stimmt nicht überein.", + ProblemInstanceEnum.Submission); + + public static readonly Problems EncryptionIssue = + new Problems( + ProblemTypeEnum.EncryptionIssue, + "Entschlüsselungs-Fehler", + "Der Schlüssel {kid} ist nicht der zu diesem Zweck vorgesehene Schlüssel.", + ProblemInstanceEnum.Metadata + ); + + public static readonly Problems IncorrectAuthenticationTag = + new Problems( + ProblemTypeEnum.IncorrectAuthenticationTag, + "Authentication-Tag ungültig", + "Das Authentication-Tag des Metadatensatzes ist ungültig.", + ProblemInstanceEnum.Metadata + ); + public static readonly Problems InvalidEventLog = + new Problems ( + ProblemTypeEnum.InvalidEventLog, + "Inkonsistentes Event-Log", + "Das Event-Log ist inkonsistent, da es nicht genau ein Event 'submit-submission' enthält.", + ProblemInstanceEnum.Submission + ); + + public static readonly Problems MissingAuthenticationTag = + new Problems ( + ProblemTypeEnum.MissingAuthenticationTag, + "Fehlende Authentication-Tags", + "Das Event 'submit-submission' enthält keine Authentication-Tags.", + ProblemInstanceEnum.Submission + ); + + public static readonly Problems MissingSchema = new Problems( + ProblemTypeEnum.MissingSchema, + "Schema-Referenz fehlt", + "Die Schema-Referenz fehlt im Metadatensatz.", + ProblemInstanceEnum.Metadata + ); + public static readonly Problems SchemaViolation = new Problems ( + ProblemTypeEnum.SchemaViolation, + "Schema-Fehler", + "Der Metadatensatz ist nicht schema-valide.", + ProblemInstanceEnum.Metadata + ); + public static readonly Problems SyntaxViolation = new Problems( + ProblemTypeEnum.SyntaxViolation, + "Syntax-Fehler", + "Der Metadatensatz ist kein valides JSON.", + ProblemInstanceEnum.Metadata + ); + public static readonly Problems UnsupportedSchema = new Problems( + ProblemTypeEnum.UnsupportedSchema, + "Metadatenschema nicht unterstützt", + "Die angegebene Metadatenschema-URI ('$schema') ist keines der unterstützten Metadatenschemas.", + ProblemInstanceEnum.Metadata + ); + + + + + [JsonProperty("instance", NullValueHandling = NullValueHandling.Ignore)] + public string instance { get; set; } + + [JsonProperty("detail", NullValueHandling = NullValueHandling.Ignore)] + public string detail { get; set; } + + [JsonProperty("title", NullValueHandling = NullValueHandling.Ignore)] + public string title { get; set; } + + // [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + // public string? description { get; set; } + + [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + public string type { get; set; } + + // [JsonProperty("items", NullValueHandling = NullValueHandling.Ignore)] + // public Items? items { get; set; } + +} diff --git a/FitConnect/Services/Models/v1/Api/SecEventToken.cs b/FitConnect/Services/Models/v1/Api/SecEventToken.cs index b0bad061141c9bff7ab20ea35c3f57fff690ab7b..ac97161abfcc9d2d3cdea346392cba61bd7dd6ad 100644 --- a/FitConnect/Services/Models/v1/Api/SecEventToken.cs +++ b/FitConnect/Services/Models/v1/Api/SecEventToken.cs @@ -5,6 +5,9 @@ // using FitConnect.Models.v1.Api; // // var welcome = Welcome.FromJson(jsonString); + +using System.Diagnostics; + namespace FitConnect.Models.v1.Api { using System; @@ -200,86 +203,6 @@ namespace FitConnect.Models.v1.Api public Problems Problems { get; set; } } - public partial class Problems { - public static readonly Problems AttachmentsMissmatch = new Problems { - type = "https://schema.fitko.de/fit-connect/events/problems/attachments-mismatch", - title = "Fehlerhafte Anlagen-Liste", - detail = "Die Liste der Anlagen in Submission und Event-Log stimmt nicht überein.", - instance = "submission" - }; - - public static readonly Problems EncryptionIssue = new Problems{ - type = "https://schema.fitko.de/fit-connect/events/problems/encryption-issue", - title = "Entschlüsselungs-Fehler", - detail = "Der Schlüssel {kid} ist nicht der zu diesem Zweck vorgesehene Schlüssel.", - instance = "metadata" - }; - public static readonly Problems IncorrectAuthenticationTag = new Problems{ - type = "https://schema.fitko.de/fit-connect/events/problems/incorrect-authentication-tag", - title = "Authentication-Tag ungültig", - detail = "Das Authentication-Tag des Metadatensatzes ist ungültig.", - instance = "metadata" - }; - public static readonly Problems InvalidEventLog = new Problems { - type = "https://schema.fitko.de/fit-connect/events/problems/invalid-event-log", - title = "Inkonsistentes Event-Log", - detail = "Das Event-Log ist inkonsistent, da es nicht genau ein Event 'submit-submission' enthält.", - instance = "submission" - }; - public static readonly Problems MissingAuthenticationTag = new Problems { - type = "https://schema.fitko.de/fit-connect/events/problems/missing-authentication-tags", - title = "Fehlende Authentication-Tags", - detail = "Das Event 'submit-submission' enthält keine Authentication-Tags.", - instance = "submission" - }; - public static readonly Problems MissingSchema = new Problems{ - type = "https://schema.fitko.de/fit-connect/events/problems/missing-schema", - title = "Schema-Referenz fehlt", - detail = "Die Schema-Referenz fehlt im Metadatensatz.", - instance = "metadata" - }; - public static readonly Problems SchemaViolation = new Problems { - type = "https://schema.fitko.de/fit-connect/events/problems/schema-violation", - title = "Schema-Fehler", - detail = "Der Metadatensatz ist nicht schema-valide.", - instance = "metadata" - }; - public static readonly Problems SyntaxViolation = new Problems{ - type = "https://schema.fitko.de/fit-connect/events/problems/syntax-violation", - title = "Syntax-Fehler", - detail= "Der Metadatensatz ist kein valides JSON.", - instance= "metadata" - }; - public static readonly Problems UnsupportedSchema = new Problems{ - type = "https://schema.fitko.de/fit-connect/events/problems/unsupported-schema", - title = "Metadatenschema nicht unterstützt", - detail = "Die angegebene Metadatenschema-URI ('$schema') ist keines der unterstützten Metadatenschemas.", - instance = "metadata" - }; - - - - - [JsonProperty("instance", NullValueHandling = NullValueHandling.Ignore)] - public string instance { get; set; } - - [JsonProperty("detail", NullValueHandling = NullValueHandling.Ignore)] - public string detail { get; set; } - - [JsonProperty("title", NullValueHandling = NullValueHandling.Ignore)] - public string title { get; set; } - - // [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] - // public string? description { get; set; } - - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] - public string type { get; set; } - - // [JsonProperty("items", NullValueHandling = NullValueHandling.Ignore)] - // public Items? items { get; set; } - - } - public partial class Items { [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] diff --git a/FitConnect/Subscriber.cs b/FitConnect/Subscriber.cs index aa80bc9508c66249485f35694e0f7f934acb4834..006c797296fed2b7d8631d468f7ddd9038a25fb3 100644 --- a/FitConnect/Subscriber.cs +++ b/FitConnect/Subscriber.cs @@ -154,7 +154,7 @@ public class Subscriber : FitConnectClient, Dictionary<string, string> attachmentSignatures) { if (submission?.Attachments != null) { if (submission.Attachments.Count != attachmentSignatures.Count) { - RejectSubmission(submission, Problems.AttachmentsMissmatch); + RejectSubmission(submission, Problems.AttachmentsMismatch); throw new ArgumentException("Attachment count mismatch"); }