From 81204083fea397211808a8857336192a7bf7fb77 Mon Sep 17 00:00:00 2001 From: Marcus Carvalho Date: Sat, 22 Feb 2020 09:29:23 +0100 Subject: [PATCH 1/2] Added new aspnetcore startup project and moved hosting code out of the SCIM project --- .../Microsoft.SCIM.WebHostSample.csproj | 11 + Microsoft.SCIM.WebHostSample/Program.cs | 26 ++ .../Provider/InMemoryGroupProvider.cs | 277 ++++++++++++++++++ .../Provider/InMemoryProvider.cs | 127 ++++++++ .../Provider/InMemoryStorage.cs | 35 +++ .../Provider/InMemoryUserProvider.cs | 265 +++++++++++++++++ .../SampleServiceResources.Designer.cs | 109 +++++++ .../Resources/SampleServiceResources.resx | 135 +++++++++ Microsoft.SCIM.WebHostSample/Startup.cs | 82 ++++++ .../appsettings.Development.json | 9 + Microsoft.SCIM.WebHostSample/appsettings.json | 10 + Microsoft.SCIM.sln | 6 + .../Service/ServiceConstants.cs | 4 +- 13 files changed, 1094 insertions(+), 2 deletions(-) create mode 100644 Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj create mode 100644 Microsoft.SCIM.WebHostSample/Program.cs create mode 100644 Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs create mode 100644 Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs create mode 100644 Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs create mode 100644 Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs create mode 100644 Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs create mode 100644 Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.resx create mode 100644 Microsoft.SCIM.WebHostSample/Startup.cs create mode 100644 Microsoft.SCIM.WebHostSample/appsettings.Development.json create mode 100644 Microsoft.SCIM.WebHostSample/appsettings.json diff --git a/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj b/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj new file mode 100644 index 00000000..c279bee5 --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp3.1 + + + + + + + diff --git a/Microsoft.SCIM.WebHostSample/Program.cs b/Microsoft.SCIM.WebHostSample/Program.cs new file mode 100644 index 00000000..aa45c28b --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Microsoft.SCIM.WebHostSample +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs new file mode 100644 index 00000000..bf39fff2 --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs @@ -0,0 +1,277 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.SCIM.WebHostSample.Provider +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net; + using System.Threading.Tasks; + using System.Web.Http; + using Microsoft.SCIM; + using Microsoft.SCIM.WebHostSample.Resources; + + public class InMemoryGroupProvider : ProviderBase + { + private readonly InMemoryStorage storage; + + public InMemoryGroupProvider() + { + this.storage = InMemoryStorage.Instance; + } + + public override Task CreateAsync(Resource resource, string correlationIdentifier) + { + if (resource.Identifier != null) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + Core2Group group = resource as Core2Group; + + if (string.IsNullOrWhiteSpace(group.DisplayName)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + IEnumerable exisitingGroups = this.storage.Groups.Values; + if + ( + exisitingGroups.Any( + (Core2Group exisitingGroup) => + string.Equals(exisitingGroup.DisplayName, group.DisplayName, StringComparison.Ordinal)) + ) + { + throw new HttpResponseException(HttpStatusCode.Conflict); + } + + string resourceIdentifier = Guid.NewGuid().ToString(); + resource.Identifier = resourceIdentifier; + this.storage.Groups.Add(resourceIdentifier, group); + + return Task.FromResult(resource); + } + + public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) + { + if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + string identifier = resourceIdentifier.Identifier; + + if (this.storage.Groups.ContainsKey(identifier)) + { + this.storage.Groups.Remove(identifier); + } + + return Task.CompletedTask; + } + + public override Task QueryAsync(IQueryParameters parameters, string correlationIdentifier) + { + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + if (string.IsNullOrWhiteSpace(correlationIdentifier)) + { + throw new ArgumentNullException(nameof(correlationIdentifier)); + } + + if (null == parameters.AlternateFilters) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + Resource[] results; + IFilter queryFilter = parameters.AlternateFilters.SingleOrDefault(); + IEnumerable buffer = Enumerable.Empty(); + if (queryFilter == null) + { + buffer = this.storage.Groups.Values; + } + else + { + if (string.IsNullOrWhiteSpace(queryFilter.AttributePath)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + if (string.IsNullOrWhiteSpace(queryFilter.ComparisonValue)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + if (queryFilter.FilterOperator != ComparisonOperator.Equals) + { + throw new NotSupportedException(SampleServiceResources.UnsupportedComparisonOperator); + } + + if (queryFilter.AttributePath.Equals(AttributeNames.DisplayName)) + { + buffer = + this.storage.Groups.Values + .Where( + (Core2Group item) => + string.Equals( + item.DisplayName, + parameters.AlternateFilters.Single().ComparisonValue, + StringComparison.OrdinalIgnoreCase)); + } + else + { + throw new NotSupportedException(SampleServiceResources.UnsupportedFilterAttributeGroup); + } + } + + results = + buffer + .Select((Core2Group item) => + { + Core2Group bufferItem = + new Core2Group + { + DisplayName = item.DisplayName, + ExternalIdentifier = item.ExternalIdentifier, + Identifier = item.Identifier, + Members = item.Members, + Metadata = item.Metadata + }; + + if (parameters?.ExcludedAttributePaths?.Any( + (string excludedAttributes) => + excludedAttributes.Equals(AttributeNames.Members, StringComparison.OrdinalIgnoreCase)) + == true) + { + bufferItem.Members = null; + } + + return bufferItem; + }) + .Select((Core2Group item) => item as Resource) + .ToArray(); + + return Task.FromResult(results); + } + + public override Task ReplaceAsync(Resource resource, string correlationIdentifier) + { + if (resource.Identifier == null) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + Core2Group group = resource as Core2Group; + + if (string.IsNullOrWhiteSpace(group.DisplayName)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + IEnumerable exisitingGroups = this.storage.Groups.Values; + if + ( + exisitingGroups.Any( + (Core2Group exisitingUser) => + string.Equals(exisitingUser.DisplayName, group.DisplayName, StringComparison.Ordinal) && + !string.Equals(exisitingUser.Identifier, group.Identifier, StringComparison.OrdinalIgnoreCase)) + ) + { + throw new HttpResponseException(HttpStatusCode.Conflict); + } + + if (!this.storage.Groups.TryGetValue(group.Identifier, out Core2Group _)) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + this.storage.Groups[group.Identifier] = group; + Resource result = group as Resource; + return Task.FromResult(result); + } + + public override Task RetrieveAsync(IResourceRetrievalParameters parameters, string correlationIdentifier) + { + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + if (string.IsNullOrWhiteSpace(correlationIdentifier)) + { + throw new ArgumentNullException(nameof(correlationIdentifier)); + } + + if (string.IsNullOrEmpty(parameters?.ResourceIdentifier?.Identifier)) + { + throw new ArgumentNullException(nameof(parameters)); + } + + string identifier = parameters.ResourceIdentifier.Identifier; + + if (this.storage.Groups.ContainsKey(identifier)) + { + if (this.storage.Groups.TryGetValue(identifier, out Core2Group group)) + { + Resource result = group as Resource; + return Task.FromResult(result); + } + } + + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + public override Task UpdateAsync(IPatch patch, string correlationIdentifier) + { + if (null == patch) + { + throw new ArgumentNullException(nameof(patch)); + } + + if (null == patch.ResourceIdentifier) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); + } + + if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); + } + + if (null == patch.PatchRequest) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); + } + + PatchRequest2 patchRequest = + patch.PatchRequest as PatchRequest2; + + if (null == patchRequest) + { + string unsupportedPatchTypeName = patch.GetType().FullName; + throw new NotSupportedException(unsupportedPatchTypeName); + } + + if (this.storage.Groups.TryGetValue(patch.ResourceIdentifier.Identifier, out Core2Group group)) + { + group.Apply(patchRequest); + } + else + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + return Task.CompletedTask; + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs new file mode 100644 index 00000000..8ed0277a --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs @@ -0,0 +1,127 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.SCIM.WebHostSample.Provider +{ + using System; + using System.Threading.Tasks; + using Microsoft.SCIM; + + public class InMemoryProvider : ProviderBase + { + private readonly ProviderBase groupProvider; + private readonly ProviderBase userProvider; + + public InMemoryProvider() + { + this.groupProvider = new InMemoryGroupProvider(); + this.userProvider = new InMemoryUserProvider(); + } + + public override Task CreateAsync(Resource resource, string correlationIdentifier) + { + if (resource is Core2EnterpriseUser) + { + return this.userProvider.CreateAsync(resource, correlationIdentifier); + } + + if (resource is Core2Group) + { + return this.groupProvider.CreateAsync(resource, correlationIdentifier); + } + + throw new NotImplementedException(); + } + + public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) + { + if (resourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) + { + return this.userProvider.DeleteAsync(resourceIdentifier, correlationIdentifier); + } + + if (resourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) + { + return this.groupProvider.DeleteAsync(resourceIdentifier, correlationIdentifier); + } + + throw new NotImplementedException(); + } + + public override Task QueryAsync(IQueryParameters parameters, string correlationIdentifier) + { + if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) + { + return this.userProvider.QueryAsync(parameters, correlationIdentifier); + } + + if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) + { + return this.groupProvider.QueryAsync(parameters, correlationIdentifier); + } + + throw new NotImplementedException(); + } + + public override Task ReplaceAsync(Resource resource, string correlationIdentifier) + { + if (resource is Core2EnterpriseUser) + { + return this.userProvider.ReplaceAsync(resource, correlationIdentifier); + } + + if (resource is Core2Group) + { + return this.groupProvider.ReplaceAsync(resource, correlationIdentifier); + } + + throw new NotImplementedException(); + } + + public override Task RetrieveAsync(IResourceRetrievalParameters parameters, string correlationIdentifier) + { + if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) + { + return this.userProvider.RetrieveAsync(parameters, correlationIdentifier); + } + + if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) + { + return this.groupProvider.RetrieveAsync(parameters, correlationIdentifier); + } + + throw new NotImplementedException(); + } + + public override Task UpdateAsync(IPatch patch, string correlationIdentifier) + { + if (patch == null) + { + throw new ArgumentNullException(nameof(patch)); + } + + if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) + { + throw new ArgumentException(nameof(patch)); + } + + if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.SchemaIdentifier)) + { + throw new ArgumentException(nameof(patch)); + } + + if (patch.ResourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) + { + return this.userProvider.UpdateAsync(patch, correlationIdentifier); + } + + if (patch.ResourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) + { + return this.groupProvider.UpdateAsync(patch, correlationIdentifier); + } + + throw new NotImplementedException(); + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs new file mode 100644 index 00000000..73096b0c --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.SCIM.WebHostSample.Provider +{ + using System; + using System.Collections.Generic; + using Microsoft.SCIM; + + public class InMemoryStorage + { + internal readonly IDictionary Groups; + internal readonly IDictionary Users; + + private InMemoryStorage() + { + this.Groups = new Dictionary(); + this.Users = new Dictionary(); + } + + private static readonly Lazy InstanceValue = + new Lazy( + () => + new InMemoryStorage()); + + public static InMemoryStorage Instance + { + get + { + return InMemoryStorage.InstanceValue.Value; + } + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs new file mode 100644 index 00000000..306158af --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs @@ -0,0 +1,265 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.SCIM.WebHostSample.Provider +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net; + using System.Threading.Tasks; + using System.Web.Http; + using Microsoft.SCIM; + using Microsoft.SCIM.WebHostSample.Resources; + + public class InMemoryUserProvider : ProviderBase + { + private readonly InMemoryStorage storage; + + public InMemoryUserProvider() + { + this.storage = InMemoryStorage.Instance; + } + + public override Task CreateAsync(Resource resource, string correlationIdentifier) + { + if (resource.Identifier != null) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + Core2EnterpriseUser user = resource as Core2EnterpriseUser; + if (string.IsNullOrWhiteSpace(user.UserName)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + IEnumerable exisitingUsers = this.storage.Users.Values; + if + ( + exisitingUsers.Any( + (Core2EnterpriseUser exisitingUser) => + string.Equals(exisitingUser.UserName, user.UserName, StringComparison.Ordinal)) + ) + { + throw new HttpResponseException(HttpStatusCode.Conflict); + } + + string resourceIdentifier = Guid.NewGuid().ToString(); + resource.Identifier = resourceIdentifier; + this.storage.Users.Add(resourceIdentifier, user); + + return Task.FromResult(resource); + } + + public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) + { + if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + string identifier = resourceIdentifier.Identifier; + + if (this.storage.Users.ContainsKey(identifier)) + { + this.storage.Users.Remove(identifier); + } + + return Task.CompletedTask; + } + + public override Task QueryAsync(IQueryParameters parameters, string correlationIdentifier) + { + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + if (string.IsNullOrWhiteSpace(correlationIdentifier)) + { + throw new ArgumentNullException(nameof(correlationIdentifier)); + } + + if (null == parameters.AlternateFilters) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + Resource[] results; + IFilter queryFilter = parameters.AlternateFilters.SingleOrDefault(); + if (queryFilter == null) + { + IEnumerable allUsers = this.storage.Users.Values; + results = + allUsers.Select((Core2EnterpriseUser user) => user as Resource).ToArray(); + + return Task.FromResult(results); + } + + if (string.IsNullOrWhiteSpace(queryFilter.AttributePath)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + if (string.IsNullOrWhiteSpace(queryFilter.ComparisonValue)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); + } + + if (queryFilter.FilterOperator != ComparisonOperator.Equals) + { + throw new NotSupportedException(SampleServiceResources.UnsupportedComparisonOperator); + } + + if (queryFilter.AttributePath.Equals(AttributeNames.UserName)) + { + IEnumerable allUsers = this.storage.Users.Values; + results = + allUsers.Where( + (Core2EnterpriseUser item) => + string.Equals( + item.UserName, + parameters.AlternateFilters.Single().ComparisonValue, + StringComparison.OrdinalIgnoreCase)) + .Select((Core2EnterpriseUser user) => user as Resource).ToArray(); + + return Task.FromResult(results); + } + + if (queryFilter.AttributePath.Equals(AttributeNames.ExternalIdentifier)) + { + IEnumerable allUsers = this.storage.Users.Values; + results = + allUsers.Where( + (Core2EnterpriseUser item) => + string.Equals( + item.ExternalIdentifier, + parameters.AlternateFilters.Single().ComparisonValue, + StringComparison.OrdinalIgnoreCase)) + .Select((Core2EnterpriseUser user) => user as Resource).ToArray(); + + return Task.FromResult(results); + } + + throw new NotSupportedException(SampleServiceResources.UnsupportedFilterAttributeUser); + } + + public override Task ReplaceAsync(Resource resource, string correlationIdentifier) + { + if (resource.Identifier == null) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + Core2EnterpriseUser user = resource as Core2EnterpriseUser; + + if (string.IsNullOrWhiteSpace(user.UserName)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + IEnumerable exisitingUsers = this.storage.Users.Values; + if + ( + exisitingUsers.Any( + (Core2EnterpriseUser exisitingUser) => + string.Equals(exisitingUser.UserName, user.UserName, StringComparison.Ordinal) && + !string.Equals(exisitingUser.Identifier, user.Identifier, StringComparison.OrdinalIgnoreCase)) + ) + { + throw new HttpResponseException(HttpStatusCode.Conflict); + } + + if (!this.storage.Users.TryGetValue(user.Identifier, out Core2EnterpriseUser _)) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + this.storage.Users[user.Identifier] = user; + Resource result = user as Resource; + return Task.FromResult(result); + } + + public override Task RetrieveAsync(IResourceRetrievalParameters parameters, string correlationIdentifier) + { + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + if (string.IsNullOrWhiteSpace(correlationIdentifier)) + { + throw new ArgumentNullException(nameof(correlationIdentifier)); + } + + if (string.IsNullOrEmpty(parameters?.ResourceIdentifier?.Identifier)) + { + throw new ArgumentNullException(nameof(parameters)); + } + + Resource result = null; + string identifier = parameters.ResourceIdentifier.Identifier; + + if (this.storage.Users.ContainsKey(identifier)) + { + if (this.storage.Users.TryGetValue(identifier, out Core2EnterpriseUser user)) + { + result = user as Resource; + return Task.FromResult(result); + } + } + + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + public override Task UpdateAsync(IPatch patch, string correlationIdentifier) + { + if (null == patch) + { + throw new ArgumentNullException(nameof(patch)); + } + + if (null == patch.ResourceIdentifier) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); + } + + if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); + } + + if (null == patch.PatchRequest) + { + throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); + } + + PatchRequest2 patchRequest = + patch.PatchRequest as PatchRequest2; + + if (null == patchRequest) + { + string unsupportedPatchTypeName = patch.GetType().FullName; + throw new NotSupportedException(unsupportedPatchTypeName); + } + + if (this.storage.Users.TryGetValue(patch.ResourceIdentifier.Identifier, out Core2EnterpriseUser user)) + { + user.Apply(patchRequest); + } + else + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + return Task.CompletedTask; + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs new file mode 100644 index 00000000..ee68a48c --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.SCIM.WebHostSample.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class SampleServiceResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal SampleServiceResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.SystemForCrossDomainIdentityManagement.Sample.Properties.SampleServiceR" + + "esources", typeof(SampleServiceResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Invalid parameters.. + /// + internal static string ExceptionInvalidParameters { + get { + return ResourceManager.GetString("ExceptionInvalidParameters", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invalid patch.. + /// + internal static string ExceptionInvalidPatch { + get { + return ResourceManager.GetString("ExceptionInvalidPatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The comparison operator is not supported. The only supported operator is 'eq'.. + /// + internal static string UnsupportedComparisonOperator { + get { + return ResourceManager.GetString("UnsupportedComparisonOperator", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The filter attribute is not supported. The supported filter attributes are displayName and externalId.. + /// + internal static string UnsupportedFilterAttributeGroup { + get { + return ResourceManager.GetString("UnsupportedFilterAttributeGroup", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The filter attribute is not supported. The supported filter attributes are userName and externalId.. + /// + internal static string UnsupportedFilterAttributeUser { + get { + return ResourceManager.GetString("UnsupportedFilterAttributeUser", resourceCulture); + } + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.resx b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.resx new file mode 100644 index 00000000..3ec37902 --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Invalid parameters. + + + Invalid patch. + + + The comparison operator is not supported. The only supported operator is 'eq'. + + + The filter attribute is not supported. The supported filter attributes are displayName and externalId. + + + The filter attribute is not supported. The supported filter attributes are userName and externalId. + + \ No newline at end of file diff --git a/Microsoft.SCIM.WebHostSample/Startup.cs b/Microsoft.SCIM.WebHostSample/Startup.cs new file mode 100644 index 00000000..e816dc55 --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Startup.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.IdentityModel.Tokens; +using Microsoft.SCIM.WebHostSample.Provider; + +namespace Microsoft.SCIM.WebHostSample +{ + public class Startup + { + public IMonitor MonitoringBehavior { get; set; } + public IProvider ProviderBehavior { get; set; } + + public Startup() + { + this.MonitoringBehavior = new ConsoleMonitor(); + this.ProviderBehavior = new InMemoryProvider(); + } + + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }) + .AddJwtBearer(options => + { + options.TokenValidationParameters = + new TokenValidationParameters + { + ValidateIssuer = false, + ValidateAudience = false, + ValidateLifetime = false, + ValidateIssuerSigningKey = false, + ValidIssuer = ServiceConstants.TokenIssuer, + ValidAudience = ServiceConstants.TokenAudience, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer)) + }; + }); + + services.AddControllers().AddNewtonsoftJson(); + + services.AddSingleton(typeof(IProvider), this.ProviderBehavior); + services.AddSingleton(typeof(IMonitor), this.MonitoringBehavior); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHsts(); + + app.UseRouting(); + app.UseHttpsRedirection(); + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints( + (IEndpointRouteBuilder endpoints) => + { + endpoints.MapDefaultControllerRoute(); + }); + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/appsettings.Development.json b/Microsoft.SCIM.WebHostSample/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/appsettings.json b/Microsoft.SCIM.WebHostSample/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Microsoft.SCIM.sln b/Microsoft.SCIM.sln index b29370a0..a0dcf760 100644 --- a/Microsoft.SCIM.sln +++ b/Microsoft.SCIM.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM", "Microsoft EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM.Sample", "Microsoft.SCIM.Sample\Microsoft.SCIM.Sample.csproj", "{06220587-471C-4AB0-BBB6-F1D9E35DBDDF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.SCIM.WebHostSample", "Microsoft.SCIM.WebHostSample\Microsoft.SCIM.WebHostSample.csproj", "{238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Debug|Any CPU.Build.0 = Debug|Any CPU {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Release|Any CPU.ActiveCfg = Release|Any CPU {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Release|Any CPU.Build.0 = Release|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs index 2fe8ac7b..44147915 100644 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs +++ b/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs @@ -20,7 +20,7 @@ public static class ServiceConstants public const string SeparatorSegments = "/"; - internal const string TokenAudience = "Microsoft.Security.Bearer"; - internal const string TokenIssuer = "Microsoft.Security.Bearer"; + public const string TokenAudience = "Microsoft.Security.Bearer"; + public const string TokenIssuer = "Microsoft.Security.Bearer"; } } \ No newline at end of file From c9009ab365fcdfa9d852207a6f690c51806edbc8 Mon Sep 17 00:00:00 2001 From: Marcus Carvalho Date: Sun, 23 Feb 2020 16:06:20 +0100 Subject: [PATCH 2/2] code cleanup --- Microsoft.SCIM.Sample/App.config | 74 ----- .../InMemoryGroupProvider.cs | 277 ------------------ Microsoft.SCIM.Sample/InMemoryProvider.cs | 127 -------- Microsoft.SCIM.Sample/InMemoryStorage.cs | 35 --- Microsoft.SCIM.Sample/InMemoryUserProvider.cs | 265 ----------------- .../Microsoft.SCIM.Sample.csproj | 16 - .../SampleServiceResources.Designer.cs | 109 ------- .../Properties/SampleServiceResources.resx | 135 --------- Microsoft.SCIM.Sample/Startup.cs | 37 --- .../.config/dotnet-tools.json | 12 + Microsoft.SCIM.sln | 8 +- .../Service/Service.cs | 76 ----- .../Service/WebApplicationStarter.cs | 67 ----- 13 files changed, 13 insertions(+), 1225 deletions(-) delete mode 100644 Microsoft.SCIM.Sample/App.config delete mode 100644 Microsoft.SCIM.Sample/InMemoryGroupProvider.cs delete mode 100644 Microsoft.SCIM.Sample/InMemoryProvider.cs delete mode 100644 Microsoft.SCIM.Sample/InMemoryStorage.cs delete mode 100644 Microsoft.SCIM.Sample/InMemoryUserProvider.cs delete mode 100644 Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj delete mode 100644 Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs delete mode 100644 Microsoft.SCIM.Sample/Properties/SampleServiceResources.resx delete mode 100644 Microsoft.SCIM.Sample/Startup.cs create mode 100644 Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json delete mode 100644 Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs delete mode 100644 Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs diff --git a/Microsoft.SCIM.Sample/App.config b/Microsoft.SCIM.Sample/App.config deleted file mode 100644 index dade2946..00000000 --- a/Microsoft.SCIM.Sample/App.config +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Microsoft.SCIM.Sample/InMemoryGroupProvider.cs b/Microsoft.SCIM.Sample/InMemoryGroupProvider.cs deleted file mode 100644 index c80c1135..00000000 --- a/Microsoft.SCIM.Sample/InMemoryGroupProvider.cs +++ /dev/null @@ -1,277 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.SCIM.Sample -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net; - using System.Threading.Tasks; - using System.Web.Http; - using Microsoft.SCIM; - using Microsoft.SCIM.Sample.Properties; - - public class InMemoryGroupProvider : ProviderBase - { - private readonly InMemoryStorage storage; - - public InMemoryGroupProvider() - { - this.storage = InMemoryStorage.Instance; - } - - public override Task CreateAsync(Resource resource, string correlationIdentifier) - { - if (resource.Identifier != null) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - Core2Group group = resource as Core2Group; - - if (string.IsNullOrWhiteSpace(group.DisplayName)) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - IEnumerable exisitingGroups = this.storage.Groups.Values; - if - ( - exisitingGroups.Any( - (Core2Group exisitingGroup) => - string.Equals(exisitingGroup.DisplayName, group.DisplayName, StringComparison.Ordinal)) - ) - { - throw new HttpResponseException(HttpStatusCode.Conflict); - } - - string resourceIdentifier = Guid.NewGuid().ToString(); - resource.Identifier = resourceIdentifier; - this.storage.Groups.Add(resourceIdentifier, group); - - return Task.FromResult(resource); - } - - public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) - { - if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier)) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - string identifier = resourceIdentifier.Identifier; - - if (this.storage.Groups.ContainsKey(identifier)) - { - this.storage.Groups.Remove(identifier); - } - - return Task.CompletedTask; - } - - public override Task QueryAsync(IQueryParameters parameters, string correlationIdentifier) - { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - - if (string.IsNullOrWhiteSpace(correlationIdentifier)) - { - throw new ArgumentNullException(nameof(correlationIdentifier)); - } - - if (null == parameters.AlternateFilters) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - Resource[] results; - IFilter queryFilter = parameters.AlternateFilters.SingleOrDefault(); - IEnumerable buffer = Enumerable.Empty(); - if (queryFilter == null) - { - buffer = this.storage.Groups.Values; - } - else - { - if (string.IsNullOrWhiteSpace(queryFilter.AttributePath)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - if (string.IsNullOrWhiteSpace(queryFilter.ComparisonValue)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - if (queryFilter.FilterOperator != ComparisonOperator.Equals) - { - throw new NotSupportedException(SampleServiceResources.UnsupportedComparisonOperator); - } - - if (queryFilter.AttributePath.Equals(AttributeNames.DisplayName)) - { - buffer = - this.storage.Groups.Values - .Where( - (Core2Group item) => - string.Equals( - item.DisplayName, - parameters.AlternateFilters.Single().ComparisonValue, - StringComparison.OrdinalIgnoreCase)); - } - else - { - throw new NotSupportedException(SampleServiceResources.UnsupportedFilterAttributeGroup); - } - } - - results = - buffer - .Select((Core2Group item) => - { - Core2Group bufferItem = - new Core2Group - { - DisplayName = item.DisplayName, - ExternalIdentifier = item.ExternalIdentifier, - Identifier = item.Identifier, - Members = item.Members, - Metadata = item.Metadata - }; - - if (parameters?.ExcludedAttributePaths?.Any( - (string excludedAttributes) => - excludedAttributes.Equals(AttributeNames.Members, StringComparison.OrdinalIgnoreCase)) - == true) - { - bufferItem.Members = null; - } - - return bufferItem; - }) - .Select((Core2Group item) => item as Resource) - .ToArray(); - - return Task.FromResult(results); - } - - public override Task ReplaceAsync(Resource resource, string correlationIdentifier) - { - if (resource.Identifier == null) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - Core2Group group = resource as Core2Group; - - if (string.IsNullOrWhiteSpace(group.DisplayName)) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - IEnumerable exisitingGroups = this.storage.Groups.Values; - if - ( - exisitingGroups.Any( - (Core2Group exisitingUser) => - string.Equals(exisitingUser.DisplayName, group.DisplayName, StringComparison.Ordinal) && - !string.Equals(exisitingUser.Identifier, group.Identifier, StringComparison.OrdinalIgnoreCase)) - ) - { - throw new HttpResponseException(HttpStatusCode.Conflict); - } - - if (!this.storage.Groups.TryGetValue(group.Identifier, out Core2Group _)) - { - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - this.storage.Groups[group.Identifier] = group; - Resource result = group as Resource; - return Task.FromResult(result); - } - - public override Task RetrieveAsync(IResourceRetrievalParameters parameters, string correlationIdentifier) - { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - - if (string.IsNullOrWhiteSpace(correlationIdentifier)) - { - throw new ArgumentNullException(nameof(correlationIdentifier)); - } - - if (string.IsNullOrEmpty(parameters?.ResourceIdentifier?.Identifier)) - { - throw new ArgumentNullException(nameof(parameters)); - } - - string identifier = parameters.ResourceIdentifier.Identifier; - - if (this.storage.Groups.ContainsKey(identifier)) - { - if (this.storage.Groups.TryGetValue(identifier, out Core2Group group)) - { - Resource result = group as Resource; - return Task.FromResult(result); - } - } - - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - public override Task UpdateAsync(IPatch patch, string correlationIdentifier) - { - if (null == patch) - { - throw new ArgumentNullException(nameof(patch)); - } - - if (null == patch.ResourceIdentifier) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); - } - - if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); - } - - if (null == patch.PatchRequest) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); - } - - PatchRequest2 patchRequest = - patch.PatchRequest as PatchRequest2; - - if (null == patchRequest) - { - string unsupportedPatchTypeName = patch.GetType().FullName; - throw new NotSupportedException(unsupportedPatchTypeName); - } - - if (this.storage.Groups.TryGetValue(patch.ResourceIdentifier.Identifier, out Core2Group group)) - { - group.Apply(patchRequest); - } - else - { - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - return Task.CompletedTask; - } - } -} diff --git a/Microsoft.SCIM.Sample/InMemoryProvider.cs b/Microsoft.SCIM.Sample/InMemoryProvider.cs deleted file mode 100644 index 0ac17053..00000000 --- a/Microsoft.SCIM.Sample/InMemoryProvider.cs +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.SCIM.Sample -{ - using System; - using System.Threading.Tasks; - using Microsoft.SCIM; - - public class InMemoryProvider : ProviderBase - { - private readonly ProviderBase groupProvider; - private readonly ProviderBase userProvider; - - public InMemoryProvider() - { - this.groupProvider = new InMemoryGroupProvider(); - this.userProvider = new InMemoryUserProvider(); - } - - public override Task CreateAsync(Resource resource, string correlationIdentifier) - { - if (resource is Core2EnterpriseUser) - { - return this.userProvider.CreateAsync(resource, correlationIdentifier); - } - - if (resource is Core2Group) - { - return this.groupProvider.CreateAsync(resource, correlationIdentifier); - } - - throw new NotImplementedException(); - } - - public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) - { - if (resourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) - { - return this.userProvider.DeleteAsync(resourceIdentifier, correlationIdentifier); - } - - if (resourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) - { - return this.groupProvider.DeleteAsync(resourceIdentifier, correlationIdentifier); - } - - throw new NotImplementedException(); - } - - public override Task QueryAsync(IQueryParameters parameters, string correlationIdentifier) - { - if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) - { - return this.userProvider.QueryAsync(parameters, correlationIdentifier); - } - - if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) - { - return this.groupProvider.QueryAsync(parameters, correlationIdentifier); - } - - throw new NotImplementedException(); - } - - public override Task ReplaceAsync(Resource resource, string correlationIdentifier) - { - if (resource is Core2EnterpriseUser) - { - return this.userProvider.ReplaceAsync(resource, correlationIdentifier); - } - - if (resource is Core2Group) - { - return this.groupProvider.ReplaceAsync(resource, correlationIdentifier); - } - - throw new NotImplementedException(); - } - - public override Task RetrieveAsync(IResourceRetrievalParameters parameters, string correlationIdentifier) - { - if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) - { - return this.userProvider.RetrieveAsync(parameters, correlationIdentifier); - } - - if (parameters.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) - { - return this.groupProvider.RetrieveAsync(parameters, correlationIdentifier); - } - - throw new NotImplementedException(); - } - - public override Task UpdateAsync(IPatch patch, string correlationIdentifier) - { - if (patch == null) - { - throw new ArgumentNullException(nameof(patch)); - } - - if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) - { - throw new ArgumentException(nameof(patch)); - } - - if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.SchemaIdentifier)) - { - throw new ArgumentException(nameof(patch)); - } - - if (patch.ResourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser)) - { - return this.userProvider.UpdateAsync(patch, correlationIdentifier); - } - - if (patch.ResourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2Group)) - { - return this.groupProvider.UpdateAsync(patch, correlationIdentifier); - } - - throw new NotImplementedException(); - } - } -} diff --git a/Microsoft.SCIM.Sample/InMemoryStorage.cs b/Microsoft.SCIM.Sample/InMemoryStorage.cs deleted file mode 100644 index bde0e4f2..00000000 --- a/Microsoft.SCIM.Sample/InMemoryStorage.cs +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.SCIM.Sample -{ - using System; - using System.Collections.Generic; - using Microsoft.SCIM; - - public class InMemoryStorage - { - internal readonly IDictionary Groups; - internal readonly IDictionary Users; - - private InMemoryStorage() - { - this.Groups = new Dictionary(); - this.Users = new Dictionary(); - } - - private static readonly Lazy InstanceValue = - new Lazy( - () => - new InMemoryStorage()); - - public static InMemoryStorage Instance - { - get - { - return InMemoryStorage.InstanceValue.Value; - } - } - } -} diff --git a/Microsoft.SCIM.Sample/InMemoryUserProvider.cs b/Microsoft.SCIM.Sample/InMemoryUserProvider.cs deleted file mode 100644 index f8a58287..00000000 --- a/Microsoft.SCIM.Sample/InMemoryUserProvider.cs +++ /dev/null @@ -1,265 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.SCIM.Sample -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net; - using System.Threading.Tasks; - using System.Web.Http; - using Microsoft.SCIM; - using Microsoft.SCIM.Sample.Properties; - - public class InMemoryUserProvider : ProviderBase - { - private readonly InMemoryStorage storage; - - public InMemoryUserProvider() - { - this.storage = InMemoryStorage.Instance; - } - - public override Task CreateAsync(Resource resource, string correlationIdentifier) - { - if (resource.Identifier != null) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - Core2EnterpriseUser user = resource as Core2EnterpriseUser; - if (string.IsNullOrWhiteSpace(user.UserName)) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - IEnumerable exisitingUsers = this.storage.Users.Values; - if - ( - exisitingUsers.Any( - (Core2EnterpriseUser exisitingUser) => - string.Equals(exisitingUser.UserName, user.UserName, StringComparison.Ordinal)) - ) - { - throw new HttpResponseException(HttpStatusCode.Conflict); - } - - string resourceIdentifier = Guid.NewGuid().ToString(); - resource.Identifier = resourceIdentifier; - this.storage.Users.Add(resourceIdentifier, user); - - return Task.FromResult(resource); - } - - public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) - { - if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier)) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - string identifier = resourceIdentifier.Identifier; - - if (this.storage.Users.ContainsKey(identifier)) - { - this.storage.Users.Remove(identifier); - } - - return Task.CompletedTask; - } - - public override Task QueryAsync(IQueryParameters parameters, string correlationIdentifier) - { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - - if (string.IsNullOrWhiteSpace(correlationIdentifier)) - { - throw new ArgumentNullException(nameof(correlationIdentifier)); - } - - if (null == parameters.AlternateFilters) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - Resource[] results; - IFilter queryFilter = parameters.AlternateFilters.SingleOrDefault(); - if (queryFilter == null) - { - IEnumerable allUsers = this.storage.Users.Values; - results = - allUsers.Select((Core2EnterpriseUser user) => user as Resource).ToArray(); - - return Task.FromResult(results); - } - - if (string.IsNullOrWhiteSpace(queryFilter.AttributePath)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - if (string.IsNullOrWhiteSpace(queryFilter.ComparisonValue)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidParameters); - } - - if (queryFilter.FilterOperator != ComparisonOperator.Equals) - { - throw new NotSupportedException(SampleServiceResources.UnsupportedComparisonOperator); - } - - if (queryFilter.AttributePath.Equals(AttributeNames.UserName)) - { - IEnumerable allUsers = this.storage.Users.Values; - results = - allUsers.Where( - (Core2EnterpriseUser item) => - string.Equals( - item.UserName, - parameters.AlternateFilters.Single().ComparisonValue, - StringComparison.OrdinalIgnoreCase)) - .Select((Core2EnterpriseUser user) => user as Resource).ToArray(); - - return Task.FromResult(results); - } - - if (queryFilter.AttributePath.Equals(AttributeNames.ExternalIdentifier)) - { - IEnumerable allUsers = this.storage.Users.Values; - results = - allUsers.Where( - (Core2EnterpriseUser item) => - string.Equals( - item.ExternalIdentifier, - parameters.AlternateFilters.Single().ComparisonValue, - StringComparison.OrdinalIgnoreCase)) - .Select((Core2EnterpriseUser user) => user as Resource).ToArray(); - - return Task.FromResult(results); - } - - throw new NotSupportedException(SampleServiceResources.UnsupportedFilterAttributeUser); - } - - public override Task ReplaceAsync(Resource resource, string correlationIdentifier) - { - if (resource.Identifier == null) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - Core2EnterpriseUser user = resource as Core2EnterpriseUser; - - if (string.IsNullOrWhiteSpace(user.UserName)) - { - throw new HttpResponseException(HttpStatusCode.BadRequest); - } - - IEnumerable exisitingUsers = this.storage.Users.Values; - if - ( - exisitingUsers.Any( - (Core2EnterpriseUser exisitingUser) => - string.Equals(exisitingUser.UserName, user.UserName, StringComparison.Ordinal) && - !string.Equals(exisitingUser.Identifier, user.Identifier, StringComparison.OrdinalIgnoreCase)) - ) - { - throw new HttpResponseException(HttpStatusCode.Conflict); - } - - if (!this.storage.Users.TryGetValue(user.Identifier, out Core2EnterpriseUser _)) - { - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - this.storage.Users[user.Identifier] = user; - Resource result = user as Resource; - return Task.FromResult(result); - } - - public override Task RetrieveAsync(IResourceRetrievalParameters parameters, string correlationIdentifier) - { - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - - if (string.IsNullOrWhiteSpace(correlationIdentifier)) - { - throw new ArgumentNullException(nameof(correlationIdentifier)); - } - - if (string.IsNullOrEmpty(parameters?.ResourceIdentifier?.Identifier)) - { - throw new ArgumentNullException(nameof(parameters)); - } - - Resource result = null; - string identifier = parameters.ResourceIdentifier.Identifier; - - if (this.storage.Users.ContainsKey(identifier)) - { - if (this.storage.Users.TryGetValue(identifier, out Core2EnterpriseUser user)) - { - result = user as Resource; - return Task.FromResult(result); - } - } - - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - public override Task UpdateAsync(IPatch patch, string correlationIdentifier) - { - if (null == patch) - { - throw new ArgumentNullException(nameof(patch)); - } - - if (null == patch.ResourceIdentifier) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); - } - - if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); - } - - if (null == patch.PatchRequest) - { - throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch); - } - - PatchRequest2 patchRequest = - patch.PatchRequest as PatchRequest2; - - if (null == patchRequest) - { - string unsupportedPatchTypeName = patch.GetType().FullName; - throw new NotSupportedException(unsupportedPatchTypeName); - } - - if (this.storage.Users.TryGetValue(patch.ResourceIdentifier.Identifier, out Core2EnterpriseUser user)) - { - user.Apply(patchRequest); - } - else - { - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - return Task.CompletedTask; - } - } -} diff --git a/Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj b/Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj deleted file mode 100644 index 86f590d8..00000000 --- a/Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - DEBUG - - - - - - - diff --git a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs b/Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs deleted file mode 100644 index 1e4ab2c1..00000000 --- a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Microsoft.SCIM.Sample.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class SampleServiceResources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal SampleServiceResources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.SystemForCrossDomainIdentityManagement.Sample.Properties.SampleServiceR" + - "esources", typeof(SampleServiceResources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Invalid parameters.. - /// - internal static string ExceptionInvalidParameters { - get { - return ResourceManager.GetString("ExceptionInvalidParameters", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invalid patch.. - /// - internal static string ExceptionInvalidPatch { - get { - return ResourceManager.GetString("ExceptionInvalidPatch", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The comparison operator is not supported. The only supported operator is 'eq'.. - /// - internal static string UnsupportedComparisonOperator { - get { - return ResourceManager.GetString("UnsupportedComparisonOperator", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The filter attribute is not supported. The supported filter attributes are displayName and externalId.. - /// - internal static string UnsupportedFilterAttributeGroup { - get { - return ResourceManager.GetString("UnsupportedFilterAttributeGroup", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The filter attribute is not supported. The supported filter attributes are userName and externalId.. - /// - internal static string UnsupportedFilterAttributeUser { - get { - return ResourceManager.GetString("UnsupportedFilterAttributeUser", resourceCulture); - } - } - } -} diff --git a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.resx b/Microsoft.SCIM.Sample/Properties/SampleServiceResources.resx deleted file mode 100644 index 3ec37902..00000000 --- a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.resx +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Invalid parameters. - - - Invalid patch. - - - The comparison operator is not supported. The only supported operator is 'eq'. - - - The filter attribute is not supported. The supported filter attributes are displayName and externalId. - - - The filter attribute is not supported. The supported filter attributes are userName and externalId. - - \ No newline at end of file diff --git a/Microsoft.SCIM.Sample/Startup.cs b/Microsoft.SCIM.Sample/Startup.cs deleted file mode 100644 index aba08a01..00000000 --- a/Microsoft.SCIM.Sample/Startup.cs +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -#pragma warning disable IDE0065 // Misplaced using directive -#pragma warning restore IDE0065 // Misplaced using directive - -namespace Microsoft.SCIM.Sample -{ - using System; - using Microsoft.SCIM; - - public class Startup - { - private const string baseAddress = "http://localhost:20000"; - - static void Main() - { - Service service = new ServiceProvider(); - service.Start(new Uri(Startup.baseAddress)); - - Console.ReadKey(true); - } - } - - internal class ServiceProvider : Service - { - public override IMonitor MonitoringBehavior { get; set; } - public override IProvider ProviderBehavior { get; set; } - - public ServiceProvider() - { - this.MonitoringBehavior = new ConsoleMonitor(); - this.ProviderBehavior = new InMemoryProvider(); - } - } -} diff --git a/Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json b/Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json new file mode 100644 index 00000000..56e0950c --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "3.1.2", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/Microsoft.SCIM.sln b/Microsoft.SCIM.sln index a0dcf760..fff9b0ca 100644 --- a/Microsoft.SCIM.sln +++ b/Microsoft.SCIM.sln @@ -5,9 +5,7 @@ VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM", "Microsoft.SystemForCrossDomainIdentityManagement\Microsoft.SCIM.csproj", "{C9ED6410-1995-4B98-AD57-C02D5F16631C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM.Sample", "Microsoft.SCIM.Sample\Microsoft.SCIM.Sample.csproj", "{06220587-471C-4AB0-BBB6-F1D9E35DBDDF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.SCIM.WebHostSample", "Microsoft.SCIM.WebHostSample\Microsoft.SCIM.WebHostSample.csproj", "{238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM.WebHostSample", "Microsoft.SCIM.WebHostSample\Microsoft.SCIM.WebHostSample.csproj", "{238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -19,10 +17,6 @@ Global {C9ED6410-1995-4B98-AD57-C02D5F16631C}.Debug|Any CPU.Build.0 = Debug|Any CPU {C9ED6410-1995-4B98-AD57-C02D5F16631C}.Release|Any CPU.ActiveCfg = Release|Any CPU {C9ED6410-1995-4B98-AD57-C02D5F16631C}.Release|Any CPU.Build.0 = Release|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Release|Any CPU.Build.0 = Release|Any CPU {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Debug|Any CPU.Build.0 = Debug|Any CPU {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs deleted file mode 100644 index 9d1c3632..00000000 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.SCIM -{ - using System; - using System.IO; - using Microsoft.AspNetCore.Hosting; - using Microsoft.Extensions.DependencyInjection; - - public abstract class Service : IDisposable - { - private readonly object thisLock = new object(); - private IDisposable webHost; - - public abstract IMonitor MonitoringBehavior { get; set; } - public abstract IProvider ProviderBehavior { get; set; } - - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (this.webHost != null) - { - lock (this.thisLock) - { - if (this.webHost != null) - { - this.webHost.Dispose(); - this.webHost = null; - } - } - } - } - - public void Start(Uri baseAddress) - { - if (null == baseAddress) - { - throw new ArgumentNullException(nameof(baseAddress)); - } - - if (null == this.ProviderBehavior) - { - throw new InvalidOperationException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionNotInitializedProviderBehavior); - } - - if (null == this.MonitoringBehavior) - { - throw new InvalidOperationException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionNotInitializedMonitoringBehavior); - } - - lock (this.thisLock) - { - IWebHost host = - new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .ConfigureServices(services => - { - services.AddSingleton(typeof(IProvider), this.ProviderBehavior); - services.AddSingleton(typeof(IMonitor), this.MonitoringBehavior); - }) - .UseStartup() - .Build(); - - host.Run(); - } - } - } -} diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs deleted file mode 100644 index 5bb4ff02..00000000 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs +++ /dev/null @@ -1,67 +0,0 @@ -//---------------------------------------------------------------- -// Copyright (c) Microsoft Corporation. All rights reserved. -//---------------------------------------------------------------- - -namespace Microsoft.SCIM -{ - using System; - using System.Text; - using Microsoft.AspNetCore.Authentication.JwtBearer; - using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.Routing; - using Microsoft.Extensions.Configuration; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.IdentityModel.Tokens; - - public class WebApplicationStarter - { - public WebApplicationStarter(IConfiguration configuration) - { - this.Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public static void ConfigureServices(IServiceCollection services) - { - services.AddAuthentication(options => - { - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(options => - { - options.TokenValidationParameters = - new TokenValidationParameters - { - ValidateIssuer = false, - ValidateAudience = false, - ValidateLifetime = false, - ValidateIssuerSigningKey = false, - ValidIssuer = ServiceConstants.TokenIssuer, - ValidAudience = ServiceConstants.TokenAudience, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer)) - }; - }); - - services.AddControllers().AddNewtonsoftJson(); - } - - public static void Configure(IApplicationBuilder applicationBuilder) - { - applicationBuilder.UseHsts(); - - applicationBuilder.UseRouting(); - //app.UseHttpsRedirection(); - //app.UseAuthentication(); - //app.UseAuthorization(); - - applicationBuilder.UseEndpoints( - (IEndpointRouteBuilder endpoints) => - { - endpoints.MapDefaultControllerRoute(); - }); - } - } -}