Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ODS-3401] Cycles in claims taxonomy (security metadata for resource claims) causes requests to hang #993

Merged
merged 14 commits into from
Mar 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public virtual AuthorizationStrategy GetAuthorizationStrategyByName(string autho

public virtual IList<ClaimSetResourceClaimAction> GetClaimsForClaimSet(string claimSetName)
{

return _securityTableGateway.GetClaimSetResourceClaimActions()
.Where(c => c.ClaimSet.ClaimSetName.Equals(claimSetName, StringComparison.OrdinalIgnoreCase))
.ToList();
Expand All @@ -54,9 +53,9 @@ public virtual IList<string> GetResourceClaimLineage(string resourceClaimUri)
.ToList();
}

private IEnumerable<ResourceClaim> GetResourceClaimLineageForResourceClaim(string resourceClaimUri)
private IEnumerable<ResourceClaim> GetResourceClaimLineageForResourceClaim(string resourceClaimUri, HashSet<ResourceClaim> resourceClaimLineage = null)
{
var resourceClaimLineage = new List<ResourceClaim>();
resourceClaimLineage ??= new HashSet<ResourceClaim>();

ResourceClaim resourceClaim;

Expand All @@ -74,11 +73,14 @@ private IEnumerable<ResourceClaim> GetResourceClaimLineageForResourceClaim(strin

if (resourceClaim != null)
{
resourceClaimLineage.Add(resourceClaim);
if (!resourceClaimLineage.Add(resourceClaim))
{
throw new InvalidOperationException($"The lineage for resource claim '{resourceClaimUri}' is not well-formed. A cycle was detected in the resource claim lineage.");
}

if (resourceClaim.ParentResourceClaim != null)
{
resourceClaimLineage.AddRange(GetResourceClaimLineageForResourceClaim(resourceClaim.ParentResourceClaim.ClaimName));
resourceClaimLineage.UnionWith(GetResourceClaimLineageForResourceClaim(resourceClaim.ParentResourceClaim.ClaimName, resourceClaimLineage));
}
}

Expand Down
Loading