Esempio n. 1
0
		private void ConfigureApp(Container container){

			var appSettings = new ConfigurationResourceManager();
                    
            double se= appSettings.Get("DefaultSessionExpiry", 480);
            AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);         
                                   
            string cacheHost= appSettings.Get("REDISTOGO_URL","localhost:6379").Replace("redis://redistogo-appharbor:","").Replace("/","");

            var p = new BasicRedisClientManager(new string[]{cacheHost});
            
            OrmLiteConfig.DialectProvider= FirebirdOrmLiteDialectProvider.Instance;
            
            IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(
                ConfigUtils.GetConnectionString("ApplicationDb"));
                        
            container.Register(appSettings);
            
            container.Register<Factory>(
                new Factory(){
                    DbFactory=dbFactory,
                    RedisClientsManager = p
                }
            );
            
            //container.Register<ICacheClient>(new MemoryCacheClient { FlushOnDispose = false });
            container.Register<IRedisClientsManager>(c => p);
                        
            Plugins.Add(new AuthFeature(
                 () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
                new IAuthProvider[]
            {
                new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}

            })
            {
                IncludeAssignRoleServices=false, 
            });
                            
            
            OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
                dbFactory
            );
            
            container.Register<IUserAuthRepository>(
                c => authRepo
            ); 

            
            if(appSettings.Get("EnableRegistrationFeature", false))
                Plugins.Add( new  RegistrationFeature());
						
		}
Esempio n. 2
0
        void ConfigureApp(Container container)
        {
            var appSettings = new ConfigurationResourceManager();

            double se= appSettings.Get("DefaultSessionExpiry", 480);
            AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);

            string cacheHost= appSettings.Get("REDISTOGO_URL","localhost:6379").Replace("redis://redistogo:","").Replace("/","");

            var redisClientManager = new BasicRedisClientManager(new string[]{cacheHost});

            OrmLiteConfig.DialectProvider= MySqlDialectProvider.Instance;

            IDbConnectionFactory dbFactory =
                new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("ApplicationDb"));

            string smtpServer= appSettings.Get("MAILGUN_SMTP_SERVER", "localhost");
            string smtpLogin= appSettings.Get("MAILGUN_SMTP_LOGIN", "username");
            string smtpPassword= appSettings.Get("MAILGUN_SMTP_PASSWORD", "PASSWORD");
            int smtpPort= appSettings.Get("MAILGUN_SMTP_PORT", 587);
            Mailer mailer = new Mailer(smtpServer, smtpPort, smtpLogin, smtpPassword);

            var appConfig= new AppConfig(appSettings);

            RepositoryClient rc = new RepositoryClient(dbFactory, redisClientManager);
            Controller controller = new Controller(rc,mailer,appConfig);
            container.Register<Controller>( controller );

            AuthRepoProxy arp = new AuthRepoProxy(dbFactory, redisClientManager);
            container.Register<AuthRepoProxy>( arp );

            container.Register<IRedisClientsManager>(c => redisClientManager);
            //container.Register<ICacheClient>(c => redisClientManager);

            Plugins.Add(new AuthFeature( () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
                new IAuthProvider[]
            {
                new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}
            })
               {
                IncludeAssignRoleServices=false
            });

            OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(dbFactory);

            container.Register<IUserAuthRepository>(c => authRepo);

            if(appSettings.Get("EnableRegistrationFeature", false))
                Plugins.Add( new  RegistrationFeature());
        }
Esempio n. 3
0
		public AppHost (): base("Aicl.Galapago", typeof(AuthenticationService).Assembly)
		{
			var appSettings = new ConfigurationResourceManager();
			if (appSettings.Get("EnableLog4Net", false))
			{
				var cf="log4net.conf".MapHostAbsolutePath();
				log4net.Config.XmlConfigurator.Configure(
					new System.IO.FileInfo(cf));
				LogManager.LogFactory = new  Log4NetFactory();
			}
			else
				LogManager.LogFactory = new ConsoleLogFactory();
						
			log = LogManager.GetLogger(typeof (AppHost));

		}
