protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            InitializeSwaggerMetadata();

            pipelines.OnError.AddItemToEndOfPipeline(
                (ctx, ex) => new OnErrorHooks(_logger)
                .HandleInternalServerError(
                    ctx,
                    ex,
                    container.Resolve <IResponseNegotiator>(),
                    _appConfig.IsDevelopment));

            pipelines.BeforeRequest += ctx => RequestHooks.RemoveContentTypeHeaderForGet(ctx);
            pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);

            pipelines.AfterRequest += ctx =>
            {
                foreach (var corsHeader in HttpResponseHeaders.CorsHeaders)
                {
                    ctx.Response.Headers.Add(corsHeader.Item1, corsHeader.Item2);
                }
            };

            container.Register(_appConfig);
            container.Register(_appConfig.AzureActiveDirectoryClientSettings);
            container.Register(_logger);
        }
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            InitializeSwaggerMetadata();

            base.ApplicationStartup(container, pipelines);

            pipelines.OnError.AddItemToEndOfPipeline(
                (ctx, ex) => new OnErrorHooks(_logger)
                .HandleInternalServerError(
                    ctx,
                    ex,
                    container.Resolve <IResponseNegotiator>(),
                    _env));

            pipelines.BeforeRequest += ctx => RequestHooks.RemoveContentTypeHeaderForGet(ctx);
            pipelines.BeforeRequest += ctx => RequestHooks.ErrorResponseIfContentTypeMissingForPostAndPut(ctx);
            pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);

            pipelines.AfterRequest += ctx =>
            {
                foreach (var corsHeader in HttpResponseHeaders.CorsHeaders)
                {
                    ctx.Response.Headers.Add(corsHeader.Item1, corsHeader.Item2);
                }
            };

            ConfigureApplicationRegistrations(container);
            var dbBootstrapper = container.Resolve <IDbBootstrapper>();

            dbBootstrapper.Setup();
        }
        protected override async void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            TinyIoCContainer = container;

            InitializeSwaggerMetadata();

            base.ApplicationStartup(container, pipelines);

            pipelines.OnError.AddItemToEndOfPipeline(
                (ctx, ex) => new OnErrorHooks(_logger)
                .HandleInternalServerError(
                    ctx,
                    ex,
                    container.Resolve <IResponseNegotiator>(),
                    _env));

            pipelines.BeforeRequest += ctx => RequestHooks.RemoveContentTypeHeaderForGet(ctx);
            pipelines.BeforeRequest += ctx => RequestHooks.ErrorResponseIfContentTypeMissingForPostAndPut(ctx);
            pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);

            pipelines.AfterRequest += ctx =>
            {
                foreach (var corsHeader in HttpResponseHeaders.CorsHeaders)
                {
                    ctx.Response.Headers.Add(corsHeader.Item1, corsHeader.Item2);
                }
            };

            ConfigureApplicationRegistrations(container);
            var dbBootstrapper = container.Resolve <IDbBootstrapper>();

            dbBootstrapper.Setup();

            var appConfig            = container.Resolve <IAppConfiguration>();
            var groupMigratorService = container.Resolve <GroupMigratorService>();

            if (appConfig.MigrateDuplicateGroups)
            {
                var migrationResults = await groupMigratorService.MigrateDuplicateGroups();
            }

            if (appConfig.MigrateGroupSource)
            {
                await groupMigratorService.MigrateWindowsSourceToDirectory();
            }

            if (appConfig.MigrateGroupIdentityProvider)
            {
                await groupMigratorService.MigrateIdentityProvider();
            }
        }
        protected virtual ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator ConfigureBootstrapper(
            ConfigurableBootstrapper configurableBootstrapper, params Claim[] claims)
        {
            var configurableBootstrapperConfigurator =
                new ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator(configurableBootstrapper);

            configurableBootstrapperConfigurator.Module <T>();
            configurableBootstrapperConfigurator.RequestStartup((container, pipeline, context) =>
            {
                context.CurrentUser     = new TestPrincipal(claims);
                pipeline.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);
            });
            return(configurableBootstrapperConfigurator);
        }
示例#5
0
        public RolesTests(bool useInMemoryDB = true)
        {
            var store = useInMemoryDB
                ? new InMemoryRoleStore()
                : (IRoleStore) new CouchDbRoleStore(DbService(), Logger, EventContextResolverService);
            var clientStore = useInMemoryDB
                ? new InMemoryClientStore()
                : (IClientStore) new CouchDbClientStore(DbService(), Logger, EventContextResolverService);

            var clientService = new ClientService(clientStore);
            var roleService   = new RoleService(store, new InMemoryPermissionStore(), clientService);

            Browser = new Browser(with =>
            {
                with.Module(new RolesModule(
                                roleService,
                                clientService,
                                new RoleValidator(roleService),
                                Logger));

                with.Module(new ClientsModule(
                                clientService,
                                new ClientValidator(clientService),
                                Logger));

                with.RequestStartup((_, pipelines, context) =>
                {
                    context.CurrentUser = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
                    {
                        new Claim(Claims.Scope, Scopes.ManageClientsScope),
                        new Claim(Claims.Scope, Scopes.ReadScope),
                        new Claim(Claims.Scope, Scopes.WriteScope),
                        new Claim(Claims.ClientId, "rolesprincipal")
                    }, "rolesprincipal"));
                    pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);
                });
            }, withDefaults => withDefaults.HostName("testhost"));

            Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.FormValue("Id", "rolesprincipal");
                with.FormValue("Name", "rolesprincipal");
                with.Header("Accept", "application/json");
            }).Wait();
        }
