Example #1
0
        public void ShouldInitFromAppConfig()
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            settings.Add("Roles", "Admin: Monkey, Gorilla; User: BabyShoes, RegularUser");
            DefaultConfiguration.SetAppSettings(settings);

            DaoRoleProvider.InitializeFromConfig();

            ExpectExists("Gorilla");
            ExpectExists("Monkey");
            ExpectExists("BabyShoes");
            ExpectExists("RegularUser");

            DaoRoleProvider roleprovider = new DaoRoleProvider();

            Expect.IsTrue(roleprovider.IsUserInRole("Gorilla", "Admin"));
            Expect.IsTrue(roleprovider.IsUserInRole("Monkey", "Admin"));
            Expect.IsFalse(roleprovider.IsUserInRole("Gorilla", "User"));
            Expect.IsFalse(roleprovider.IsUserInRole("Monkey", "User"));
            Expect.IsTrue(roleprovider.IsUserInRole("BabyShoes", "User"));
            Expect.IsTrue(roleprovider.IsUserInRole("RegularUser", "User"));
            Expect.IsFalse(roleprovider.IsUserInRole("BabyShoes", "Admin"));
            Expect.IsFalse(roleprovider.IsUserInRole("RegularUser", "Admin"));
        }
Example #2
0
        public void ShouldBeAbleToCreateAndDeleteRole()
        {
            DaoRoleProvider provider = new DaoRoleProvider();

            Expect.IsFalse(provider.RoleExists(roleName), "Role should not have existed: {0}"._Format(roleName));
            provider.CreateRole(roleName);
            Expect.IsTrue(provider.RoleExists(roleName), "Role didn't get created");
            provider.DeleteRole(roleName, false);
            Expect.IsFalse(provider.RoleExists(roleName), "Role didn't get deleted");
        }
