-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ public ClaimsAuthorizer(IClaimsParser claimsParser) | |
|
||
public Response<bool> Authorize( | ||
ClaimsPrincipal claimsPrincipal, | ||
Dictionary<string, string> routeClaimsRequirement, | ||
Dictionary<string, string[]> routeClaimsRequirement, | ||
List<PlaceholderNameAndValue> urlPathPlaceholderNameAndValues | ||
) | ||
{ | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. We have well known open PR by Mohsen who followed |
||
if (match.Success) | ||
{ | ||
var variableName = match.Captures[0].Value; | ||
|
@@ -67,7 +67,7 @@ List<PlaceholderNameAndValue> urlPathPlaceholderNameAndValues | |
else | ||
{ | ||
// static claim | ||
var authorized = values.Data.Contains(required.Value); | ||
var authorized = required.Value.Any(x=> values.Data.Contains(x)); | ||
if (!authorized) | ||
{ | ||
return new ErrorResponse<bool>(new ClaimValueNotAuthorizedError( | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher; | ||||||||
using Ocelot.Responses; | ||||||||
using Ocelot.Responses; | ||||||||
using System.Security.Claims; | ||||||||
|
||||||||
namespace Ocelot.Authorization | ||||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
List<PlaceholderNameAndValue> urlPathPlaceholderNameAndValues | ||||||||
); | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
private bool _isAuthorized; | ||||||
private List<ClaimToThing> _claimToQueries; | ||||||
private List<ClaimToThing> _claimToDownstreamPath; | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
_routeClaimRequirement = input; | ||||||
return this; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||
using Ocelot.Configuration.Creator; | ||||||||
using Ocelot.Configuration.Creator; | ||||||||
using Ocelot.Values; | ||||||||
|
||||||||
namespace Ocelot.Configuration | ||||||||
|
@@ -23,7 +23,7 @@ public DownstreamRoute( | |||||||
CacheOptions cacheOptions, | ||||||||
LoadBalancerOptions loadBalancerOptions, | ||||||||
RateLimitOptions rateLimitOptions, | ||||||||
Dictionary<string, string> routeClaimsRequirement, | ||||||||
Dictionary<string, string[]> routeClaimsRequirement, | ||||||||
List<ClaimToThing> claimsToQueries, | ||||||||
List<ClaimToThing> claimsToHeaders, | ||||||||
List<ClaimToThing> claimsToClaims, | ||||||||
|
@@ -99,7 +99,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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
public List<ClaimToThing> ClaimsToQueries { get; } | ||||||||
public List<ClaimToThing> ClaimsToHeaders { get; } | ||||||||
public List<ClaimToThing> ClaimsToClaims { get; } | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,31 +1,31 @@ | ||||||
using Ocelot.Configuration.Creator; | ||||||
namespace Ocelot.Configuration.File | ||||||
using Ocelot.Configuration.Creator; | ||||||
|
||||||
namespace Ocelot.Configuration.File | ||||||
{ | ||||||
public class FileRoute : IRoute, ICloneable | ||||||
{ | ||||||
public FileRoute() | ||||||
{ | ||||||
AddClaimsToRequest = new Dictionary<string, string>(); | ||||||
AddHeadersToRequest = new Dictionary<string, string>(); | ||||||
AddQueriesToRequest = new Dictionary<string, string>(); | ||||||
AuthenticationOptions = new FileAuthenticationOptions(); | ||||||
ChangeDownstreamPathTemplate = new Dictionary<string, string>(); | ||||||
DelegatingHandlers = new List<string>(); | ||||||
DownstreamHeaderTransform = new Dictionary<string, string>(); | ||||||
DownstreamHostAndPorts = new List<FileHostAndPort>(); | ||||||
FileCacheOptions = new FileCacheOptions(); | ||||||
HttpHandlerOptions = new FileHttpHandlerOptions(); | ||||||
LoadBalancerOptions = new FileLoadBalancerOptions(); | ||||||
Metadata = new Dictionary<string, string>(); | ||||||
Priority = 1; | ||||||
QoSOptions = new FileQoSOptions(); | ||||||
RateLimitOptions = new FileRateLimitRule(); | ||||||
RouteClaimsRequirement = new Dictionary<string, string>(); | ||||||
SecurityOptions = new FileSecurityOptions(); | ||||||
public class FileRoute : IRoute, ICloneable | ||||||
{ | ||||||
public FileRoute() | ||||||
{ | ||||||
AddClaimsToRequest = new Dictionary<string, string>(); | ||||||
AddHeadersToRequest = new Dictionary<string, string>(); | ||||||
AddQueriesToRequest = new Dictionary<string, string>(); | ||||||
AuthenticationOptions = new FileAuthenticationOptions(); | ||||||
ChangeDownstreamPathTemplate = new Dictionary<string, string>(); | ||||||
DelegatingHandlers = new List<string>(); | ||||||
DownstreamHeaderTransform = new Dictionary<string, string>(); | ||||||
DownstreamHostAndPorts = new List<FileHostAndPort>(); | ||||||
FileCacheOptions = new FileCacheOptions(); | ||||||
HttpHandlerOptions = new FileHttpHandlerOptions(); | ||||||
LoadBalancerOptions = new FileLoadBalancerOptions(); | ||||||
Metadata = new Dictionary<string, string>(); | ||||||
Priority = 1; | ||||||
QoSOptions = new FileQoSOptions(); | ||||||
RateLimitOptions = new FileRateLimitRule(); | ||||||
RouteClaimsRequirement = new Dictionary<string, string[]>(); | ||||||
SecurityOptions = new FileSecurityOptions(); | ||||||
UpstreamHeaderTemplates = new Dictionary<string, string>(); | ||||||
UpstreamHeaderTransform = new Dictionary<string, string>(); | ||||||
UpstreamHttpMethod = new List<string>(); | ||||||
UpstreamHeaderTransform = new Dictionary<string, string>(); | ||||||
UpstreamHttpMethod = new List<string>(); | ||||||
} | ||||||
|
||||||
public FileRoute(FileRoute from) | ||||||
|
@@ -44,30 +44,30 @@ public FileRoute(FileRoute from) | |||||
public List<FileHostAndPort> DownstreamHostAndPorts { get; set; } | ||||||
public string DownstreamHttpMethod { get; set; } | ||||||
public string DownstreamHttpVersion { get; set; } | ||||||
/// <summary>The <see cref="HttpVersionPolicy"/> enum specifies behaviors for selecting and negotiating the HTTP version for a request.</summary> | ||||||
/// <value>A <see langword="string" /> value of defined <see cref="VersionPolicies"/> constants.</value> | ||||||
/// <remarks> | ||||||
/// Related to the <see cref="DownstreamHttpVersion"/> property. | ||||||
/// <list type="bullet"> | ||||||
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpversionpolicy">HttpVersionPolicy Enum</see></item> | ||||||
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.httpversion">HttpVersion Class</see></item> | ||||||
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.versionpolicy">HttpRequestMessage.VersionPolicy Property</see></item> | ||||||
/// </list> | ||||||
/// </remarks> | ||||||
|
||||||
/// <summary>The <see cref="HttpVersionPolicy"/> enum specifies behaviors for selecting and negotiating the HTTP version for a request.</summary> | ||||||
/// <value>A <see langword="string" /> value of defined <see cref="VersionPolicies"/> constants.</value> | ||||||
/// <remarks> | ||||||
/// Related to the <see cref="DownstreamHttpVersion"/> property. | ||||||
/// <list type="bullet"> | ||||||
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpversionpolicy">HttpVersionPolicy Enum</see></item> | ||||||
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.httpversion">HttpVersion Class</see></item> | ||||||
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.versionpolicy">HttpRequestMessage.VersionPolicy Property</see></item> | ||||||
/// </list> | ||||||
/// </remarks> | ||||||
public string DownstreamHttpVersionPolicy { get; set; } | ||||||
public string DownstreamPathTemplate { get; set; } | ||||||
public string DownstreamScheme { get; set; } | ||||||
public string DownstreamScheme { get; set; } | ||||||
public FileCacheOptions FileCacheOptions { get; set; } | ||||||
public FileHttpHandlerOptions HttpHandlerOptions { get; set; } | ||||||
public string Key { get; set; } | ||||||
public FileLoadBalancerOptions LoadBalancerOptions { get; set; } | ||||||
public IDictionary<string, string> Metadata { get; set; } | ||||||
public IDictionary<string, string> Metadata { get; set; } | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
public bool RouteIsCaseSensitive { get; set; } | ||||||
public FileSecurityOptions SecurityOptions { get; set; } | ||||||
public string ServiceName { get; set; } | ||||||
|
@@ -103,14 +103,14 @@ public static void DeepCopy(FileRoute from, FileRoute to) | |||||
to.DownstreamHostAndPorts = from.DownstreamHostAndPorts.Select(x => new FileHostAndPort(x)).ToList(); | ||||||
to.DownstreamHttpMethod = from.DownstreamHttpMethod; | ||||||
to.DownstreamHttpVersion = from.DownstreamHttpVersion; | ||||||
to.DownstreamHttpVersionPolicy = from.DownstreamHttpVersionPolicy; | ||||||
to.DownstreamHttpVersionPolicy = from.DownstreamHttpVersionPolicy; | ||||||
to.DownstreamPathTemplate = from.DownstreamPathTemplate; | ||||||
to.DownstreamScheme = from.DownstreamScheme; | ||||||
to.DownstreamScheme = from.DownstreamScheme; | ||||||
to.FileCacheOptions = new(from.FileCacheOptions); | ||||||
to.HttpHandlerOptions = new(from.HttpHandlerOptions); | ||||||
to.Key = from.Key; | ||||||
to.LoadBalancerOptions = new(from.LoadBalancerOptions); | ||||||
to.Metadata = new Dictionary<string, string>(from.Metadata); | ||||||
to.Metadata = new Dictionary<string, string>(from.Metadata); | ||||||
to.Priority = from.Priority; | ||||||
to.QoSOptions = new(from.QoSOptions); | ||||||
to.RateLimitOptions = new(from.RateLimitOptions); | ||||||
|
@@ -127,5 +127,5 @@ public static void DeepCopy(FileRoute from, FileRoute to) | |||||
to.UpstreamHttpMethod = new(from.UpstreamHttpMethod); | ||||||
to.UpstreamPathTemplate = from.UpstreamPathTemplate; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
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.