Skip to content

Commit

Permalink
Ticket #825 & Ticket #824
Browse files Browse the repository at this point in the history
  • Loading branch information
thabart committed Dec 4, 2024
1 parent 6aa7c93 commit 4ccd11b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/Scim/SimpleIdServer.Scim/Api/BaseApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected async Task<IActionResult> 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())
{
Expand Down Expand Up @@ -321,7 +321,7 @@ protected async Task<IActionResult> InternalGet(string realm, string id, GetSCIM
if (getRepresentationResult.HasError) return this.BuildError(getRepresentationResult);
var representation = getRepresentationResult.Result;
await _attributeReferenceEnricher.Enrich(_resourceType, new List<SCIMRepresentation> { representation }, _uriProvider.GetAbsoluteUriWithVirtualPath());
return BuildHTTPResult(representation, HttpStatusCode.OK, true);
return BuildHTTPResult(realm, representation, HttpStatusCode.OK, true);
}
catch (SCIMSchemaViolatedException ex)
{
Expand Down Expand Up @@ -353,7 +353,7 @@ protected async Task<IActionResult> 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)
{
Expand Down Expand Up @@ -404,7 +404,7 @@ protected async Task<IActionResult> 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);
Expand Down Expand Up @@ -448,7 +448,7 @@ protected async Task<IActionResult> 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);
Expand Down Expand Up @@ -521,7 +521,7 @@ protected async Task<IActionResult> 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);
Expand Down Expand Up @@ -598,9 +598,9 @@ private async Task<IActionResult> 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);
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Scim/SimpleIdServer.Scim/RouteBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4ccd11b

Please sign in to comment.