Esempio n. 4
0
        public AppHost() : base("Aicl.Delfin", typeof(AuthenticationService).Assembly)
        {
            var appSettings = new ConfigurationResourceManager();

            if (appSettings.Get("EnableLog4Net", false))
            {
                var cf = "log4net.conf".MapHostAbsolutePath();
                log4net.Config.XmlConfigurator.Configure(
                    new System.IO.FileInfo(cf));
                LogManager.LogFactory = new  Log4NetFactory();
            }
            else
            {
                LogManager.LogFactory = new ConsoleLogFactory();
            }

            log = LogManager.GetLogger(typeof(AppHost));
        }
Esempio n. 5
0
		void ConfigureApp(Container container)
		{
			var appSettings = new ConfigurationResourceManager();
                    
            string smtpServer= appSettings.Get("MAILGUN_SMTP_SERVER", "localhost");
			string smtpLogin= appSettings.Get("MAILGUN_SMTP_LOGIN", "username");
			string smtpPassword= appSettings.Get("MAILGUN_SMTP_PASSWORD", "PASSWORD");
			int smtpPort= appSettings.Get("MAILGUN_SMTP_PORT", 587);

			Mailer mailer = new Mailer(smtpServer, smtpPort, smtpLogin, smtpPassword);

			IRepository rp = new MemRepo();
			RepositoryClient rc = new RepositoryClient(rp);
			Controller controller = new Controller(rc,mailer);
			controller.InitRepo();
            container.Register<Controller>( controller );
            

            
						
		}
Esempio n. 6
0
		private void ConfigureAuth(Container container){

			var appSettings = new ConfigurationResourceManager();
			double se= appSettings.Get("DefaultSessionExpiry", 480);
			AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);			

			if (appSettings.Get("EnableRedisForAuthCache", false)){
				string cacheHost= appSettings.Get("AuthCacheHost", "localhost:6379");			
				int cacheDb= appSettings.Get("AuthCacheDb",8);				
										
				string cachePassword= appSettings.Get("AuthCachePassword",string.Empty);
						
				var p = new PooledRedisClientManager(new string[]{cacheHost},
							new string[]{cacheHost},
							cacheDb); 
				
				if(! string.IsNullOrEmpty(cachePassword))
					p.GetClient().Password= cachePassword;
				
				container.Register<ICacheClient>(p);
			}
			else
			{
				container.Register<ICacheClient>(new MemoryCacheClient());	
			}
			
			Plugins.Add(new AuthFeature(
				 () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
				new IAuthProvider[]
        	{
				new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}
        	})
			{
				IncludeAssignRoleServices=false, 
			});
		    				
			var dbFactory = new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("UserAuth")) ;
			
			OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
				dbFactory
			);
			
			container.Register<IUserAuthRepository>(
				c => authRepo
			); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

			
			if (appSettings.Get("EnableRegistrationFeature", false))
				Plugins.Add( new  RegistrationFeature());
						
		}
