/// <summary> /// Get published application with the given url. /// </summary> public EndpointConfig GetPublishedEndpoint(string endpointUrl) { foreach (var entry in _proxyStore) { // deserialize the store entry if (EnvironmentConfig.IsWin2016) { StoreConfig_2016 conf = StoreConfig_2016.FromXml(entry.value.DecodeFromBase64()); var endpoint = conf.EndpointConfig.FirstOrDefault( _ => _.FrontendUrl.EqualsIgnoreCase(endpointUrl)); // if the endpoint was found, return it if (endpoint != null) { return(endpoint); } } else { StoreConfig conf = StoreConfig.FromXml(entry.value.DecodeFromBase64()); var endpoint = conf.EndpointConfig.FirstOrDefault( _ => _.FrontendUrl.EqualsIgnoreCase(endpointUrl)); // if the endpoint was found, return it if (endpoint != null) { return(endpoint); } } } // return null if no endpoint was found return(null); }
/// <summary> /// Initializes server data store. /// </summary> private void InitializeDataStore(bool includeEndpoint = false) { // construct global config var storeConfigString = string.Empty; if (EnvironmentConfig.IsWin2016) { GlobalConfig_2016 globalConfig = new GlobalConfig_2016(); EndpointConfig_2016[] endpointConfig = null; this.InitialBaseGlobalConfig(globalConfig); globalConfig.AccessTokenAcceptanceDurationSec = Convert.ToString(AccessTokenAcceptanceDurationSec); globalConfig.ActiveEndpointAuthenticationURL = UrlHelper.CombineUrls(EnvironmentConfig.ADFSServerUrl, AdfsServicePathPairs.ActiveEndpointAuthenticationURL); globalConfig.SchemaVersion = SchemaVersion; globalConfig.StsSignOutURL = UrlHelper.CombineUrls(EnvironmentConfig.ADFSServerUrl, AdfsServicePathPairs.StsSignOutURL); if (includeEndpoint) { EndpointConfig_2016 testEndpoint = new EndpointConfig_2016(); this.InitialBaseEndpointConfig(testEndpoint); testEndpoint.PersistentAccessCookieExpirationTimeSec = Convert.ToString(PersistentAccessCookieExpirationTimeSec); testEndpoint.DisableHttpOnlyCookieProtection = Convert.ToString(false).ToLower(); testEndpoint.EnableHttpRedirect = Convert.ToString(false).ToLower(); testEndpoint.EnableSignOut = Convert.ToString(false).ToLower(); endpointConfig = new[] { testEndpoint }; } var storeConfig = new StoreConfig_2016 { GlobalConfig = (GlobalConfig_2016)globalConfig, EndpointConfig = endpointConfig }; storeConfigString = storeConfig.ToString().EncodeToBase64(); } else { GlobalConfig globalConfig = new GlobalConfig(); EndpointConfig[] endpointConfig = null; this.InitialBaseGlobalConfig(globalConfig); if (includeEndpoint) { EndpointConfig testEndpoint = new EndpointConfig(); this.InitialBaseEndpointConfig(testEndpoint); endpointConfig = new[] { testEndpoint }; } var storeConfig = new StoreConfig { GlobalConfig = globalConfig, EndpointConfig = endpointConfig }; storeConfigString = storeConfig.ToString().EncodeToBase64(); } // if the proxy store already exists, increase its version by one // if the proxy store has not been initialized yet, set the store version // to a random number. // // We do this to somewhat make sure that the store gets a different version // each time a test case runs. The proxy only updates its state when it gets // a different version from its cache. We want the proxy always to sync its // state with server's store config. // // For more detail, refer to Windows source code: // winblue_gdr/ds/security/ADFSv2/Product/ApplicationProxy/Configuration/src/ProxyConfigManager.cpp // in Function UpdateProxyConfig, it says: // if (m_currentConfigVersion != newConfigVersion) // var storeEntryKey = EnvironmentConfig.IsWin2016 ? EnvironmentConfig.SUTConfigEntryKey_2016 : EnvironmentConfig.SUTConfigEntryKey_2012R2; var newVersion = _proxyStore == null ? MinStoreVersion // new Random(DateTime.Now.Millisecond).Next(MinStoreVersion, MaxStoreVersion) : _proxyStore.First(_ => _.key.EqualsIgnoreCase(storeEntryKey)).version + 1; // set the new proxy store _proxyStore = new List <StoreEntry> { new StoreEntry { version = newVersion, key = storeEntryKey, value = storeConfigString } }; }