public string GetReplacementToken() { //Convention: "Admin_" + instance id. string instanceId = instanceIdContextProvider.GetInstanceId(); if (string.IsNullOrEmpty(instanceId)) { throw new InvalidOperationException( "The instance-year-specific Admin database name replacement token cannot be derived because the instance id was not set in the current context."); } return($"Admin_{instanceId}"); }
public virtual Action GetActionByName(string actionName) { var instanceId = _instanceIdContextProvider.GetInstanceId(); if (string.IsNullOrEmpty(instanceId)) { throw new InvalidOperationException("Expected instanceId is null or empty."); } var instanceSecurityRepoCacheObject = InstanceSecurityRepositoryCache.GetCache() .GetSecurityRepository(instanceId); return(instanceSecurityRepoCacheObject.Actions.First(a => a.ActionName.Equals(actionName, StringComparison.InvariantCultureIgnoreCase))); }
private string GetMetadataAbsoluteUrl(string schemaFile, string uriSegment) { bool isInstanceYearSpecific = _apiSettings.GetApiMode().Equals(ApiMode.InstanceYearSpecific); bool isYearSpecific = _apiSettings.GetApiMode().Equals(ApiMode.YearSpecific) || isInstanceYearSpecific; bool useReverseProxyHeaders = _apiSettings.UseReverseProxyHeaders ?? false; string basicPath = Request.RootUrl(useReverseProxyHeaders) + "/metadata/" + (isInstanceYearSpecific ? $"{_instanceIdContextProvider.GetInstanceId()}/" : string.Empty) + (isYearSpecific ? $"{_schoolYearContextProvider.GetSchoolYear()}/" : string.Empty) + "xsd"; return($"{basicPath}/{uriSegment}/{schemaFile}"); }
/// <summary> /// Checks the cache for an existing value, and if not found, calls through to decorated implementation to retrieve the details (which is then cached). /// </summary> /// <param name="token">The OAuth security token.</param> /// <returns>The <see cref="ApiClientDetails"/> associated with the token.</returns> public async Task <ApiClientDetails> GetClientDetailsForTokenAsync(string token) { string cacheKey; if (_apiSettings.GetApiMode() == ApiMode.InstanceYearSpecific) { const string InstanceCacheKeyFormat = "OAuthTokenValidator.ApiClientDetails.{0}.{1}"; var instanceId = _instanceIdContextProvider.GetInstanceId(); if (string.IsNullOrEmpty(instanceId)) { throw new InvalidOperationException("Expected instanceId is null or empty."); } cacheKey = string.Format(InstanceCacheKeyFormat, instanceId, token); } else { cacheKey = string.Format(CacheKeyFormat, token); } // Try to load API client details from cache if (_cacheProvider.TryGetCachedObject(cacheKey, out object apiClientDetailsAsObject)) { return((ApiClientDetails)apiClientDetailsAsObject); } // Pass call through to implementation var apiClientDetails = await _next.GetClientDetailsForTokenAsync(token); // If token is valid, insert API client details into the cache for **half** the duration of the externally managed expiration period if (apiClientDetails.IsTokenValid) { _cacheProvider.Insert( cacheKey, apiClientDetails, DateTime.Now.AddMinutes(_bearerTokenTimeoutMinutes.Value / 2.0), TimeSpan.Zero); } return(apiClientDetails); }
public string GetReplacementToken() { //Convention: "Ods_" + instance id + "_"+ school year. string instanceId = instanceIdContextProvider.GetInstanceId(); if (string.IsNullOrEmpty(instanceId)) { throw new InvalidOperationException( "The instance-year-specific ODS database name replacement token cannot be derived because the instance id was not set in the current context."); } int schoolYear = schoolYearContextProvider.GetSchoolYear(); if (schoolYear == 0) { throw new InvalidOperationException( "The instance-year-specific ODS database name replacement token cannot be derived because the school year was not set in the current context."); } return(string.Format("Ods_{0}_{1}", instanceId, schoolYear)); }
/// <inheritdoc cref="IApiClientDetailsCacheKeyProvider.GetCacheKey" /> public string GetCacheKey(string token) { string cacheKey; // NOTE: This abstraction could be further decomposed into separate implementations for the different ApiModes if (_apiSettings.GetApiMode() == ApiMode.InstanceYearSpecific) { const string InstanceCacheKeyFormat = "ApiClientDetails.{0}.{1}"; var instanceId = _instanceIdContextProvider.GetInstanceId(); if (string.IsNullOrEmpty(instanceId)) { throw new InvalidOperationException("Expected instanceId is null or empty."); } cacheKey = string.Format(InstanceCacheKeyFormat, instanceId, token); } else { cacheKey = string.Format(CacheKeyFormat, token); } return(cacheKey); }