Esempio n. 7
0
		void ConfigureApp(Container container){

			var appSettings = new ConfigurationResourceManager();
                    
            double se= appSettings.Get("DefaultSessionExpiry", 480);
            AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);         
                                   
            string cacheHost= appSettings.Get("REDISTOGO_URL","localhost:6379").Replace("redis://redistogo-appharbor:","").Replace("/","");

            var redisClientManager = new BasicRedisClientManager(new string[]{cacheHost});
            
			OrmLiteConfig.DialectProvider= MySqlDialectProvider.Instance;
            
            IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(
                ConfigUtils.GetConnectionString("ApplicationDb"));
            
			var factory = new Factory(){
                DbFactory=dbFactory,
                RedisClientsManager = redisClientManager
			};

			var empresa = factory.Execute(proxy=>{
				return proxy.GetEmpresa();
			});

			var mailer = new Mailer(empresa);

			Channel channel = new Channel(empresa.PublishKey,
			                              empresa.SubscribeKey, empresa.SecretKey,"",false);

				
			container.Register(channel);
            container.Register(new AppConfig(appSettings){MailLogToken=empresa.MailLogToken});
            container.Register<Factory>(factory);
			container.Register(mailer);
            //container.Register<ICacheClient>(new MemoryCacheClient { FlushOnDispose = false });
            container.Register<IRedisClientsManager>(c => redisClientManager);
                        
            Plugins.Add(new AuthFeature(
                 () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
                new IAuthProvider[]
            {
                new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}

            })
            {
                IncludeAssignRoleServices=false, 
            });
                            
            
            OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
                dbFactory
            );
            
            container.Register<IUserAuthRepository>(
                c => authRepo
            ); 

            
            if(appSettings.Get("EnableRegistrationFeature", false))
                Plugins.Add( new  RegistrationFeature());
						
		}
		private void ConfigureAuth(Container container){
			
			container.Register<ICacheClient>(new MemoryCacheClient());
			
			Plugins.Add(new AuthFeature(
				 () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
				new IAuthProvider[]
        	{
				new CredentialsAuthProvider()
        	}));
		    
			var appSettings = new ConfigurationResourceManager();
				
			var dbFactory = new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("UserAuth")) ;
			
			OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
				dbFactory
			);
			
			container.Register<IUserAuthRepository>(
				c => authRepo
			); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

			
			if (appSettings.Get("RecreateAuthTables", false))
				authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
			else{
				authRepo.CreateMissingTables();   //Create only the missing tables				
			}
						
			Plugins.Add( new  RegistrationFeature());
			
		    //Add admin user  
			string userName = "******";
			string password = "******";
		
			List<string> userPermissions= new List<string>(
			new string[]{	
			"Customer.create", "Company.create", "Country.create", "City.create", "Author.create", "Person.create",	
			"Customer.read",   "Company.read",   "Country.read",   "City.read",   "Author.read",   "Person.read",
			"Customer.update", "Company.update", "Country.update", "City.update", "Author.update", "Person.update"
			});
			
			List<string> adminPermissions= new List<string>(userPermissions);
			adminPermissions.AddRange(new string[]{	
			"Customer.destroy","Company.destroy","Country.destroy","City.destroy","Author.destroy","Person.destroy"
			});
			
			if ( authRepo.GetUserAuthByUserName(userName)== default(UserAuth) ){
				List<string> roles= new List<string>();
				roles.Add(RoleNames.Admin);
			    string hash;
			    string salt;
			    new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
			    authRepo.CreateUserAuth(new UserAuth {
				    DisplayName = userName,
			        Email = userName+"@mail.com",
			        UserName = userName,
			        FirstName = "",
			        LastName = "",
			        PasswordHash = hash,
			        Salt = salt,
					Roles =roles,
					Permissions=adminPermissions,
			    }, password);
			}
			// user
			userName="******";
			password="******";
			var meta= new Dictionary<string,string>();
			meta.Add("ExpiresAt", DateTime.UtcNow.SerializeToString());
			
			if ( authRepo.GetUserAuthByUserName(userName)== default(UserAuth) ){
				string hash;
			    string salt;
			    new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
			    authRepo.CreateUserAuth(new UserAuth {
				    DisplayName = userName,
			        Email = userName+"@mail.com",
			        UserName = userName,
			        FirstName = "",
			        LastName = "",
			        PasswordHash = hash,
			        Salt = salt,
					Permissions=userPermissions,
					Meta= meta
				}, password);
			}
			
		}
Esempio n. 9
0
        void ConfigureApp(Container container)
        {
            var appSettings = new ConfigurationResourceManager();

            double se = appSettings.Get("DefaultSessionExpiry", 480);

            AuthProvider.DefaultSessionExpiry = TimeSpan.FromMinutes(se);

            string cacheHost = appSettings.Get("REDISTOGO_URL", "localhost:6379").Replace("redis://redistogo-appharbor:", "").Replace("/", "");

            var redisClientManager = new BasicRedisClientManager(new string[] { cacheHost });

            OrmLiteConfig.DialectProvider = MySqlDialectProvider.Instance;

            IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(
                ConfigUtils.GetConnectionString("ApplicationDb"));

            var factory = new Factory()
            {
                DbFactory           = dbFactory,
                RedisClientsManager = redisClientManager
            };

            var empresa = factory.Execute(proxy => {
                return(proxy.GetEmpresa());
            });

            var mailer = new Mailer(empresa);

            Channel channel = new Channel(empresa.PublishKey,
                                          empresa.SubscribeKey, empresa.SecretKey, "", false);


            container.Register(channel);
            container.Register(new AppConfig(appSettings)
            {
                MailLogToken = empresa.MailLogToken
            });
            container.Register <Factory>(factory);
            container.Register(mailer);
            //container.Register<ICacheClient>(new MemoryCacheClient { FlushOnDispose = false });
            container.Register <IRedisClientsManager>(c => redisClientManager);

            Plugins.Add(new AuthFeature(
                            () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
                            new IAuthProvider[]
            {
                new AuthenticationProvider()
                {
                    SessionExpiry = TimeSpan.FromMinutes(se)
                }
            })
            {
                IncludeAssignRoleServices = false,
            });


            OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
                dbFactory
                );

            container.Register <IUserAuthRepository>(
                c => authRepo
                );


            if (appSettings.Get("EnableRegistrationFeature", false))
            {
                Plugins.Add(new  RegistrationFeature());
            }
        }
