public override void Configure(Container container)
            {
                //1. Registering the Authorization Provider
                Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                            new IAuthProvider[]
                {
                    new BasicAuthProvider()
                }));

                //2. Enabling the /register service
                Plugins.Add(new RegistrationFeature());

                //3. configuring the Repository that uses SQL Server backend
                var connString = "Data Source=;Initial Catalog=;User ID=;password="******"johnd") == null)
                {
                    ormLiteRepository.CreateUserAuth(new UserAuth
                    {
                        UserName  = "******",
                        FirstName = "John",
                        LastName  = "Doe",
                        Roles     = new List <string> {
                            RoleNames.Admin
                        }
                    }, "mypassword");
                }

                //4. Registering the Session Cache
                container.Register <ICacheClient>(new MemoryCacheClient());
            }
        public void SetUp()
        {
            try
            {
                tests = new OAuthUserSessionTests();
                var inMemoryRepo = new InMemoryAuthRepository();
                inMemoryRepo.Clear();
                userAuthRepositorys.Add(inMemoryRepo);

                var appSettings = new AppSettings();
                var redisRepo   = new RedisAuthRepository(new BasicRedisClientManager(new string[] { appSettings.GetString("Redis.Host") ?? "localhost" }));
                redisRepo.Clear();
                userAuthRepositorys.Add(redisRepo);

                if (OAuthUserSessionTestsBase.UseSqlServer)
                {
                    var connStr          = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\auth.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                    var sqlServerFactory = new OrmLiteConnectionFactory(connStr, SqlServerOrmLiteDialectProvider.Instance);
                    var sqlServerRepo    = new OrmLiteAuthRepository(sqlServerFactory);
                    sqlServerRepo.DropAndReCreateTables();
                }
                else
                {
                    var sqliteInMemoryRepo = new OrmLiteAuthRepository(dbFactory);
                    using (var db = dbFactory.Open())
                    {
                        db.DropAndCreateTable <UserAuth>();
                        db.DropAndCreateTable <UserAuthDetails>();
                    }
                    sqliteInMemoryRepo.Clear();
                    userAuthRepositorys.Add(sqliteInMemoryRepo);

                    var sqliteDbFactory = new OrmLiteConnectionFactory(
                        "~/App_Data/auth.sqlite".MapProjectPath());
                    var sqliteDbRepo = new OrmLiteAuthRepository(sqliteDbFactory);
                    sqliteDbRepo.CreateMissingTables();
                    userAuthRepositorys.Add(sqliteDbRepo);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Exemple #3
0
            public override void Configure(Container container)
            {
                Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                            new IAuthProvider[]
                {
                    new BasicAuthProvider()
                }));

                Plugins.Add(new RegistrationFeature());

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

                //configuring OrmLiteAuthRepository that uses SQL Server backend
                var connString = "Data Source=;Initial Catalog=;User ID=;password="******"johnd") == null)
                {
                    ormLiteRepository.CreateUserAuth(new UserAuth
                    {
                        UserName  = "******",
                        FirstName = "John",
                        LastName  = "Doe",
                        Roles     = new List <string> {
                            RoleNames.Admin
                        }
                    }, "mypassword");
                }
            }
Exemple #4
0
        /// <summary>
        /// Configures the authentication.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="factory">The factory.</param>
        public void ConfigureAuth(Funq.Container container, OrmLiteConnectionFactory factory)
        {
            // Instantiate the authentication repository with the configured OrmLiteConnectionFactory.
            var authRepository = new OrmLiteAuthRepository(factory);

            // Create the missing tables if they are not yet configured.
            authRepository.CreateMissingTables();

            // Register the authentication repository.
            container.Register <IUserAuthRepository>(c => authRepository);

            // Register all Authentication methods needed.
            Plugins.Add(
                new AuthFeature(
                    () => new AuthUserSession(),
                    new IAuthProvider[] { new CredentialsAuthProvider(), new BasicAuthProvider() }));

            // HtmlRedirect = null --^

            // Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());
        }
Exemple #5
0
        public override void Configure(Funq.Container container)
        {
            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

            //https://github.com/wordnik/swagger-core/wiki
            //Document your code and expose it to the world
            Plugins.Add(new SwaggerFeature());

            //Registers authorization service and endpoints /auth and /auth{provider}
            Plugins.Add(new AuthFeature(
                            () => new AuthUserSession(),
                            new IAuthProvider[] { new CredentialsAuthProvider() }
                            )
            {
                HtmlRedirect = null
            });

            //Registers registartion service and endpoints /register, /assignroles, /unassignroles
            Plugins.Add(new RegistrationFeature());
            this.RegisterAs <MyRegistrationValidator, IValidator <Registration> >();

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(CreateOrderValidator).Assembly);

            var dataFilePath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\data.db";

            container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(dataFilePath, SqliteDialect.Provider));

            var userRep = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IUserAuthRepository>(userRep);
            var redisCon = ConfigurationManager.AppSettings["redisUrl"].ToString();

            container.Register <IRedisClientsManager>(new PooledRedisClientManager(20, 60, redisCon));
            container.Register <ICacheClient>(c => (ICacheClient)c.Resolve <IRedisClientsManager>().GetCacheClient());

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));

            //https://github.com/ServiceStack/ServiceStack.Redis/wiki/RedisPubSub
            //start threads that subscribe to Redis channels for Pub/Sub
            new OrderSubscribers(container).StartSubscriberThreads();
            new FulfillmentSubscribers(container).StartSubscriberThreads();

            //https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization#userauth-persistence---the-iuserauthrepository
            //Use ServiceStacks authentication/authorization persistence
            userRep.CreateMissingTables(); //Create missing Auth

            //Re-Create Tables for the demo
            using (var con = AppHostBase.Resolve <IDbConnectionFactory>().OpenDbConnection())
            {
                con.CreateTable <Order>(true);
                con.CreateTable <Fulfillment>(true);
            }

            //clear redis
            using (var redis = AppHostBase.Resolve <IRedisClientsManager>().GetClient())
            {
            }
            //Create dummy user accounts (TestUser/Password)
            foreach (var user in DummyUserAccounts.GetDummyAccounts())
            {
                if (userRep.GetUserAuthByUserName(user.UserName) == null)
                {
                    userRep.CreateUserAuth(new UserAuth {
                        UserName = user.UserName
                    }, user.Password);
                }
            }
        }