public ProviderValidator FetchProviderValidator(string wellknownAuthority) { if (WellknownAuthorities.AuthoritiesMap.ContainsKey(wellknownAuthority)) { if (_providerValidators.ContainsKey(wellknownAuthority)) { return(_providerValidators[wellknownAuthority]); } try { var container = new OpenIdConnectDiscoverCacheContainer( WellknownAuthorities.AuthoritiesMap[wellknownAuthority], _defaultHttpClientFactory.HttpMessageHandler); container.DiscoveryCache.Refresh(); var providerValidator = new ProviderValidator(container, _cache); _providerValidators.Add(wellknownAuthority, providerValidator); return(providerValidator); } catch (Exception e) { //TODO: log and permanently mark this wellknown as bad } } return(null); }
public virtual async Task <ClaimsPrincipal> ValidateTokenAsync(TokenDescriptor tokenDescriptor) { if (tokenDescriptor.TokenScheme != TokenScheme) { throw new ArgumentException($"{nameof(tokenDescriptor.TokenScheme)} must be {TokenScheme} to use this validator"); } var discoveryContainer = _discoverCacheContainerFactory.Get(tokenDescriptor.TokenScheme); if (discoveryContainer == null) { throw new ArgumentException($"The OIDC AuthorityKey:{nameof(tokenDescriptor.TokenScheme)} is not supported"); } var providerValidator = new ProviderValidator(discoveryContainer, _memoryCache); try { var principal = await providerValidator.ValidateToken(tokenDescriptor.Token, new TokenValidationParameters() { ValidateAudience = false }); return(principal); } catch (Exception e) { throw new Exception("Invalid Binding Token", e); } }
public IdentityController(ConfiguredDiscoverCacheContainerFactory configuredDiscoverCacheContainerFactory, IMemoryCache memoryCache) { _configuredDiscoverCacheContainerFactory = configuredDiscoverCacheContainerFactory; _discoveryContainer = _configuredDiscoverCacheContainerFactory.Get("p7identityserver4"); _memoryCache = memoryCache; _providerValidator = new ProviderValidator(_discoveryContainer, _memoryCache); }
public async Task <IActionResult> Put([FromRoute] string providerId, [FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } if (string.IsNullOrWhiteSpace(providerId)) { return(ErrorResult .BadRequest($"The identifier '{providerId}' provided in the url path is invalid. Must be a valid provider ID.", ResultErrorCode.ValidationError) .ActionResult()); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } if (!providerId.Equals(provider.Id, StringComparison.OrdinalIgnoreCase)) { return(ErrorResult .BadRequest(new ValidationError { Field = "id", Message = $"Provider's id does match the identifier provided in the path." }) .ActionResult()); } var oldProvider = await providersRepository .GetAsync(provider.Id) .ConfigureAwait(false); if (oldProvider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{provider.Id}' could not be found on this TeamCloud Instance.") .ActionResult()); } var currentUserForCommand = await userService .CurrentUserAsync() .ConfigureAwait(false); oldProvider.PopulateFromExternalModel(provider); var command = new OrchestratorProviderUpdateCommand(currentUserForCommand, oldProvider); return(await orchestrator .InvokeAndReturnAccepted(command) .ConfigureAwait(false)); }
public async Task <IActionResult> Put([FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var teamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (teamCloudInstance is null) { return(ErrorResult .NotFound($"No TeamCloud Instance was found.") .ActionResult()); } var oldProvider = teamCloudInstance.Providers?.FirstOrDefault(p => p.Id == provider.Id); if (oldProvider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{provider.Id}' could not be found on this TeamCloud Instance.") .ActionResult()); } var command = new OrchestratorProviderUpdateCommand(CurrentUser, provider); var commandResult = await orchestrator .InvokeAsync(command) .ConfigureAwait(false); if (commandResult.Links.TryGetValue("status", out var statusUrl)) { return(StatusResult .Accepted(commandResult.CommandId.ToString(), statusUrl, commandResult.RuntimeStatus.ToString(), commandResult.CustomStatus) .ActionResult()); } throw new Exception("This shoudn't happen, but we need to decide to do when it does."); }
public async Task <IActionResult> Post([FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var teamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (teamCloudInstance is null) { return(ErrorResult .NotFound($"No TeamCloud Instance was found.") .ActionResult()); } if (teamCloudInstance.Providers.Contains(provider)) { return(ErrorResult .Conflict($"A Provider with the ID '{provider.Id}' already exists on this TeamCloud Instance. Please try your request again with a unique ID or call PUT to update the existing Provider.") .ActionResult()); } var command = new OrchestratorProviderCreateCommand(CurrentUser, provider); var commandResult = await orchestrator .InvokeAsync(command) .ConfigureAwait(false); if (commandResult.Links.TryGetValue("status", out var statusUrl)) { return(StatusResult .Accepted(commandResult.CommandId.ToString(), statusUrl, commandResult.RuntimeStatus.ToString(), commandResult.CustomStatus) .ActionResult()); } throw new Exception("This shoudn't happen, but we need to decide to do when it does."); }
public async Task <IActionResult> Post([FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var existingProvider = await providersRepository .GetAsync(provider.Id) .ConfigureAwait(false); if (existingProvider != null) { return(ErrorResult .Conflict($"A Provider with the ID '{provider.Id}' already exists on this TeamCloud Instance. Please try your request again with a unique ID or call PUT to update the existing Provider.") .ActionResult()); } var currentUserForCommand = await userService .CurrentUserAsync() .ConfigureAwait(false); var commandProvider = new TeamCloud.Model.Internal.Data.Provider(); commandProvider.PopulateFromExternalModel(provider); var command = new OrchestratorProviderCreateCommand(currentUserForCommand, commandProvider); return(await orchestrator .InvokeAndReturnAccepted(command) .ConfigureAwait(false)); }
public async Task <IActionResult> Put([FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var oldProvider = await providersRepository .GetAsync(provider.Id) .ConfigureAwait(false); if (oldProvider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{provider.Id}' could not be found on this TeamCloud Instance.") .ActionResult()); } var currentUserForCommand = await userService .CurrentUserAsync() .ConfigureAwait(false); oldProvider.PopulateFromExternalModel(provider); var command = new OrchestratorProviderUpdateCommand(currentUserForCommand, oldProvider); return(await orchestrator .InvokeAndReturnAccepted(command) .ConfigureAwait(false)); }
public async Task <string> AddProviders(ProviderDTO provider) { var x = _mapper.Map <ProviderDTO, Provider>(provider); ProviderValidator validator = new ProviderValidator(); ValidationResult results = validator.Validate(x); if (!results.IsValid) { foreach (var failure in results.Errors) { string error = ("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage); return(error); } return("Error"); } else { await _eFUnitOfWork.EFProviderRepository.Add(x); return("Постачальника успішно добавлено!"); } }
public async Task <IActionResult> Post([FromBody] Provider provider) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } var validation = new ProviderValidator().Validate(provider); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ToActionResult()); } var providerDocument = await ProviderRepository .GetAsync(provider.Id) .ConfigureAwait(false); if (providerDocument != null) { return(ErrorResult .Conflict($"A Provider with the ID '{provider.Id}' already exists on this TeamCloud Instance. Please try your request again with a unique ID or call PUT to update the existing Provider.") .ToActionResult()); } if (provider.Type == ProviderType.Virtual) { var serviceProviders = await ProviderRepository .ListAsync(providerType : ProviderType.Service) .ToListAsync() .ConfigureAwait(false); var serviceProvider = serviceProviders .FirstOrDefault(p => provider.Id.StartsWith($"{p.Id}.", StringComparison.Ordinal)); if (serviceProvider is null) { var validServiceProviderIds = string.Join(", ", serviceProviders.Select(p => p.Id)); return(ErrorResult .BadRequest(new ValidationError { Field = "id", Message = $"No matching service provider found. Virtual provider ids must begin with the associated Service provider id followed by a period (.). Available service providers: {validServiceProviderIds}" }) .ToActionResult()); } var urlPrefix = $"{serviceProvider.Url}?"; if (!provider.Url.StartsWith(urlPrefix, StringComparison.OrdinalIgnoreCase)) { return(ErrorResult .BadRequest(new ValidationError { Field = "url", Message = $"Virtual provider url must match the associated service provider url followed by a query string. The url should begin with {urlPrefix}" }) .ToActionResult()); } } var currentUser = await UserService .CurrentUserAsync() .ConfigureAwait(false); providerDocument = new ProviderDocument() .PopulateFromExternalModel(provider); var command = new OrchestratorProviderCreateCommand(currentUser, providerDocument); return(await Orchestrator .InvokeAndReturnActionResultAsync <ProviderDocument, Provider>(command, Request) .ConfigureAwait(false)); }