Esempio n. 10
0
		private void ConfigureAuth(Container container){
			
			
			var appSettings = new ConfigurationResourceManager();
			double se= appSettings.Get("DefaultSessionExpiry", 480);
			AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);			

			if (appSettings.Get("EnableRedisForAuthCache", false)){
				string cacheHost= appSettings.Get("AuthCacheHost", "localhost:6379");			
				int cacheDb= appSettings.Get("AuthCacheDb",8);				
										
				string cachePassword= appSettings.Get("AuthCachePassword",string.Empty);
						
				var p = new PooledRedisClientManager(new string[]{cacheHost},
							new string[]{cacheHost},
							cacheDb); 
				
				if(! string.IsNullOrEmpty(cachePassword))
					p.GetClient().Password= cachePassword;
				
				container.Register<ICacheClient>(p);
			}
			else
			{
				container.Register<ICacheClient>(new MemoryCacheClient());	
			}
			
			Plugins.Add(new AuthFeature(
				 () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
				new IAuthProvider[]
        	{
				new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}
        	})
			{
				IncludeAssignRoleServices=false, 
			});
		    				
			var dbFactory = new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("UserAuth")) ;
			
			OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
				dbFactory
			);
			
			container.Register<IUserAuthRepository>(
				c => authRepo
			); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

			
			if (appSettings.Get("EnableRegistrationFeature", false))
				Plugins.Add( new  RegistrationFeature());
			
			
			
			if (!appSettings.Get("AddUsers", false)) return;
			
			
			// addusers
			var oldL =FirebirdOrmLiteDialectProvider.Instance.DefaultStringLength;
			
			FirebirdOrmLiteDialectProvider.Instance.DefaultStringLength=1024;
			if (appSettings.Get("RecreateAuthTables", false))
				authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
			else{
				authRepo.CreateMissingTables();   //Create only the missing tables				
			}
			
			FirebirdOrmLiteDialectProvider.Instance.DefaultStringLength=oldL;
						
		    //Add admin user  
			string userName = "******";
			string password = "******";
		
			List<string> permissions= new List<string>(
			new string[]{	
		
			});
			
			if ( authRepo.GetUserAuthByUserName(userName)== default(UserAuth) ){
				List<string> roles= new List<string>();
				roles.Add(RoleNames.Admin);
			    string hash;
			    string salt;
			    new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
			    authRepo.CreateUserAuth(new UserAuth {
				    DisplayName = userName,
			        Email = userName+"@mail.com",
			        UserName = userName,
			        FirstName = "",
			        LastName = "",
			        PasswordHash = hash,
			        Salt = salt,
					Roles =roles,
					Permissions=permissions
			    }, password);
			}
			
			userName = "******";
			password = "******";
		
			permissions= new List<string>(
			new string[]{	
			
			});
			
			if ( authRepo.GetUserAuthByUserName(userName)== default(UserAuth) ){
				List<string> roles= new List<string>();
				roles.Add("Test");
				string hash;
			    string salt;
			    new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
			    authRepo.CreateUserAuth(new UserAuth {
				    DisplayName = userName,
			        Email = userName+"@mail.com",
			        UserName = userName,
			        FirstName = "",
			        LastName = "",
			        PasswordHash = hash,
			        Salt = salt,
					Roles =roles,
					Permissions=permissions
			    }, password);
			}	
		}