public async Task Handle(HttpContext context, ConfigServerOptions options) { if (!CheckMethodAndAuthentication(context, options)) { return; } // clientId/ConfigSet.json // clientId/ConfigSet/Config.json var pathParams = context.ToPathParams(); if (pathParams.Length < 2) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configClientService.GetClientOrDefault(pathParams[0]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } var payload = await GetPayloadOrDefault(pathParams, client); if (payload == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else { await httpResponseFactory.BuildJsonFileResponse(context, payload.Payload, payload.FileName); } }
public static bool ChallengeClientConfigurator(this HttpContext source, ConfigServerOptions option, ConfigurationClient client, IHttpResponseFactory responseFactory) { if (client == null) { responseFactory.BuildNotFoundStatusResponse(source); return(false); } if (string.IsNullOrWhiteSpace(option.ClientConfiguratorClaimType) || string.IsNullOrWhiteSpace(client.ConfiguratorClaim)) { return(source.ChallengeAuthentication(option.AllowManagerAnomynousAccess, responseFactory)); } //If we have an expected claim then we do not want to allow anomynous if (!source.ChallengeAuthentication(false, responseFactory)) { return(false); } if (!source.HasClaim(option.ClientConfiguratorClaimType, client.ConfiguratorClaim)) { responseFactory.BuildStatusResponse(source, 403); return(false); } return(true); }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // Model/{ Client Id}/{ Configuration Set} // GET: Model for configuration set if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 2) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configClientService.GetClientOrDefault(pathParams[0]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } var configSet = configCollection.SingleOrDefault(c => pathParams[1].Equals(c.ConfigSetType.Name, StringComparison.OrdinalIgnoreCase)); if (configSet == null) { return; } await httpResponseFactory.BuildJsonResponse(context, await modelPayloadMapper.Map(configSet, new ConfigurationIdentity(client, configCollection.GetVersion()))); return; }
public async Task Handle(HttpContext context, ConfigServerOptions options) { if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 2) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configurationClientService.GetClientOrDefault(pathParams[0]); if (!context.ChallengeClientRead(options, client, httpResponseFactory)) { return; } var config = await router.GetConfigInstanceOrDefault(client, pathParams[1]); if (config == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else { await httpResponseFactory.BuildJsonResponse(context, config.GetConfiguration()); } }
private UserPermissions GetPermissionFromPrincipal(ClaimsPrincipal user, ConfigServerOptions options) { var result = new UserPermissions(); if (AllowAnomynousClientAdmin(options)) { result.CanAccessClientAdmin = true; result.CanEditClients = true; result.CanEditGroups = true; result.CanDeleteArchives = true; } if (user.HasClaim(s => s.Type.Equals(options.ClientAdminClaimType, StringComparison.OrdinalIgnoreCase) && ConfigServerConstants.AdminClaimValue.Equals(s.Value, StringComparison.OrdinalIgnoreCase))) { result.CanAccessClientAdmin = true; result.CanEditClients = true; result.CanEditGroups = true; result.CanDeleteArchives = true; } if (!result.CanAccessClientAdmin && user.HasClaim(s => s.Type.Equals(options.ClientAdminClaimType, StringComparison.OrdinalIgnoreCase) && ConfigServerConstants.ConfiguratorClaimValue.Equals(s.Value, StringComparison.OrdinalIgnoreCase))) { result.CanAccessClientAdmin = true; } result.ClientConfiguratorClaims = user.Claims.Where(w => w.Type.Equals(options.ClientConfiguratorClaimType, StringComparison.OrdinalIgnoreCase)) .Select(s => s.Value) .ToArray(); return(result); }
public static bool ChallengeClientRead(this HttpContext source, ConfigServerOptions option, ConfigurationClient client, IHttpResponseFactory responseFactory) { if (client == null) { responseFactory.BuildNotFoundStatusResponse(source); return(false); } if (string.IsNullOrWhiteSpace(option.ClientReadClaimType) || string.IsNullOrWhiteSpace(client.ReadClaim)) { return(source.ChallengeAuthentication(option.AllowAnomynousAccess, responseFactory)); } //If we have an expected claim then we do not want to allow anomynous if (!source.ChallengeAuthentication(false, responseFactory)) { return(false); } if (!source.User.HasClaim(c => option.ClientReadClaimType.Equals(c.Type, StringComparison.OrdinalIgnoreCase) && client.ReadClaim.Equals(c.Value, StringComparison.OrdinalIgnoreCase))) { responseFactory.BuildStatusResponse(source, 403); return(false); } return(true); }
public Task Handle(HttpContext context, ConfigServerOptions options) { // GET Gets All Groups // POST Update Groups // /{GroupId} GET // /{GroupId}/Clients GET // /None/Clients GET if (!CheckMethodAndAuthentication(context, options)) { return(Task.FromResult(true)); } var pathParams = context.ToPathParams(); switch (pathParams.Length) { case 0: return(HandleEmptyPath(context)); case 1: return(HandleGroupPath(context, pathParams[0])); case 2: return(string.Equals(pathParams[1], groupClientsPath, StringComparison.OrdinalIgnoreCase) ? HandleGroupClientPath(context, pathParams[0], options) : HandleNotFound(context)); default: return(HandleNotFound(context)); } }
public Task Handle(HttpContext context, ConfigServerOptions options) { // / POST Save snapshot // /{snapShotId}DELETE: Deletes snapShot // /Group/{clientGroupId} GET: Gets SnapshotIds for clientGroupId // /{snapShotId}/to/{clientId} if (!CheckMethodAndAuthentication(context, options)) { return(Task.FromResult(true)); } var pathParams = context.ToPathParams(); switch (pathParams.Length) { case 0: return(HandleSaveSnapshot(context, options)); case 1: return(HandleDeleteSnapshot(context, pathParams[0], options)); case 2: return(HandleGetSnapshotForGroup(context, pathParams, options)); case 3: return(HandlePushSnapshotToClient(context, pathParams, options)); default: httpResponseFactory.BuildNotFoundStatusResponse(context); return(Task.FromResult(true)); } }
public static bool CheckClientWrite(this HttpContext source, ConfigServerOptions option, ConfigurationClient client) { if (string.IsNullOrWhiteSpace(option.ClientReadClaimType) || string.IsNullOrWhiteSpace(client.ConfiguratorClaim)) { return(true); } return(source.HasClaim(option.ClientConfiguratorClaimType, client.ConfiguratorClaim)); }
private static string GetThemeUrl(string basePath, ConfigServerOptions options) { if (string.IsNullOrWhiteSpace(options.ThemeUrl)) { return($"{basePath}/Assets/lib/deeppurple-amber.css"); } return(options.ThemeUrl); }
private async Task HandleClientPath(HttpContext context, string clientId, ConfigServerOptions options) { var client = await configurationClientService.GetClientOrDefault(clientId); if (context.ChallengeClientConfiguratorOrAdmin(options, client, httpResponseFactory)) { await httpResponseFactory.BuildJsonResponse(context, Map(client)); } }
private bool CheckMethodAndAuthentication(HttpContext context, ConfigServerOptions options) { if (context.Request.Method == "POST") { return(context.ChallengeUser(options.ClientAdminClaimType, new HashSet <string>(new[] { ConfigServerConstants.AdminClaimValue, ConfigServerConstants.ConfiguratorClaimValue }, StringComparer.OrdinalIgnoreCase), options.AllowManagerAnomynousAccess, httpResponseFactory)); } httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return(false); }
public Task Handle(HttpContext context, ConfigServerOptions options) { var managerPath = context.Request.PathBase.Value; var basePath = GetBasePath(managerPath); if (!CheckMethodAndAuthentication(context, options)) { return(Task.FromResult(true)); } return(context.Response.WriteAsync(Shell(basePath, managerPath, options))); }
private bool CheckMethodAndAuthentication(HttpContext context, ConfigServerOptions options) { if (context.Request.Method == "GET") { return(true); } else { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return(false); } }
private bool CheckMethodAndAuthentication(HttpContext context, ConfigServerOptions options) { if (context.Request.Method == "GET") { return(context.ChallengeAuthentication(options.AllowAnomynousAccess, httpResponseFactory)); } else { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return(false); } }
private async Task HandleSaveSnapshot(HttpContext context, ConfigServerOptions options) { if (context.Request.Method != "POST") { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return; } var command = await context.GetObjectFromJsonBodyAsync <CreateSnapshotCommand>(); var commmandResult = await commandBus.SubmitAsync(command); await httpResponseFactory.BuildResponseFromCommandResult(context, commmandResult); }
public async Task Handle(HttpContext context, ConfigServerOptions options) { var pathParams = context.ToPathParams(); // /{id} // /{id}/{resource} // /{id}/to/{id} if (!CheckMethodAndAuthentication(context, options, pathParams)) { return; } if (pathParams.Length == 0 || pathParams.Length > 3) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var clientIdentity = await GetIdentityFromPathOrDefault(pathParams[0]); if (clientIdentity == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } switch (pathParams.Length) { case 1: await GetResourceCatalogue(context, clientIdentity, options); break; case 2: await HandleTwoParams(context, pathParams, clientIdentity, options); break; case 3: await TransferResource(context, pathParams, clientIdentity, options); break; default: httpResponseFactory.BuildNotFoundStatusResponse(context); break; } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { var param = context.ToPathParams(); if (param.Length != 0) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else if (context.Request.Method != "POST") { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); } else { await httpResponseFactory.BuildJsonResponse(context, Guid.NewGuid()); } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // /ConfigurationSet/{clientId}/{Configuration Set} // POST: Uploads configuration set file // /Configuration/{clientId}/{Config name} // POST: Uploads configuration file // /Editor/{clientId}/{Config name} // POST: Uploads configuration file if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 3) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configClientService.GetClientOrDefault(pathParams[1]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } if (pathParams[0].Equals("Configuration", StringComparison.OrdinalIgnoreCase)) { await HandleUploadConfiguration(context, pathParams[2], client); } else if (pathParams[0].Equals("ConfigurationSet", StringComparison.OrdinalIgnoreCase)) { await HandleUploadConfigurationSet(context, pathParams[2], client); } else if (pathParams[0].Equals("Editor", StringComparison.OrdinalIgnoreCase)) { await HandleUploadToEditor(context, pathParams[2], client); } else { httpResponseFactory.BuildNotFoundStatusResponse(context); } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // /{ Client Id}/{ config name} // GET: Gets Config model for editor // POST: Sets Config from editor model if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 2) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configClientService.GetClientOrDefault(pathParams[0]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } switch (context.Request.Method) { case "GET": await HandleGetRequest(context, client, pathParams[1]); break; case "POST": await HandlePostRequest(context, client, pathParams[1]); break; default: httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } return; }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // GET: Gets all configuration set summaries if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length == 0) { await httpResponseFactory.BuildJsonResponse(context, GetConfigurationSetSummaries()); return; } httpResponseFactory.BuildNotFoundStatusResponse(context); return; }
public async Task Handle(HttpContext context, ConfigServerOptions options) { if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 0) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var tags = registry.Select(model => model.RequiredClientTag).Where(model => model != null).Distinct().OrderBy(o => o.Value); await httpResponseFactory.BuildJsonResponse(context, tags); return; }
private async Task HandleEmptyPath(HttpContext context, ConfigServerOptions options) { switch (context.Request.Method) { case "GET": await httpResponseFactory.BuildJsonResponse(context, await GetAllClients(context, options)); break; case "POST": await HandlePost(context); break; default: httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } }
private string Shell(string basePath, string managerPath, ConfigServerOptions options) => $@" <html> <head> <title>Configuration manager</title> <meta charset=""UTF-8""> <meta name = ""viewport"" content=""width=device-width, initial-scale=1""> <link href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"" rel=""stylesheet"" /> <link href=""{GetThemeUrl(basePath, options)}"" rel=""stylesheet"" /> <link rel = ""stylesheet"" href=""{basePath}/Assets/styles.css""> <base href=""{managerPath}"" /> </head> <!-- 3. Display the application --> <body> <config-server-shell>Loading...</config-server-shell> <script type=""text/javascript"" src=""{basePath}/Assets/runtime.js""></script> <script type = ""text/javascript"" src=""{basePath}/Assets/polyfills.js""></script> <script type = ""text/javascript"" src=""{basePath}/Assets/main.js""></script> </body> </html> ";
public async Task Handle(HttpContext context, ConfigServerOptions options) { // /{id} GET // /{id}/{resource} DELETE GET // /{id}?before={date} DELETE if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length == 0 || pathParams.Length > 2) { httpResponseFactory.BuildStatusResponse(context, StatusCodes.Status404NotFound); return; } var clientIdentity = await GetIdentityFromPathOrDefault(pathParams[0]); if (clientIdentity == null) { httpResponseFactory.BuildStatusResponse(context, StatusCodes.Status404NotFound); return; } if (pathParams.Length == 1) { await HandleSingleParam(context, options, clientIdentity); return; } else { await HandleTwoParams(context, pathParams, options, clientIdentity); } return; }
private async Task HandleTwoParams(HttpContext context, string[] pathParams, ConfigServerOptions options, ConfigurationIdentity clientIdentity) { switch (context.Request.Method) { case "GET": { if (!context.ChallengeClientConfigurator(options, clientIdentity.Client, httpResponseFactory)) { break; } var result = await resourceArchive.GetArchiveResource(pathParams[1], clientIdentity); if (!result.HasEntry) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else { await httpResponseFactory.BuildFileResponse(context, result.Content, result.Name); } break; } case "DELETE": { await resourceArchive.DeleteArchiveResource(pathParams[1], clientIdentity); httpResponseFactory.BuildNoContentResponse(context); break; } default: { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { if (context.Request.Method != "GET") { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return; } var permissions = GetPermissionFromPrincipal(context.User, options); var pathParams = context.ToPathParams(); if (pathParams.Length == 0) { await httpResponseFactory.BuildJsonResponse(context, permissions); } else { var client = await clientService.GetClientOrDefault(pathParams[0]); var clientPermission = MapToClientPermission(permissions, client); await httpResponseFactory.BuildJsonResponse(context, clientPermission); } }
private async Task HandleSingleParam(HttpContext context, ConfigServerOptions options, ConfigurationIdentity clientIdentity) { switch (context.Request.Method) { case "GET": { if (!context.ChallengeClientConfiguratorOrAdmin(options, clientIdentity.Client, httpResponseFactory)) { break; } var clientResourceCatalogue = await resourceArchive.GetArchiveResourceCatalogue(clientIdentity); await httpResponseFactory.BuildJsonResponse(context, clientResourceCatalogue); break; } case "DELETE": { if (context.Request.Query.TryGetValue("before", out var pram) && DateTime.TryParse(pram, out var dateParam)) { await resourceArchive.DeleteOldArchiveResources(dateParam, clientIdentity); httpResponseFactory.BuildNoContentResponse(context); break; } httpResponseFactory.BuildNotFoundStatusResponse(context); break; } default: { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } } }
public Task Handle(HttpContext context, ConfigServerOptions options) { // GET Gets All // POST Update Client // /{ClientId} GET if (!CheckMethodAndAuthentication(context, options)) { return(Task.FromResult(true)); } var pathParams = context.ToPathParams(); switch (pathParams.Length) { case 0: return(HandleEmptyPath(context, options)); case 1: return(HandleClientPath(context, pathParams[0], options)); default: return(HandleNotFound(context)); } }
private bool AllowAnomynousClientAdmin(ConfigServerOptions options) { return(options.AllowManagerAnomynousAccess && string.IsNullOrWhiteSpace(options.ClientAdminClaimType)); }