removed thing that checks if route is authorised cos we dont need it

This commit is contained in:
tom.pallister
2016-10-14 20:08:09 +01:00
parent 8c194a365b
commit f545ba8620
18 changed files with 93 additions and 210 deletions

View File

@@ -1,11 +0,0 @@
namespace Ocelot.Library.Infrastructure.Authentication
{
using Responses;
public class CouldNotFindConfigurationError : Error
{
public CouldNotFindConfigurationError(string message)
: base(message)
{
}
}
}

View File

@@ -1,10 +0,0 @@
namespace Ocelot.Library.Infrastructure.Authentication
{
using DownstreamRouteFinder;
using Responses;
public interface IRouteRequiresAuthentication
{
Response<bool> IsAuthenticated(DownstreamRoute downstreamRoute, string httpMethod);
}
}

View File

@@ -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);
}
}
}

View 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);
}
}
}

View File

@@ -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));
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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));
}
}

View File

@@ -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)
{