Example #3
0
        public void ShouldBeAbleToAddUsersToRole()
        {
            User user = User.Ensure(userName);

            DaoRoleProvider provider = new DaoRoleProvider();

            provider.DeleteRole(roleName, false);
            Expect.IsFalse(provider.RoleExists(roleName));
            provider.CreateRole(roleName);

            Expect.IsFalse(provider.IsUserInRole(userName, roleName));
            provider.AddUsersToRoles(new string[] { userName }, new string[] { roleName });

            Expect.IsTrue(provider.IsUserInRole(userName, roleName), "user wasn't added to role");

            provider.DeleteRole(roleName, false);
        }
        // --

        public static ServiceRegistry Create()
        {
            DataSettings dataSettings      = DataSettings.Current;
            string       databasesPath     = dataSettings.GetSysDatabaseDirectory().FullName;
            string       userDatabasesPath = Path.Combine(databasesPath, "UserDbs");

            AppConf                           conf         = new AppConf(BamConf.Load(ServiceConfig.ContentRoot), ServiceConfig.ProcessName.Or(RegistryName));
            UserManager                       userMgr      = conf.UserManagerConfig.Create();
            DaoUserResolver                   userResolver = new DaoUserResolver();
            DaoRoleResolver                   roleResolver = new DaoRoleResolver();
            SQLiteDatabaseProvider            dbProvider   = new SQLiteDatabaseProvider(databasesPath, Log.Default);
            ApplicationRegistrationRepository coreRepo     = new ApplicationRegistrationRepository();

            dbProvider.SetDatabases(coreRepo);
            dbProvider.SetDatabases(userMgr);
            userMgr.Database.TryEnsureSchema(typeof(UserAccounts.Data.User), Log.Default);
            userResolver.Database = userMgr.Database;
            roleResolver.Database = userMgr.Database;

            ServiceRegistryRepository serviceRegistryRepo = new ServiceRegistryRepository();

            serviceRegistryRepo.Database = dataSettings.GetSysDatabaseFor(serviceRegistryRepo);
            serviceRegistryRepo.EnsureDaoAssemblyAndSchema();

            DaoRoleProvider           daoRoleProvider = new DaoRoleProvider(userMgr.Database);
            RoleService               coreRoleService = new RoleService(daoRoleProvider, conf);
            AssemblyServiceRepository assSvcRepo      = new AssemblyServiceRepository();

            assSvcRepo.Database = dataSettings.GetSysDatabaseFor(assSvcRepo);
            assSvcRepo.EnsureDaoAssemblyAndSchema();

            ConfigurationService configSvc     = new ConfigurationService(coreRepo, conf, userDatabasesPath);
            CompositeRepository  compositeRepo = new CompositeRepository(coreRepo);
            SystemLoggerService  loggerSvc     = new SystemLoggerService(conf);

            dbProvider.SetDatabases(loggerSvc);
            loggerSvc.SetLogger();

            ServiceRegistry reg = (ServiceRegistry)(new ServiceRegistry())
                                  .ForCtor <ConfigurationService>("databaseRoot").Use(userDatabasesPath)
                                  .ForCtor <ConfigurationService>("conf").Use(conf)
                                  .ForCtor <ConfigurationService>("coreRepo").Use(coreRepo)
                                  .For <ILogger>().Use(Log.Default)
                                  .For <IRepository>().Use(coreRepo)
                                  .For <DaoRepository>().Use(coreRepo)
                                  .For <ApplicationRegistrationRepository>().Use(coreRepo)
                                  .For <AppConf>().Use(conf)
                                  .For <IDatabaseProvider>().Use(dbProvider)
                                  .For <IUserManager>().Use(userMgr)
                                  .For <UserManager>().Use(userMgr)
                                  .For <IUserResolver>().Use(userResolver)
                                  .For <DaoUserResolver>().Use(userResolver)
                                  .For <IRoleResolver>().Use(roleResolver)
                                  .For <DaoRoleResolver>().Use(roleResolver)
                                  .For <IRoleProvider>().Use(coreRoleService)
                                  .For <RoleService>().Use(coreRoleService)
                                  .For <EmailComposer>().Use(userMgr.EmailComposer)
                                  .For <IApplicationNameProvider>().Use <ApplicationRegistrationService>()
                                  .For <ApplicationRegistrationService>().Use <ApplicationRegistrationService>()
                                  .For <IApiKeyResolver>().Use <ApplicationRegistrationService>()
                                  .For <ISmtpSettingsProvider>().Use(userMgr)
                                  .For <UserRegistryService>().Use <UserRegistryService>()
                                  .For <ConfigurationService>().Use(configSvc)
                                  .For <IStorableTypesProvider>().Use <NamespaceRepositoryStorableTypesProvider>()
                                  .For <FileService>().Use <FileService>()
                                  .For <IFileService>().Use <FileService>()
                                  .For <AssemblyServiceRepository>().Use(assSvcRepo)
                                  .For <IAssemblyService>().Use <AssemblyService>()
                                  .For <ServiceRegistryRepository>().Use(serviceRegistryRepo)
                                  .For <ServiceRegistryService>().Use <ServiceRegistryService>()
                                  .For <OAuthService>().Use <OAuthService>()
                                  .For <ILog>().Use(loggerSvc)
                                  .For <SystemLoggerService>().Use(loggerSvc)
                                  .For <DataSettings>().Use(DataSettings.Current)
                                  .For <IApplicationNameResolver>().Use <ClientApplicationNameResolver>()
                                  .For <ClientApplicationNameResolver>().Use <ClientApplicationNameResolver>()
                                  .For <SmtpSettingsProvider>().Use(DataSettingsSmtpSettingsProvider.Default)
                                  .For <NotificationService>().Use <NotificationService>()
                                  .For <ILogReader>().Use <SystemLogReaderService>()
                                  .For <CredentialManagementService>().Use <CredentialManagementService>();

            reg.For <ServiceRegistry>().Use(reg)
            .For <DiagnosticService>().Use <DiagnosticService>();

            reg.SetProperties(userMgr);
            userMgr.ServiceProvider = reg;

            reg.For <CompositeRepository>().Use(() =>
            {
                compositeRepo.AddTypes(reg.Get <IStorableTypesProvider>().GetTypes());
                return(compositeRepo);
            });

            ServiceProxySystem.UserResolvers.Clear();
            ServiceProxySystem.RoleResolvers.Clear();
            ServiceProxySystem.UserResolvers.AddResolver(userResolver);
            ServiceProxySystem.RoleResolvers.AddResolver(roleResolver);
            reg.Name = RegistryName;
            return(reg);
        }