From 4ccd11bb2c88e119085155d4eddd7083a2df5aa2 Mon Sep 17 00:00:00 2001 From: thabart Date: Wed, 4 Dec 2024 22:44:09 +0100 Subject: [PATCH] Ticket #825 & Ticket #824 --- .../Api/BaseApiController.cs | 20 +++++++++---------- .../RouteBuilderExtensions.cs | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Scim/SimpleIdServer.Scim/Api/BaseApiController.cs b/src/Scim/SimpleIdServer.Scim/Api/BaseApiController.cs index 66f280a9d..4a809ea69 100644 --- a/src/Scim/SimpleIdServer.Scim/Api/BaseApiController.cs +++ b/src/Scim/SimpleIdServer.Scim/Api/BaseApiController.cs @@ -257,7 +257,7 @@ protected async Task InternalSearch(string prefix, SearchSCIMReso foreach (var record in representations) { JObject newJObj = null; - var location = $"{baseUrl}/{_resourceTypeResolver.ResolveByResourceType(_resourceType).ControllerName}/{record.Id}"; + var location = GetLocation(realm, record); bool includeStandardRequest = true; if (searchRequest.Attributes.Any()) { @@ -321,7 +321,7 @@ protected async Task InternalGet(string realm, string id, GetSCIM if (getRepresentationResult.HasError) return this.BuildError(getRepresentationResult); var representation = getRepresentationResult.Result; await _attributeReferenceEnricher.Enrich(_resourceType, new List { representation }, _uriProvider.GetAbsoluteUriWithVirtualPath()); - return BuildHTTPResult(representation, HttpStatusCode.OK, true); + return BuildHTTPResult(realm, representation, HttpStatusCode.OK, true); } catch (SCIMSchemaViolatedException ex) { @@ -353,7 +353,7 @@ protected async Task InternalAdd(string prefix, RepresentationPar if (addRepresentationResult.HasError) return this.BuildError(addRepresentationResult); var representation = addRepresentationResult.Result; representation.ApplyEmptyArray(); - var location = GetLocation(representation); + var location = GetLocation(realm, representation); var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes); if (IsPublishEvtsEnabled) { @@ -404,7 +404,7 @@ protected async Task InternalDelete(string prefix, string id, Can if (getRepresentationResult.HasError) return this.BuildError(getRepresentationResult); var representation = getRepresentationResult.Result; representation.ApplyEmptyArray(); - var location = GetLocation(representation); + var location = GetLocation(realm, representation); var content = representation.ToResponse(location, false, mergeExtensionAttributes: _options.MergeExtensionAttributes); if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationRemovedEvent(id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty)); return new StatusCodeResult((int)HttpStatusCode.NoContent); @@ -448,7 +448,7 @@ protected async Task InternalUpdate(string prefix, string id, Rep if (!updateResult.Result.IsReplaced) return NoContent(); var representation = updateResult.Result.Representation; representation.ApplyEmptyArray(); - var location = GetLocation(representation); + var location = GetLocation(realm, representation); if (!_options.IsFullRepresentationReturned) { var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes); @@ -521,7 +521,7 @@ protected async Task InternalPatch(string prefix, string id, Patc if (!patchResult.IsPatched) return NoContent(); var representation = patchResult.Representation; representation.ApplyEmptyArray(); - var location = GetLocation(representation); + var location = GetLocation(realm, representation); if(!_options.IsFullRepresentationReturned) { var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes); @@ -598,9 +598,9 @@ private async Task Handle(Exception exception, CancellationToken return customActionResult; } - protected IActionResult BuildHTTPResult(SCIMRepresentation representation, HttpStatusCode status, bool isGetRequest) + protected IActionResult BuildHTTPResult(string realm, SCIMRepresentation representation, HttpStatusCode status, bool isGetRequest) { - var location = GetLocation(representation); + var location = GetLocation(realm, representation); var content = representation.ToResponse(location, isGetRequest, mergeExtensionAttributes: _options.MergeExtensionAttributes); return BuildHTTPResult(status, location, representation.Version, content); } @@ -617,9 +617,9 @@ protected IActionResult BuildHTTPResult(HttpStatusCode status, string location, }; } - protected string GetLocation(SCIMRepresentation representation) + protected string GetLocation(string realm, SCIMRepresentation representation) { - return $"{_uriProvider.GetAbsoluteUriWithVirtualPath()}/{_resourceTypeResolver.ResolveByResourceType(representation.ResourceType).ControllerName}/{representation.Id}"; + return $"{_uriProvider.GetAbsoluteUriWithVirtualPath()}{(!string.IsNullOrWhiteSpace(realm) ? $"/{realm}" : string.Empty)}/{_resourceTypeResolver.ResolveByResourceType(representation.ResourceType).ControllerName}/{representation.Id}"; } protected virtual string GetResourceType(string resourceType) diff --git a/src/Scim/SimpleIdServer.Scim/RouteBuilderExtensions.cs b/src/Scim/SimpleIdServer.Scim/RouteBuilderExtensions.cs index 9ddfb1667..c44a907f0 100644 --- a/src/Scim/SimpleIdServer.Scim/RouteBuilderExtensions.cs +++ b/src/Scim/SimpleIdServer.Scim/RouteBuilderExtensions.cs @@ -23,7 +23,7 @@ public static IRouteBuilder UseScim(this IRouteBuilder webApp, bool usePrefix = defaults: new { controller = "Schemas", action = "GetAll" }); webApp.ScimMapControllerRoute("getSchema", pattern: SCIMEndpoints.Schemas + "/{id}", - defaults: new { controller = "Schema", action = "Get" }); + defaults: new { controller = "Schemas", action = "Get" }); webApp.ScimMapControllerRoute("getServiceProviderConfig", pattern: SCIMEndpoints.ServiceProviderConfig,