mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-12-24 12:05:47 +08:00
removed thing that checks if route is authorised cos we dont need it
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
using Responses;
|
||||
public class CouldNotFindConfigurationError : Error
|
||||
{
|
||||
public CouldNotFindConfigurationError(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
using DownstreamRouteFinder;
|
||||
using Responses;
|
||||
|
||||
public interface IRouteRequiresAuthentication
|
||||
{
|
||||
Response<bool> IsAuthenticated(DownstreamRoute downstreamRoute, string httpMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Configuration;
|
||||
using DownstreamRouteFinder;
|
||||
using Responses;
|
||||
|
||||
public class RouteRequiresAuthentication : IRouteRequiresAuthentication
|
||||
{
|
||||
private readonly IOcelotConfiguration _configuration;
|
||||
|
||||
public RouteRequiresAuthentication(IOcelotConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public Response<bool> IsAuthenticated(DownstreamRoute downstreamRoute, string httpMethod)
|
||||
{
|
||||
var reRoute =
|
||||
_configuration.ReRoutes.FirstOrDefault(
|
||||
x =>
|
||||
x.DownstreamTemplate == downstreamRoute.DownstreamUrlTemplate &&
|
||||
string.Equals(x.UpstreamHttpMethod, httpMethod, StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
if (reRoute == null)
|
||||
{
|
||||
return new ErrorResponse<bool>(new List<Error> {new CouldNotFindConfigurationError($"Could not find configuration for {downstreamRoute.DownstreamUrlTemplate} using method {httpMethod}")});
|
||||
}
|
||||
|
||||
return new OkResponse<bool>(reRoute.IsAuthenticated);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/Ocelot.Library/Infrastructure/Builder/ReRouteBuilder.cs
Normal file
47
src/Ocelot.Library/Infrastructure/Builder/ReRouteBuilder.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Ocelot.Library.Infrastructure.Builder
|
||||
{
|
||||
using Configuration;
|
||||
|
||||
public class ReRouteBuilder
|
||||
{
|
||||
private string _downstreamTemplate;
|
||||
private string _upstreamTemplate;
|
||||
private string _upstreamTemplatePattern;
|
||||
private string _upstreamHttpMethod;
|
||||
private bool _isAuthenticated;
|
||||
private string _authenticationProvider;
|
||||
|
||||
public void WithDownstreamTemplate(string input)
|
||||
{
|
||||
_downstreamTemplate = input;
|
||||
}
|
||||
|
||||
public void WithUpstreamTemplate(string input)
|
||||
{
|
||||
_upstreamTemplate = input;
|
||||
}
|
||||
|
||||
public void WithUpstreamTemplatePattern(string input)
|
||||
{
|
||||
_upstreamTemplatePattern = input;
|
||||
}
|
||||
public void WithUpstreamHttpMethod(string input)
|
||||
{
|
||||
_upstreamHttpMethod = input;
|
||||
}
|
||||
public void WithIsAuthenticated(bool input)
|
||||
{
|
||||
_isAuthenticated = input;
|
||||
|
||||
}
|
||||
public void WithAuthenticationProvider(string input)
|
||||
{
|
||||
_authenticationProvider = input;
|
||||
}
|
||||
|
||||
public ReRoute Build()
|
||||
{
|
||||
return new ReRoute(_downstreamTemplate, _upstreamTemplate, _upstreamHttpMethod, _upstreamTemplatePattern, _isAuthenticated, _authenticationProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Ocelot.Library.Infrastructure.Configuration
|
||||
|
||||
var isAuthenticated = !string.IsNullOrEmpty(reRoute.Authentication);
|
||||
|
||||
_reRoutes.Add(new ReRoute(reRoute.DownstreamTemplate, reRoute.UpstreamTemplate, reRoute.UpstreamHttpMethod, upstreamTemplate, isAuthenticated));
|
||||
_reRoutes.Add(new ReRoute(reRoute.DownstreamTemplate, reRoute.UpstreamTemplate, reRoute.UpstreamHttpMethod, upstreamTemplate, isAuthenticated, reRoute.Authentication));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
{
|
||||
public class ReRoute
|
||||
{
|
||||
public ReRoute(string downstreamTemplate, string upstreamTemplate, string upstreamHttpMethod, string upstreamTemplatePattern, bool isAuthenticated)
|
||||
public ReRoute(string downstreamTemplate, string upstreamTemplate, string upstreamHttpMethod, string upstreamTemplatePattern, bool isAuthenticated, string authenticationProvider)
|
||||
{
|
||||
DownstreamTemplate = downstreamTemplate;
|
||||
UpstreamTemplate = upstreamTemplate;
|
||||
UpstreamHttpMethod = upstreamHttpMethod;
|
||||
UpstreamTemplatePattern = upstreamTemplatePattern;
|
||||
IsAuthenticated = isAuthenticated;
|
||||
AuthenticationProvider = authenticationProvider;
|
||||
}
|
||||
|
||||
public string DownstreamTemplate { get; private set; }
|
||||
@@ -16,5 +17,6 @@
|
||||
public string UpstreamTemplatePattern { get; private set; }
|
||||
public string UpstreamHttpMethod { get; private set; }
|
||||
public bool IsAuthenticated { get; private set; }
|
||||
public string AuthenticationProvider { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,16 @@ using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
|
||||
{
|
||||
using Configuration;
|
||||
|
||||
public class DownstreamRoute
|
||||
{
|
||||
public DownstreamRoute(List<TemplateVariableNameAndValue> templateVariableNameAndValues, string downstreamUrlTemplate)
|
||||
public DownstreamRoute(List<TemplateVariableNameAndValue> templateVariableNameAndValues, ReRoute reRoute)
|
||||
{
|
||||
TemplateVariableNameAndValues = templateVariableNameAndValues;
|
||||
DownstreamUrlTemplate = downstreamUrlTemplate;
|
||||
ReRoute = reRoute;
|
||||
}
|
||||
public List<TemplateVariableNameAndValue> TemplateVariableNameAndValues { get; private set; }
|
||||
public string DownstreamUrlTemplate { get; private set; }
|
||||
public ReRoute ReRoute { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
|
||||
var templateVariableNameAndValues = _templateVariableNameAndValueFinder.Find(upstreamUrlPath,
|
||||
template.UpstreamTemplate);
|
||||
|
||||
return new OkResponse<DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, template.DownstreamTemplate));
|
||||
return new OkResponse<DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, template));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer
|
||||
{
|
||||
var upstreamUrl = new StringBuilder();
|
||||
|
||||
upstreamUrl.Append(downstreamRoute.DownstreamUrlTemplate);
|
||||
upstreamUrl.Append(downstreamRoute.ReRoute.DownstreamTemplate);
|
||||
|
||||
foreach (var templateVarAndValue in downstreamRoute.TemplateVariableNameAndValues)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user