Ejemplo n.º 1
0
 public SecurityBase(ICloudFoundryOptions options, IManagementOptions mgmtOptions, ILogger logger = null, HttpClient httpClient = null)
 {
     _options     = options;
     _mgmtOptions = mgmtOptions;
     _logger      = logger;
     _httpClient  = httpClient;
 }
Ejemplo n.º 2
0
 public CloudFoundrySecurity(ICloudFoundryOptions options, IManagementOptions managementOptions, ILogger <CloudFoundrySecurity> logger = null)
 {
     _options           = options;
     _managementOptions = managementOptions;
     _logger            = logger;
     _base = new SecurityBase(options, managementOptions, logger);
 }
Ejemplo n.º 3
0
        public static bool ShouldInvoke(this IEndpoint endpoint, IManagementOptions mgmtContext, ILogger logger = null)
        {
            var enabled = endpoint.IsEnabled(mgmtContext);
            var exposed = endpoint.IsExposed(mgmtContext);

            logger?.LogDebug($"endpoint: {endpoint.Id}, contextPath: {mgmtContext.Path}, enabled: {enabled}, exposed: {exposed}");
            return(enabled && exposed);
        }
 public CloudFoundrySecurityOwinMiddleware(OwinMiddleware next, ICloudFoundryOptions options, IEnumerable <IManagementOptions> mgmtOptions, ILogger <CloudFoundrySecurityOwinMiddleware> logger = null)
     : base(next)
 {
     _options     = options;
     _logger      = logger;
     _mgmtOptions = mgmtOptions.OfType <CloudFoundryManagementOptions>().Single();
     _base        = new SecurityBase(options, _mgmtOptions, logger);
 }
        public CloudFoundrySecurityMiddleware(RequestDelegate next, ICloudFoundryOptions options, IEnumerable <IManagementOptions> mgmtOptions, ILogger <CloudFoundrySecurityMiddleware> logger = null)
        {
            _next        = next;
            _logger      = logger;
            _options     = options;
            _mgmtOptions = mgmtOptions?.OfType <CloudFoundryManagementOptions>().SingleOrDefault();

            _base = new SecurityBase(options, _mgmtOptions, logger);
        }
        public CloudFoundrySecurityMiddleware(RequestDelegate next, ICloudFoundryOptions options, CloudFoundryManagementOptions mgmtOptions, ILogger <CloudFoundrySecurityMiddleware> logger = null)
        {
            _next        = next;
            _logger      = logger;
            _options     = options;
            _mgmtOptions = mgmtOptions;

            _base = new SecurityBase(options, _mgmtOptions, logger);
        }
Ejemplo n.º 7
0
        public static bool RequestVerbAndPathMatch(this IEndpoint endpoint, string httpMethod, string requestPath, IEnumerable <HttpMethod> allowedMethods, IEnumerable <IManagementOptions> mgmtOptions, bool exactMatch)
        {
            IManagementOptions matchingMgmtContext = null;

            return(endpoint.RequestPathMatches(requestPath, mgmtOptions, out matchingMgmtContext, exactMatch) &&
                   endpoint.IsEnabled(matchingMgmtContext) &&
                   endpoint.IsExposed(matchingMgmtContext) &&
                   allowedMethods.Any(m => m.Method.Equals(httpMethod)));
        }
Ejemplo n.º 8
0
 public EndpointMiddleware(IManagementOptions mgmtOptions, ILogger logger = null)
 {
     _logger      = logger;
     _mgmtOptions = mgmtOptions ?? throw new ArgumentNullException(nameof(mgmtOptions));
     if (_mgmtOptions is ManagementEndpointOptions mgmt)
     {
         mgmt.SerializerOptions = GetSerializerOptions(mgmt.SerializerOptions);
     }
 }
Ejemplo n.º 9
0
        public static bool IsEnabled(this IEndpointOptions options, IManagementOptions mgmtOptions)
        {
            var endpointOptions = (AbstractEndpointOptions)options;

            if (endpointOptions.Enabled.HasValue)
            {
                return(endpointOptions.Enabled.Value);
            }

            if (mgmtOptions.Enabled.HasValue)
            {
                return(mgmtOptions.Enabled.Value);
            }

            return(endpointOptions.DefaultEnabled);
        }
