Exemplo n.º 1
0
        private void ConfigureAuth(Funq.Container container, IAppSettings appSettings)
        {
            //Enable and register existing services you want this host to make use of.
            //Look in Web.config for examples on how to configure your oauth providers, e.g. oauth.facebook.AppId, etc.

            //Register all Authentication methods you want to enable for this web app.
            Plugins.Add(new AuthFeature(
                            () => new CustomUserSession(), //Use your own typed Custom UserSession type
                            new IAuthProvider[] {
                new CredentialsAuthProvider(),             //HTML Form post of UserName/Password credentials
                new TwitterAuthProvider(appSettings),      //Sign-in with Twitter
                new FacebookAuthProvider(appSettings),     //Sign-in with Facebook
                new DigestAuthProvider(appSettings),       //Sign-in with Digest Auth
                new BasicAuthProvider(),                   //Sign-in with Basic Auth
                new YahooOpenIdOAuthProvider(appSettings), //Sign-in with Yahoo OpenId
                new OpenIdOAuthProvider(appSettings),      //Sign-in with Custom OpenId
            }));

            //Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());

            //override the default registration validation with your own custom implementation
            container.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();

#if SQLSERVER
            //SQL Server Example:
            container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(
                                                          "Server=localhost;Database=test;User Id=test;Password=test", SqlServer2012Dialect.Provider)
            {
                ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
            });
#else
            //Create a DB Factory configured to access the UserAuth PostgreSQL DB
            var connStr = appSettings.GetString("ConnectionString");  //ConnectionString in Web.Config
            container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(connStr, PostgreSqlDialect.Provider)
            {
                ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
            });
#endif


            //Store User Data into the referenced SqlServer database
            container.Register <IUserAuthRepository>(c =>
                                                     new OrmLiteAuthRepository(c.Resolve <IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

            var authRepo = (OrmLiteAuthRepository)container.Resolve <IUserAuthRepository>();                         //If using and RDBMS to persist UserAuth, we must create required tables
            if (appSettings.Get("RecreateAuthTables", false))
            {
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            }
            else
            {
                authRepo.InitSchema();   //Create only the missing tables
            }
            Plugins.Add(new RequestLogsFeature());
        }
Exemplo n.º 2
0
        private void ConfigureAuth(Funq.Container container)
        {
            //Enable and register existing services you want this host to make use of.
            //Look in Web.config for examples on how to configure your oauth providers, e.g. oauth.facebook.AppId, etc.
            var appSettings = new AppSettings(tier: "dev");

            //var appSettings = new AppSettings(); //uncomment to use "live" config appSettings

            //Register all Authentication methods you want to enable for this web app.
            Plugins.Add(new AuthFeature(
                            () => new CustomUserSession(),  //Use your own typed Custom UserSession type
                            new IAuthProvider[] {
                new CredentialsAuthProvider(),              //HTML Form post of UserName/Password credentials
                new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
                new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
                new DigestAuthProvider(appSettings),        //Sign-in with Digest Auth
                new BasicAuthProvider(),                    //Sign-in with Basic Auth
                new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
                new YahooOpenIdOAuthProvider(appSettings),  //Sign-in with Yahoo OpenId
                new OpenIdOAuthProvider(appSettings),       //Sign-in with Custom OpenId
            }));

            //Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());

            //override the default registration validation with your own custom implementation
            container.RegisterAs <CustomRegistrationValidator, IValidator <Register> >();

            //Create a DB Factory configured to access the UserAuth SQL Server DB
            var connStr = appSettings.Get("SQLSERVER_CONNECTION_STRING", //AppHarbor or Local connection string
                                          ConfigUtils.GetConnectionString("UserAuth"));

            container.Register <IDbConnectionFactory>(
                new OrmLiteConnectionFactory(connStr, //ConnectionString in Web.Config
                                             SqlServerOrmLiteDialectProvider.Instance)
            {
                ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
            });

            //Store User Data into the referenced SqlServer database
            container.Register <IUserAuthRepository>(c =>
                                                     new OrmLiteAuthRepository(c.Resolve <IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

            var authRepo = (OrmLiteAuthRepository)container.Resolve <IUserAuthRepository>();                         //If using and RDBMS to persist UserAuth, we must create required tables

            if (appSettings.Get("RecreateAuthTables", false))
            {
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            }
            else
            {
                authRepo.InitSchema();   //Create only the missing tables
            }
            Plugins.Add(new RequestLogsFeature());
        }
Exemplo n.º 3
0
        public override void Configure(Funq.Container container)
        {
            JsConfig.EmitCamelCaseNames = true;
            JsConfig.IncludeNullValues  = true;
            JsConfig.DateHandler        = JsonDateHandler.ISO8601;

            LogManager.LogFactory = new DebugLogFactory();

            SetConfig(new EndpointHostConfig
            {
                WsdlServiceNamespace = "",
                AllowJsonpRequests   = true,
                DebugMode            = true,
                EnableFeatures       = Feature.All.Remove(GetDisabledFeatures())
            });

            //Authentication (see: https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.Endpoints.Tests/AuthTests.cs)
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[] {
                new BasicAuthProvider(),   //Sign-in with Basic Auth
            })
            {
                HtmlRedirect = null      /* prevent redirect to login page, make the user login using basic auth prompt */
            });
            userRepository = new InMemoryAuthRepository();
            container.Register <IUserAuthRepository>(userRepository);
            CreateUser(userRepository, 1, UserName, "DisplayName", null, Password);

            //NEW: Enable the validation feature and scans the service assembly for validators
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(Northwind.Data.Services.CategoryService).Assembly);

            //Caching
            container.Register <ICacheClient>(new MemoryCacheClient());

            //Repositories
            container.RegisterAs <CategoryServiceRepository, ICategoryServiceRepository>();
            container.RegisterAs <CustomerServiceRepository, ICustomerServiceRepository>();
            container.RegisterAs <CustomerCustomerDemoServiceRepository, ICustomerCustomerDemoServiceRepository>();
            container.RegisterAs <CustomerDemographicServiceRepository, ICustomerDemographicServiceRepository>();
            container.RegisterAs <EmployeeServiceRepository, IEmployeeServiceRepository>();
            container.RegisterAs <EmployeeTerritoryServiceRepository, IEmployeeTerritoryServiceRepository>();
            container.RegisterAs <OrderServiceRepository, IOrderServiceRepository>();
            container.RegisterAs <OrderDetailServiceRepository, IOrderDetailServiceRepository>();
            container.RegisterAs <ProductServiceRepository, IProductServiceRepository>();
            container.RegisterAs <RegionServiceRepository, IRegionServiceRepository>();
            container.RegisterAs <ShipperServiceRepository, IShipperServiceRepository>();
            container.RegisterAs <SupplierServiceRepository, ISupplierServiceRepository>();
            container.RegisterAs <TerritoryServiceRepository, ITerritoryServiceRepository>();

            //DataAccess / OrmLite
            var connectionString = ConfigurationManager.ConnectionStrings["ApiDbConnectionString"].ConnectionString;

            container.Register <IDataAccessAdapterFactory>(c => new DataAccessAdapterFactory(connectionString));
            container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(connectionString, true, new SqlServerOrmLiteDialectProvider()));
        }
