-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#746 Multiple values in static claims #2131
base: develop
Are you sure you want to change the base?
#746 Multiple values in static claims #2131
Conversation
Thank you for the PR! |
@raman-m reviewing it right now... |
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.
@raman-m @asrasya-kosha Ok for me, but the ClaimsAuthorizer code is difficult to read. I think we could probably refactor it a bit.
@@ -32,7 +32,7 @@ List<PlaceholderNameAndValue> urlPathPlaceholderNameAndValues | |||
if (values.Data != null) | |||
{ | |||
// dynamic claim | |||
var match = Regex.Match(required.Value, @"^{(?<variable>.+)}$"); | |||
var match = Regex.Match(required.Value!.FirstOrDefault() ?? string.Empty, "^{(?<variable>.+)}$"); |
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.
That's not your code, I agree, Maybe we could use a compiled Regex and enhance security by specifying a timeout, 10 seconds...
[GeneratedRegex("^{(?<variable>.+)}$", RegexOptions.Compiled, 10000)]
private static partial Regex DynamicClaimRegex();
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.
in GenerateRegex, RegexOptions.Compiled is ignored
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.
We have well known open PR by Mohsen who followed Regex
best practices, see #1348
Thanks for code review! But you know I will return to feature PRs after v23.3 Hotfixes release. |
@raman-m I'll add acceptance tests and new unit tests (I thought I added them but I'll have a look once again) this weekend and update the PR. The line ending changes are perhaps a GitHub issue? because I don't see them in rider when I do sa side by side compare. Thanks |
@@ -32,7 +32,7 @@ List<PlaceholderNameAndValue> urlPathPlaceholderNameAndValues | |||
if (values.Data != null) | |||
{ | |||
// dynamic claim | |||
var match = Regex.Match(required.Value, @"^{(?<variable>.+)}$"); | |||
var match = Regex.Match(required.Value!.FirstOrDefault() ?? string.Empty, "^{(?<variable>.+)}$"); |
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.
in GenerateRegex, RegexOptions.Compiled is ignored
@@ -8,7 +8,7 @@ public interface IClaimsAuthorizer | |||
{ | |||
Response<bool> Authorize( | |||
ClaimsPrincipal claimsPrincipal, | |||
Dictionary<string, string> routeClaimsRequirement, | |||
Dictionary<string, string[]> routeClaimsRequirement, |
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.
Dictionary<string, string[]> routeClaimsRequirement, | |
IDictionary<string, string[]> routeClaimsRequirement, | |
@@ -126,7 +126,7 @@ public DownstreamRouteBuilder WithClaimsToClaims(List<ClaimToThing> input) | |||
return this; | |||
} | |||
|
|||
public DownstreamRouteBuilder WithRouteClaimsRequirement(Dictionary<string, string> input) | |||
public DownstreamRouteBuilder WithRouteClaimsRequirement(Dictionary<string, string[]> input) |
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.
public DownstreamRouteBuilder WithRouteClaimsRequirement(Dictionary<string, string[]> input) | |
public DownstreamRouteBuilder WithRouteClaimsRequirement(IDictionary<string, string[]> input) |
public int Priority { get; set; } | ||
public FileQoSOptions QoSOptions { get; set; } | ||
public FileRateLimitRule RateLimitOptions { get; set; } | ||
public string RequestIdKey { get; set; } | ||
public Dictionary<string, string> RouteClaimsRequirement { get; set; } | ||
public Dictionary<string, string[]> RouteClaimsRequirement { get; set; } |
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.
public Dictionary<string, string[]> RouteClaimsRequirement { get; set; } | |
public IDictionary<string, string[]> RouteClaimsRequirement { get; set; } |
@@ -100,7 +100,7 @@ public DownstreamRoute( | |||
public CacheOptions CacheOptions { get; } | |||
public LoadBalancerOptions LoadBalancerOptions { get; } | |||
public RateLimitOptions RateLimitOptions { get; } | |||
public Dictionary<string, string> RouteClaimsRequirement { get; } | |||
public Dictionary<string, string[]> RouteClaimsRequirement { get; } |
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.
public Dictionary<string, string[]> RouteClaimsRequirement { get; } | |
public IDictionary<string, string[]> RouteClaimsRequirement { get; } | |
@@ -13,7 +13,7 @@ public class DownstreamRouteBuilder | |||
private bool _isAuthenticated; | |||
private List<ClaimToThing> _claimsToHeaders; | |||
private List<ClaimToThing> _claimToClaims; | |||
private Dictionary<string, string> _routeClaimRequirement; | |||
private Dictionary<string, string[]> _routeClaimRequirement; |
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.
private Dictionary<string, string[]> _routeClaimRequirement; | |
private IDictionary<string, string[]> _routeClaimRequirement; |
@@ -16,7 +16,7 @@ public ClaimsAuthorizer(IClaimsParser claimsParser) | |||
|
|||
public Response<bool> Authorize( | |||
ClaimsPrincipal claimsPrincipal, | |||
Dictionary<string, string> routeClaimsRequirement, | |||
Dictionary<string, string[]> routeClaimsRequirement, |
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.
Dictionary<string, string[]> routeClaimsRequirement, | |
IDictionary<string, string[]> routeClaimsRequirement, |
@asrasya-kosha Please work on code review issues. |
@asrasya-kosha commented on Aug 20, 2024
The changes in line endings are not due to GitHub; rather, they are caused by your IDE. GitHub simply identifies the different line endings and highlights those lines.
We have Visual Studio IDE settings for line endings here: .editorconfig#L19-L21 (common settings), *.{cs,vb} (C# CRLF ending). However, there is no settings file for Rider IDE. |
8204bbd
to
d2b9a2b
Compare
removed redundant tests
d2b9a2b
to
a6eae47
Compare
Closes #746
Proposed Changes
RouteClaimsRequirement
s to accept multiple values for a single keyClaimsAuthorizer
to validate with any of the given values for a key for a static claimClaimsAuthorizer
for dynamic claims to only accept the first value for a given keyNote : The proposed changed will only work for static claims. There shouldn't be any effect on the dynamic claims.