Ejemplo n.º 10
0
        public CloudFoundryEndpoint(ICloudFoundryOptions options, CloudFoundryManagementOptions mgmtOptions, ILogger <CloudFoundryEndpoint> logger = null)
            : base(options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _mgmtOption = mgmtOptions;

            if (_mgmtOption == null)
            {
                throw new ArgumentNullException(nameof(mgmtOptions));
            }

            _logger = logger;
        }
Ejemplo n.º 11
0
        public CloudFoundryEndpoint(ICloudFoundryOptions options, IEnumerable <IManagementOptions> mgmtOptions, ILogger <CloudFoundryEndpoint> logger = null)
            : base(options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _mgmtOption = mgmtOptions?.OfType <CloudFoundryManagementOptions>().SingleOrDefault();

            if (_mgmtOption == null)
            {
                throw new ArgumentNullException(nameof(mgmtOptions));
            }

            _logger = logger;
        }
 public MappingsEndpointMiddleware(
     RequestDelegate next,
     IMappingsOptions options,
     IManagementOptions mgmtOptions,
     MappingsEndpoint endpoint,
     IRouteMappings routeMappings = null,
     IActionDescriptorCollectionProvider actionDescriptorCollectionProvider = null,
     IEnumerable <IApiDescriptionProvider> apiDescriptionProviders          = null,
     ILogger <MappingsEndpointMiddleware> logger = null)
     : base(endpoint, mgmtOptions, logger: logger)
 {
     _next          = next;
     _options       = options;
     _routeMappings = routeMappings;
     _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
     _apiDescriptionProviders            = apiDescriptionProviders;
 }
Ejemplo n.º 13
0
        public static bool IsExposed(this IEndpointOptions options, IManagementOptions mgmtOptions)
        {
            var actOptions = mgmtOptions as ActuatorManagementOptions;

            if (!string.IsNullOrEmpty(options.Id) && actOptions != null && actOptions.Exposure != null)
            {
                var exclude = actOptions.Exposure.Exclude;
                if (exclude != null && (exclude.Contains("*") || exclude.Contains(options.Id)))
                {
                    return(false);
                }

                var include = actOptions.Exposure.Include;
                if (include != null && (include.Contains("*") || include.Contains(options.Id)))
                {
                    return(true);
                }

                return(false);
            }

            return(true);
        }
Ejemplo n.º 14
0
        public static string GetContextPath(this IEndpointOptions options, IManagementOptions mgmtContext)
        {
            var contextPath = mgmtContext.Path;

            if (!contextPath.EndsWith("/") && !string.IsNullOrEmpty(options.Path))
            {
                contextPath += "/";
            }

            contextPath += options.Path;

            if (!options.ExactMatch)
            {
                if (!contextPath.EndsWith("/"))
                {
                    contextPath += "/";
                }

                contextPath += "{**_}";
            }

            return(contextPath);
        }
Ejemplo n.º 15
0
        private static bool RequestPathMatches(this IEndpoint endpoint, string requestPath, IEnumerable <IManagementOptions> mgmtOptions, out IManagementOptions matchingContext, bool exactMatch = true)
        {
            matchingContext = null;
            var endpointPath = endpoint.Path;

            if (mgmtOptions == null)
            {
                return(exactMatch ? requestPath.Equals(endpointPath) : requestPath.StartsWith(endpointPath));
            }
            else
            {
                foreach (var context in mgmtOptions)
                {
                    var contextPath = context.Path;
                    if (!contextPath.EndsWith("/") && !string.IsNullOrEmpty(endpointPath))
                    {
                        contextPath += "/";
                    }

                    var fullPath = contextPath + endpointPath;
                    if (exactMatch ? requestPath.Equals(fullPath) : requestPath.StartsWith(fullPath))
                    {
                        matchingContext = context;
                        return(true);
                    }
                }

                return(false);
            }
        }
Ejemplo n.º 16
0
 public static bool IsExposed(this IEndpoint endpoint, IManagementOptions mgmtContext)
 {
     return(mgmtContext == null ? true : endpoint.Options.IsExposed(mgmtContext));
 }