示例#6
0
        public void InitializeBrowser(IIdentityServiceProvider identityServiceProvider)
        {
            Browser = new Browser(with =>
            {
                // TODO: move this to base class and refactor all integration tests to use
                with.FieldNameConverter <UnderscoredFieldNameConverter>();

                with.Module(new GroupsModule(
                                _groupService,
                                new GroupValidator(_groupService),
                                Logger,
                                DefaultPropertySettings));

                with.Module(new RolesModule(
                                RoleService,
                                _clientService,
                                new RoleValidator(RoleService),
                                Logger));

                with.Module(new ClientsModule(
                                _clientService,
                                new ClientValidator(_clientService),
                                Logger));

                with.Module(new IdentitySearchModule(
                                new IdentitySearchService(_clientService, RoleService, _groupService, identityServiceProvider, Logger),
                                new IdentitySearchRequestValidator(),
                                Logger));

                with.RequestStartup((_, pipelines, context) =>
                {
                    context.CurrentUser = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
                    {
                        new Claim(Claims.Scope, Scopes.ManageClientsScope),
                        new Claim(Claims.Scope, Scopes.ReadScope),
                        new Claim(Claims.Scope, Scopes.WriteScope),
                        new Claim(Claims.ClientId, AtlasClientId),
                        new Claim(Claims.IdentityProvider, "idP1")
                    }, "rolesprincipal"));
                    pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);
                });
            }, withDefaults => withDefaults.HostName("testhost"));
        }
示例#7
0
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            InitializeSwaggerMetadata();

            pipelines.OnError.AddItemToEndOfPipeline(
                (ctx, ex) => new OnErrorHooks(_logger)
                .HandleInternalServerError(
                    ctx,
                    ex,
                    container.Resolve <IResponseNegotiator>(),
                    false));     //TODO: find out how to determine if IsDevelopment is true

            pipelines.BeforeRequest += ctx => RequestHooks.RemoveContentTypeHeaderForGet(ctx);
            pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);

            container.Register(_appConfig);
            container.Register(_logger);
        }
        public ClientTests(bool useInMemoryDB = true)
        {
            var store         = useInMemoryDB ? new InMemoryClientStore() : (IClientStore) new CouchDbClientStore(this.DbService(), this.Logger, this.EventContextResolverService);
            var clientService = new ClientService(store);

            this.Browser = new Browser(with =>
            {
                with.Module(new ClientsModule(
                                clientService,
                                new Domain.Validators.ClientValidator(clientService),
                                this.Logger));

                with.RequestStartup((_, pipelines, context) =>
                {
                    context.CurrentUser = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
                    {
                        new Claim(Claims.Scope, Scopes.ManageClientsScope),
                        new Claim(Claims.Scope, Scopes.ReadScope),
                        new Claim(Claims.Scope, Scopes.WriteScope),
                    }, "testprincipal"));
                    pipelines.BeforeRequest += (ctx) => RequestHooks.SetDefaultVersionInUrl(ctx);
                });
            }, withDefaults => withDefaults.HostName("testhost"));
        }
示例#9
0
        public GroupsTests(bool useInMemoryDB = true)
        {
            var groupStore = useInMemoryDB
                ? new InMemoryGroupStore()
                : (IGroupStore) new CouchDbGroupStore(DbService(), Logger, EventContextResolverService, _identifierFormatter);

            _roleStore = useInMemoryDB
                ? new InMemoryRoleStore()
                : (IRoleStore) new CouchDbRoleStore(DbService(), Logger, EventContextResolverService);

            var userStore = useInMemoryDB
                ? new InMemoryUserStore()
                : (IUserStore) new CouchDbUserStore(DbService(), Logger, EventContextResolverService, _identifierFormatter);

            var permissionStore = useInMemoryDB
                ? new InMemoryPermissionStore()
                : (IPermissionStore) new CouchDbPermissionStore(DbService(), Logger, EventContextResolverService);

            var clientStore = useInMemoryDB
                ? new InMemoryClientStore()
                : (IClientStore) new CouchDbClientStore(DbService(), Logger, EventContextResolverService);

            var userService       = new UserService(userStore);
            var clientService     = new ClientService(clientStore);
            var roleService       = new RoleService(_roleStore, permissionStore, clientService);
            var groupService      = new GroupService(groupStore, _roleStore, userStore, roleService);
            var permissionService = new PermissionService(permissionStore, roleService);

            Browser = new Browser(with =>
            {
                with.Module(new GroupsModule(
                                groupService,
                                new GroupValidator(groupService),
                                Logger,
                                DefaultPropertySettings));

                with.Module(new RolesModule(
                                roleService,
                                clientService,
                                new RoleValidator(roleService),
                                Logger));

                with.Module(new ClientsModule(
                                clientService,
                                new ClientValidator(clientService),
                                Logger));

                with.Module(new UsersModule(
                                clientService,
                                permissionService,
                                userService,
                                new UserValidator(),
                                Logger));

                with.Module(new PermissionsModule(
                                permissionService,
                                clientService,
                                new PermissionValidator(permissionService),
                                Logger));

                with.RequestStartup((_, pipelines, context) =>
                {
                    context.CurrentUser = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
                    {
                        new Claim(Claims.Scope, Scopes.ManageClientsScope),
                        new Claim(Claims.Scope, Scopes.ReadScope),
                        new Claim(Claims.Scope, Scopes.WriteScope),
                        new Claim(Claims.ClientId, "rolesprincipal"),
                        new Claim(Claims.IdentityProvider, "idP1")
                    }, "rolesprincipal"));
                    pipelines.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx);
                });
            }, withDefaults => withDefaults.HostName("testhost"));

            Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.FormValue("Id", "rolesprincipal");
                with.FormValue("Name", "rolesprincipal");
                with.Header("Accept", "application/json");
            }).Wait();
        }