Exemplo n.º 4
0
        public override void Configure(Funq.Container container)
        {
            JsConfig.EmitCamelCaseNames = true;
            JsConfig.IncludeNullValues  = true;
            JsConfig.DateHandler        = JsonDateHandler.ISO8601;

            LogManager.LogFactory = new ConsoleLogFactory();

            SetConfig(new EndpointHostConfig
            {
                WsdlServiceNamespace = "",
                AllowJsonpRequests   = true,
                DebugMode            = true,
                EnableFeatures       = Feature.All.Remove(GetDisabledFeatures()),
                CustomHttpHandlers   =
                {
                    // Use the CmsRazorHandler to add theming capabilities
                    { HttpStatusCode.NotFound, new CmsRazorHandler("/notfound") }
                }
            });

            //Authentication (see: https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.Endpoints.Tests/AuthTests.cs)
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[] {
                new BasicAuthProvider(),   //Sign-in with Basic Auth
            })
            {
                HtmlRedirect = null     /* prevent redirect to login page, make the user login using basic auth prompt */
            });
            userRepository = new InMemoryAuthRepository();
            container.Register <IUserAuthRepository>(userRepository);
            CreateUser(userRepository, 1, UserName, "DisplayName", null, Password);

            //Enable the validation feature and scan the service assembly for validators
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(Services.CategoryService).Assembly);

            //Razor (use CmsRazorFormat to add theming capabilities)
            Plugins.Add(new CmsRazorFormat());

            //Caching
            container.Register <ICacheClient>(new MemoryCacheClient());

            //Entity Repositories
            container.RegisterAs <CategoryServiceRepository, ICategoryServiceRepository>();
            container.RegisterAs <CustomerServiceRepository, ICustomerServiceRepository>();
            container.RegisterAs <CustomerCustomerDemoServiceRepository, ICustomerCustomerDemoServiceRepository>();
            container.RegisterAs <CustomerDemographicServiceRepository, ICustomerDemographicServiceRepository>();
            container.RegisterAs <EmployeeServiceRepository, IEmployeeServiceRepository>();
            container.RegisterAs <EmployeeTerritoryServiceRepository, IEmployeeTerritoryServiceRepository>();
            container.RegisterAs <OrderServiceRepository, IOrderServiceRepository>();
            container.RegisterAs <OrderDetailServiceRepository, IOrderDetailServiceRepository>();
            container.RegisterAs <ProductServiceRepository, IProductServiceRepository>();
            container.RegisterAs <RegionServiceRepository, IRegionServiceRepository>();
            container.RegisterAs <ShipperServiceRepository, IShipperServiceRepository>();
            container.RegisterAs <SupplierServiceRepository, ISupplierServiceRepository>();
            container.RegisterAs <TerritoryServiceRepository, ITerritoryServiceRepository>();

            //TypedList Repositories
            container.RegisterAs <TLSR.EmployeesByRegionAndTerritoryTypedListServiceRepository, TLSI.IEmployeesByRegionAndTerritoryTypedListServiceRepository>();

            //TypedView Repositories
            container.RegisterAs <TVSR.AlphabeticalListOfProductsTypedViewServiceRepository, TVSI.IAlphabeticalListOfProductsTypedViewServiceRepository>();
            container.RegisterAs <TVSR.CategorySalesFor1997TypedViewServiceRepository, TVSI.ICategorySalesFor1997TypedViewServiceRepository>();
            container.RegisterAs <TVSR.CurrentProductListTypedViewServiceRepository, TVSI.ICurrentProductListTypedViewServiceRepository>();
            container.RegisterAs <TVSR.CustomerAndSuppliersByCityTypedViewServiceRepository, TVSI.ICustomerAndSuppliersByCityTypedViewServiceRepository>();
            container.RegisterAs <TVSR.InvoicesTypedViewServiceRepository, TVSI.IInvoicesTypedViewServiceRepository>();
            container.RegisterAs <TVSR.OrderDetailsExtendedTypedViewServiceRepository, TVSI.IOrderDetailsExtendedTypedViewServiceRepository>();
            container.RegisterAs <TVSR.OrdersQryTypedViewServiceRepository, TVSI.IOrdersQryTypedViewServiceRepository>();
            container.RegisterAs <TVSR.OrderSubtotalTypedViewServiceRepository, TVSI.IOrderSubtotalTypedViewServiceRepository>();
            container.RegisterAs <TVSR.ProductsAboveAveragePriceTypedViewServiceRepository, TVSI.IProductsAboveAveragePriceTypedViewServiceRepository>();
            container.RegisterAs <TVSR.ProductSalesFor1997TypedViewServiceRepository, TVSI.IProductSalesFor1997TypedViewServiceRepository>();
            container.RegisterAs <TVSR.ProductsByCategoryTypedViewServiceRepository, TVSI.IProductsByCategoryTypedViewServiceRepository>();
            container.RegisterAs <TVSR.QuarterlyOrderTypedViewServiceRepository, TVSI.IQuarterlyOrderTypedViewServiceRepository>();
            container.RegisterAs <TVSR.SalesByCategoryTypedViewServiceRepository, TVSI.ISalesByCategoryTypedViewServiceRepository>();
            container.RegisterAs <TVSR.SalesTotalsByAmountTypedViewServiceRepository, TVSI.ISalesTotalsByAmountTypedViewServiceRepository>();
            container.RegisterAs <TVSR.SummaryOfSalesByQuarterTypedViewServiceRepository, TVSI.ISummaryOfSalesByQuarterTypedViewServiceRepository>();
            container.RegisterAs <TVSR.SummaryOfSalesByYearTypedViewServiceRepository, TVSI.ISummaryOfSalesByYearTypedViewServiceRepository>();

            //DataAccess / OrmLite
            var connectionString = ConfigurationManager.ConnectionStrings["ApiDbConnectionString"].ConnectionString;

            container.Register <IDataAccessAdapterFactory>(c => new DataAccessAdapterFactory(connectionString));
            container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(connectionString, true, new SqlServerOrmLiteDialectProvider()));

            //DataAccess Caching
            CacheController.RegisterCache(string.Empty /* connectionString */, new ResultsetCache(5 * 60 /* will purge the cache every 5 minutes */));
        }