Ejemplo n.º 17
0
 public static bool IsEnabled(this IEndpoint endpoint, IManagementOptions mgmtContext)
 {
     return(mgmtContext == null ? endpoint.Enabled : endpoint.Options.IsEnabled(mgmtContext));
 }
 public ActuatorSecurityMiddlewareTest(IManagementOptions mopts)
 {
     Environment.SetEnvironmentVariable("VCAP_APPLICATION", "somestuff");
     _base = new SecurityBase(new CloudFoundryEndpointOptions(), mopts);
 }
 public ActuatorSecurityMiddlewareTest(IManagementOptions mopts)
 {
     Environment.SetEnvironmentVariable("VCAP_APPLICATION", "somestuff");
 }
Ejemplo n.º 20
0
 public TestMiddleware2(IEndpoint <string, string> endpoint, IManagementOptions mgmtOptions, ILogger logger)
     : base(endpoint, mgmtOptions, logger: logger)
 {
 }
Ejemplo n.º 21
0
 public ActuatorEndpoint(IActuatorHypermediaOptions options, IEnumerable <IManagementOptions> mgmtOptions, ILogger <ActuatorEndpoint> logger = null)
     : base(options)
 {
     _mgmtOption = mgmtOptions?.OfType <ActuatorManagementOptions>().Single();
     _logger     = logger;
 }
Ejemplo n.º 22
0
 public LoggersEndpointMiddleware(RequestDelegate next, LoggersEndpoint endpoint, IManagementOptions mgmtOptions, ILogger <LoggersEndpointMiddleware> logger = null)
     : base(endpoint, mgmtOptions, logger)
 {
     _next = next;
 }
Ejemplo n.º 23
0
 public ThreadDumpEndpointMiddleware(RequestDelegate next, ThreadDumpEndpoint endpoint, IManagementOptions mgmtOptions, ILogger <ThreadDumpEndpointMiddleware> logger = null)
     : base(endpoint, mgmtOptions, logger: logger)
 {
     _next = next;
 }
Ejemplo n.º 24
0
 public EndpointMiddleware(IManagementOptions mgmtOptions, ILogger logger = null)
 {
     _logger      = logger;
     _mgmtOptions = mgmtOptions ?? throw new ArgumentNullException(nameof(mgmtOptions));
 }
Ejemplo n.º 25
0
 public HypermediaService(IManagementOptions mgmtOptions, IEndpointOptions options, ILogger logger = null)
 {
     _logger      = logger;
     _mgmtOptions = mgmtOptions ?? throw new ArgumentNullException(nameof(mgmtOptions));
     _options     = options ?? throw new ArgumentNullException(nameof(options));
 }
Ejemplo n.º 26
0
 public EndpointMiddleware(IEndpoint <TResult> endpoint, IManagementOptions mgmtOptions, ILogger logger = null)
 {
     _logger      = logger;
     _endpoint    = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     _mgmtOptions = mgmtOptions ?? throw new ArgumentNullException(nameof(mgmtOptions));
 }
Ejemplo n.º 27
0
 public CloudFoundryEndpointMiddleware(RequestDelegate next, CloudFoundryEndpoint endpoint, IManagementOptions mgmtOptions, ILogger <CloudFoundryEndpointMiddleware> logger = null)
     : base(endpoint, mgmtOptions, logger: logger)
 {
     _next    = next;
     _options = endpoint.Options as ICloudFoundryOptions;
 }
 public HealthEndpointMiddleware(RequestDelegate next, IManagementOptions mgmtOptions, ILogger <InfoEndpointMiddleware> logger = null)
     : base(mgmtOptions: mgmtOptions, logger: logger)
 {
     _next = next;
 }
Ejemplo n.º 29
0
 public PrometheusScraperEndpointMiddleware(RequestDelegate next, PrometheusScraperEndpoint endpoint, IManagementOptions mgmtOptions, ILogger <PrometheusScraperEndpointMiddleware> logger = null)
     : base(endpoint, mgmtOptions, logger)
 {
     _next = next;
 }