private static string GetServiceAddress() { //TODO: DI in costructor IConfigurationPropertiesProvider? var appSettingsConfiguration = new AppSettingsConfiguration(); var serviceAddress = appSettingsConfiguration.GetProperty(AgathaServiceAddressAppSettingKey); return(serviceAddress); }
private static string GetEndpointConfigurationName() { //TODO: DI in costructor IConfigurationPropertiesProvider? var appSettingsConfiguration = new AppSettingsConfiguration(); var endpointConfigurationName = appSettingsConfiguration.GetProperty(EndpointConfigurationNameKey); return(endpointConfigurationName); }
public void GetProperty_GettingAssignedValue_ReturnsExpectedValue() { const string testSettingKey = "TestSettingKey"; IConfigurationPropertiesProvider config = new AppSettingsConfiguration(); config.SetProperty(testSettingKey, "TEST"); Assert.AreEqual("TEST", config.GetProperty(testSettingKey)); }
/// <summary> /// Checks the authentication. /// </summary> /// <param name="claimsPrincipal">The claims principal.</param> public void CheckAuthentication(IClaimsPrincipal claimsPrincipal) { var bootStrapToken = (from ident in claimsPrincipal.Identities where ident.BootstrapToken != null && ident.BootstrapToken is SamlSecurityToken select ident.BootstrapToken).FirstOrDefault(); var responseSerializer = new WSTrust13ResponseSerializer(); var requestSecurityTokenResponse = new RequestSecurityTokenResponse { AppliesTo = new EndpointAddress("https://localhost/Rem.Web"), Context = "passive", Lifetime = new Lifetime(bootStrapToken.ValidFrom, bootStrapToken.ValidTo), RequestedSecurityToken = new RequestedSecurityToken(bootStrapToken), TokenType = Saml2SecurityTokenHandler.TokenProfile11ValueType, RequestType = WSTrust13Constants.RequestTypes.Issue, KeyType = WSTrust13Constants.KeyTypes.Bearer }; string content; using (var swriter = new StringWriter()) { using (var xmlWriter = XmlWriter.Create(swriter)) { responseSerializer.WriteXml( requestSecurityTokenResponse, xmlWriter, new WSTrustSerializationContext()); xmlWriter.Flush(); swriter.Flush(); var xmlString = swriter.ToString().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", ""); content = string.Format( "wa=wsignin1.0&wresult={0}&wctx=rm%3D0%26id%3Dpassive%26ru%3D%252fRem.Web%252f", HttpContext.Current.Server.UrlEncode(xmlString)); } } var currentHttpRequest = HttpContext.Current.Request; var cookieContainer = new CookieContainer(); //foreach (string cookieName in currentHttpRequest.Cookies) //{ // var httpcookie = currentHttpRequest.Cookies[cookieName]; // var cookie = new Cookie(cookieName, httpcookie.Value, httpcookie.Path, httpcookie.Domain ?? "localhost"); // cookieContainer.Add(cookie); //} var appSettingsConfiguration = new AppSettingsConfiguration(); var remWebApplicationAddress = appSettingsConfiguration.GetProperty("RemWebApplicationAddress"); var request = ( HttpWebRequest )WebRequest.CreateDefault(new Uri(remWebApplicationAddress)); request.Method = currentHttpRequest.HttpMethod; request.CookieContainer = cookieContainer; request.ContentType = currentHttpRequest.ContentType; request.Accept = string.Empty; foreach (var acceptType in currentHttpRequest.AcceptTypes) { request.Accept += acceptType; if (acceptType != currentHttpRequest.AcceptTypes.Last()) { request.Accept += ", "; } } request.ContentLength = content.Length; request.Referer = currentHttpRequest.UrlReferrer.AbsoluteUri.Replace("Rem.Mvc", "Rem.Web"); request.AllowAutoRedirect = false; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(content); } try { var response = ( HttpWebResponse )request.GetResponse(); while (response.StatusCode == HttpStatusCode.Found) { response.Close(); var location = response.Headers["Location"]; if (!location.StartsWith("http")) { location = string.Format("{0}://{1}", request.RequestUri.Scheme, request.RequestUri.Host) + location; } request = GetNewRequest(location, cookieContainer); response = ( HttpWebResponse )request.GetResponse(); } if (response.StatusCode != HttpStatusCode.OK) { throw new Exception("Failed authentication."); } var cookieStringBuilder = new StringBuilder(); foreach (Cookie cookie in cookieContainer.GetCookies(new Uri("https://localhost"))) { if (cookie.Name.StartsWith("FedAuth")) { HttpContext.Current.Response.Cookies.Add(new HttpCookie("Server" + cookie.Name, cookie.Value)); cookieStringBuilder.Append(cookie.Value); } if (cookie.Name == "ASP.NET_SessionId") { HttpContext.Current.Response.Cookies.Add(new HttpCookie(cookie.Name, cookie.Value)); } } } catch (Exception e) { throw; } }
private static void Main() { var appConfig = new AppSettingsConfiguration(); var connectionStringBuilder = new SqlConnectionStringBuilder(); connectionStringBuilder.DataSource = appConfig.GetProperty("DatabaseServerName"); connectionStringBuilder.IntegratedSecurity = true; var dbCreated = false; var databaseName = appConfig.GetProperty("DatabaseCatalogName"); var sqlDataPath = String.Empty; // appConfig.GetProperty("SqlDataPath"); using (var sqlConnnection = new SqlConnection(connectionStringBuilder.ConnectionString)) { sqlConnnection.Open(); sqlDataPath = GetDbFilePath(sqlConnnection, "master"); if (!CheckDbExists(sqlConnnection, databaseName)) { CreateDatabase(sqlConnnection, databaseName, sqlDataPath); dbCreated = true; } } var appSettingsConfiguration = new AppSettingsConfiguration(); Console.WriteLine("Creating schema script...."); var msSql2008PersistenceConfigurerProvider = new MsSql2008PersistenceConfigurerProvider(appSettingsConfiguration); #if DEBUG FluentConfigurationSerializer.IsEnabled = false; #endif IConfigurationProvider fluentConfigurationProvider = new FluentConfigurationProvider(msSql2008PersistenceConfigurerProvider, new AssemblyLocator()); var configuration = fluentConfigurationProvider.Configure().GetEnumerator().Current; ISessionFactoryProvider sessionFactoryProvider = new SessionFactoryProvider(fluentConfigurationProvider); var sessionFactory = sessionFactoryProvider.GetFactory(null); var exportFileName = appConfig.GetProperty(ExportOutputFilePropertyName); var sb = new StringBuilder(); var headerComment = string.Format( "{0}{0}{1}{0}{2}{0}{3}{0}", Environment.NewLine, "/***********************************************************", "Begin: SQL Scripts to create RemGenDatabase database objects", "***********************************************************/" ); sb.Append(headerComment); var sql = GenerateSchemaCreationSql(); using (var session = sessionFactory.OpenSession()) { TextWriter textWriter = new StringWriter(); new SchemaExport(configuration).Execute( true, false, false, session.Connection, textWriter); sql += textWriter.ToString(); } sb.Append(sql); sb.Append(Environment.NewLine); sb.Append("/***********************************************************"); sb.Append(Environment.NewLine); sb.Append("End: SQL Scripts to create RemGenDatabase database objects"); sb.Append(Environment.NewLine); sb.Append("***********************************************************/"); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); Debug.Write(sb.ToString()); Console.WriteLine(sb.ToString()); using (var fs = new FileStream(exportFileName, FileMode.OpenOrCreate, FileAccess.Write)) { using (var streamWriter = new StreamWriter(fs)) { streamWriter.Write(sb.ToString()); } } Console.WriteLine("Deploy to Database (Y/N)?"); var answer = Console.ReadLine(); if (string.Compare(answer, "yes", true) == 0 || string.Compare(answer, "y", true) == 0) { if (!dbCreated) { Console.WriteLine("Dropping Database..."); using (var sqlConnection = new SqlConnection(connectionStringBuilder.ConnectionString)) { sqlConnection.Open(); using ( var sqlDropDatabaseCommand = new SqlCommand( string.Format( "USE {0} ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE USE master DROP DATABASE {0}", databaseName), sqlConnection)) { sqlDropDatabaseCommand.ExecuteNonQuery(); } } } using (var sqlConnection = new SqlConnection(connectionStringBuilder.ConnectionString)) { sqlConnection.Open(); if (!dbCreated) { CreateDatabase(sqlConnection, databaseName, sqlDataPath); } } //connectionStringBuilder.InitialCatalog = databaseName; using (var sqlConnection = new SqlConnection(connectionStringBuilder.ConnectionString)) { sqlConnection.Open(); sqlConnection.ChangeDatabase(databaseName); Console.WriteLine("Running schema script..."); var fullScript = sb.ToString(); var goSplit = fullScript.Split( new[] { string.Format("go {0}", Environment.NewLine) }, StringSplitOptions.RemoveEmptyEntries); foreach (var sqlstring in goSplit) { var sqlToRun = sqlstring; if (sqlstring == goSplit[0]) { sqlToRun = sqlstring.Replace(headerComment, ""); } using (var createSchemaCommand = new SqlCommand(sqlToRun, sqlConnection)) { createSchemaCommand.ExecuteNonQuery(); } } } } }
public void GetProperty_GettingUnAssignedValue_ReturnsNull() { IConfigurationPropertiesProvider config = new AppSettingsConfiguration(); Assert.AreEqual(null, config.GetProperty(Guid.NewGuid().ToString())); }