-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
@mjaksn Just wondering if you might be able to do this more directly by just switching to using a private IEnumerable<ResourceClaim> GetResourceClaimLineageForResourceClaim(string resourceClaimUri)
{
// ==============================
// Use a HashSet<T> here instead of List<T>?
// ==============================
var resourceClaimLineage = new List<ResourceClaim>();
ResourceClaim resourceClaim;
try
{
resourceClaim = _securityTableGateway.GetResourceClaims()
.SingleOrDefault(rc => rc.ClaimName.Equals(resourceClaimUri, StringComparison.OrdinalIgnoreCase));
}
catch (InvalidOperationException ex)
{
// Use InvalidOperationException wrapper with custom message over InvalidOperationException
// thrown by Linq to communicate back to caller the problem with the configuration.
throw new InvalidOperationException($"Multiple resource claims with a claim name of '{resourceClaimUri}' were found in the Ed-Fi API's security configuration. Authorization cannot be performed.", ex);
}
if (resourceClaim != null)
{
// ==============================
// OLD: resourceClaimLineage.Add(resourceClaim);
// NEW:
if (!resourceClaimLineage.Add(resourceClaim))
{
// Handle cycle problem here
}
// ==============================
if (resourceClaim.ParentResourceClaim != null)
{
resourceClaimLineage.AddRange(GetResourceClaimLineageForResourceClaim(resourceClaim.ParentResourceClaim.ClaimName));
}
}
return resourceClaimLineage;
} Also, in looking at the code, I think it's an opportunity to be more efficient and declare the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After direct conversation in Slack, we discussed a few change/improvements to the implementation, include:
- Switch back to
List<T>
and use aContains
check in lieu of aHashSet<T>
and a check on theAdd
method becauseHashSet<T>
doesn't guarantee preservation of insertion order which is important to the semantics of this method. - Expand the resulting message to include the resource claims participating in the cycle to be included in the
errors
collection of the Problem Details response. - Add unit test coverage since this would be difficult to test at an integration test level.
tests/EdFi.Security.DataAccess.UnitTests/Repositories/SecurityRepositoryTests.cs
Outdated
Show resolved
Hide resolved
If I disable the Security cache, this validation fails to find the cycle because it hits the DB on each recursive call (so we get a new instance with a different hash code) so Turning off the Security cache isn't a real-world scenario; should we care about this edge case?
Note that something related could happen if the cache expires right in the middle of a check, but this wouldn't result in a StackOverflow because the cache is still there; the error message would come up with a duplicated cycle, though. |
Application/EdFi.Security.DataAccess/Repositories/SecurityRepository.cs
Outdated
Show resolved
Hide resolved
Application/EdFi.Security.DataAccess/Repositories/SecurityRepository.cs
Outdated
Show resolved
Hide resolved
Requested changes have been addressed.
No description provided.