public MemberSearchService MemberSearchService(IIdentityServiceProvider identityServiceProvider)
        {
            var memberSearchService =
                new MemberSearchService(_clientService, _roleService, identityServiceProvider, new Mock <ILogger>().Object);

            return(memberSearchService);
        }
コード例 #2
0
        public IdentitySearchService IdentitySearchService(IIdentityServiceProvider identityServiceProvider)
        {
            var identitySearchService =
                new IdentitySearchService(_clientService, _roleService, _groupService, identityServiceProvider, new Mock <ILogger>().Object);

            return(identitySearchService);
        }
コード例 #3
0
 public AccountsController(
     IIdentityServiceProvider identityServiceProvider,
     IHttpContextAccessor httpContextAccessor)
 {
     _identityServiceProvider = identityServiceProvider;
     _httpContextAccessor     = httpContextAccessor;
 }
        public Browser GetBrowser(ClaimsPrincipal principal, string storageProvider, IIdentityServiceProvider identityServiceProvider = null)
        {
            var appConfiguration = new AppConfiguration
            {
                StorageProvider   = storageProvider,
                ConnectionStrings = ConnectionStrings,
                IdentityServerConfidentialClientSettings = new IdentityServerConfidentialClientSettings
                {
                    Authority    = "http://localhost",
                    ClientId     = "test",
                    ClientSecret = "test",
                    Scopes       = new[]
                    {
                        "fabric/authorization.read",
                        "fabric/authorization.write",
                        "fabric/authorization.manageclients"
                    }
                },
                DefaultPropertySettings = new DefaultPropertySettings
                {
                    GroupSource = "Windows"
                }
            };
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            var bootstrapper = new TestBootstrapper(new Mock <ILogger>().Object, appConfiguration,
                                                    new LoggingLevelSwitch(), hostingEnvironment.Object, principal, identityServiceProvider);

            return(new Browser(bootstrapper, context =>
            {
                context.HostName("testhost");
                context.Header("Content-Type", "application/json");
                context.Header("Accept", "application/json");
            }));
        }
コード例 #5
0
 public TestBootstrapper(ILogger logger, 
     IAppConfiguration appConfig,
     LoggingLevelSwitch levelSwitch,
     IHostingEnvironment env,
     ClaimsPrincipal principal,
     IIdentityServiceProvider identityServiceProvider = null)
     : base(logger, appConfig, levelSwitch, env, null)
 {
     _principal = principal;
     _identityServiceProvider = identityServiceProvider;
 }
コード例 #6
0
 public MemberSearchService(
     ClientService clientService,
     RoleService roleService,
     IIdentityServiceProvider identityServiceProvider,
     ILogger logger)
 {
     _clientService           = clientService;
     _roleService             = roleService;
     _identityServiceProvider = identityServiceProvider;
     _logger = logger;
 }
コード例 #7
0
        private Browser InitializePatientSafetyBrowser(IIdentityServiceProvider identityServiceProvider)
        {
            var principal = 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, PatientSafetyClientId),
                new Claim(Claims.IdentityProvider, "idP1")
            }, "rolesprincipal"));

            return(GetBrowser(principal, _storageProvider, identityServiceProvider));
        }
コード例 #8
0
 public IdentitySearchService(
     ClientService clientService,
     RoleService roleService,
     GroupService groupService,
     IIdentityServiceProvider identityServiceProvider,
     ILogger logger)
 {
     _clientService           = clientService;
     _roleService             = roleService;
     _groupService            = groupService;
     _identityServiceProvider = identityServiceProvider;
     _logger = logger;
 }
コード例 #9
0
        public void InitializeBrowser(IIdentityServiceProvider identityServiceProvider)
        {
            var principal = 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"));

            Browser = GetBrowser(principal, _storageProvider, identityServiceProvider);
        }
コード例 #10
0
        public void InitializeClientWithoutRoles(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeBrowser(identityServiceProvider);

            // create the Atlas client
            var response = Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Id", AtlasClientId);
                with.FormValue("Name", AtlasClientId);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #11
0
        public async Task InitializeClientWithoutRolesAsync(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeBrowser(identityServiceProvider);

            // create the Atlas client
            var response = await Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id   = AtlasClientId,
                    Name = AtlasClientId
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #12
0
        public async Task InitializeClientWithRolesAndNoGroupsAsync(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeBrowser(identityServiceProvider);

            // create the Atlas client
            var response = await Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id   = AtlasClientId,
                    Name = AtlasClientId
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // create roles
            response = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = UserAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = AdminAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #13
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"));
        }
コード例 #14
0
        public void InitializeClientWithRolesAndNoGroups(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeBrowser(identityServiceProvider);

            // create the Atlas client
            var response = Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Id", AtlasClientId);
                with.FormValue("Name", AtlasClientId);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // create roles
            response = Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Grain", "app");
                with.FormValue("SecurableItem", AtlasClientId);
                with.FormValue("Name", UserAtlasRoleName);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Grain", "app");
                with.FormValue("SecurableItem", AtlasClientId);
                with.FormValue("Name", AdminAtlasRoleName);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #15
0
 public GroupSearchService(IIdentityServiceProvider identitySearchProvider)
 {
     _identitySearchProvider = identitySearchProvider;
 }
コード例 #16
0
        public void InitializeSuccessData(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeBrowser(identityServiceProvider);

            // create the Atlas client
            var response = Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Id", AtlasClientId);
                with.FormValue("Name", AtlasClientId);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // create roles
            var userAtlasRoleResponse = Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Grain", "app");
                with.FormValue("SecurableItem", AtlasClientId);
                with.FormValue("Name", UserAtlasRoleName);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, userAtlasRoleResponse.StatusCode);

            var adminAtlasRoleResponse = Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Grain", "app");
                with.FormValue("SecurableItem", AtlasClientId);
                with.FormValue("Name", AdminAtlasRoleName);
            }).Result;

            Assert.Equal(HttpStatusCode.Created, adminAtlasRoleResponse.StatusCode);

            // create groups
            response = Browser.Post("/groups", with =>
            {
                with.HttpRequest();
                with.FormValue("GroupName", UserAtlasGroupName);
                with.FormValue("GroupSource", "Custom");
                with.Header("Accept", "application/json");
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = Browser.Post("/groups", with =>
            {
                with.HttpRequest();
                with.FormValue("GroupName", AdminAtlasGroupName);
                with.FormValue("GroupSource", "Windows");
                with.Header("Accept", "application/json");
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // add role to group
            response = Browser.Post($"/groups/{AdminAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Id", adminAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>().Id.ToString());
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = Browser.Post($"/groups/{UserAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Id", userAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>().Id.ToString());
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // add user to custom group
            response = Browser.Post($"/groups/{UserAtlasGroupName}/users", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("SubjectId", "atlas_user");
                with.FormValue("IdentityProvider", "Windows");
            }).Result;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #17
0
        public async Task InitializeSuccessDataAsync(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeBrowser(identityServiceProvider);

            // create the Atlas client
            var response = await Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id   = AtlasClientId,
                    Name = AtlasClientId
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // create roles
            var userAtlasRoleResponse = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = UserAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, userAtlasRoleResponse.StatusCode);

            var adminAtlasRoleResponse = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = AdminAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, adminAtlasRoleResponse.StatusCode);

            var contributorAtlasRole = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = ContributorAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, contributorAtlasRole.StatusCode);

            // create groups
            response = await Browser.Post("/groups", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    GroupName   = UserAtlasGroupName,
                    GroupSource = "Custom",
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = await Browser.Post("/groups", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    GroupName   = AdminAtlasGroupName,
                    GroupSource = "Windows",
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // add role to group
            response = await Browser.Post($"/groups/{AdminAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id = adminAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>().Id.ToString()
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = await Browser.Post($"/groups/{UserAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id = userAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>().Id.ToString()
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);


            var subjectId        = "atlas_user";
            var identityProvider = "Windows";

            // add user to custom group
            response = await Browser.Post($"/groups/{UserAtlasGroupName}/users", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    SubjectId        = subjectId,
                    IdentityProvider = identityProvider
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            //add role to user
            response = await Browser.Post($"/user/{identityProvider}/{subjectId}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new []
                {
                    contributorAtlasRole.Body.DeserializeJson <RoleApiModel>()
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
コード例 #18
0
        public async Task InitializeSuccessDataAsync(IIdentityServiceProvider identityServiceProvider)
        {
            InitializeAtlasBrowser(identityServiceProvider);

            // create the Atlas client
            var response = await Browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id   = AtlasClientId,
                    Name = AtlasClientId
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // create the Patient Safety client
            var browser = InitializePatientSafetyBrowser(identityServiceProvider);

            response = await browser.Post("/clients", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Id   = PatientSafetyClientId,
                    Name = PatientSafetyClientId
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // create roles
            var userAtlasRoleResponse = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = UserAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, userAtlasRoleResponse.StatusCode);

            var adminAtlasRoleResponse = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = AdminAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, adminAtlasRoleResponse.StatusCode);

            var contributorAtlasRoleResponse = await Browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = AtlasClientId,
                    Name          = ContributorAtlasRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, contributorAtlasRoleResponse.StatusCode);

            var adminPatientSafetyRole = await browser.Post("/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    Grain         = "app",
                    SecurableItem = PatientSafetyClientId,
                    Name          = AdminPatientSafetyRoleName
                });
            });

            Assert.Equal(HttpStatusCode.Created, adminPatientSafetyRole.StatusCode);

            // create groups
            response = await Browser.Post("/groups", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    GroupName   = UserAtlasGroupName,
                    GroupSource = "Custom",
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = await Browser.Post("/groups", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    GroupName   = AdminAtlasGroupName,
                    GroupSource = GroupConstants.DirectorySource,
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var adminAtlasRole = adminAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>();

            // add role to group
            response = await Browser.Post($"/groups/{AdminAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    new
                    {
                        adminAtlasRole.Grain,
                        adminAtlasRole.SecurableItem,
                        adminAtlasRole.Name,
                        adminAtlasRole.Id
                    }
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var userAtlasRole = userAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>();

            response = await Browser.Post($"/groups/{UserAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    new
                    {
                        userAtlasRole.Grain,
                        userAtlasRole.SecurableItem,
                        userAtlasRole.Name,
                        userAtlasRole.Id
                    }
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var contributorAtlasRole = contributorAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>();

            //add second role to the group
            response = await Browser.Post($"/groups/{UserAtlasGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    new
                    {
                        contributorAtlasRole.Grain,
                        contributorAtlasRole.SecurableItem,
                        contributorAtlasRole.Name,
                        contributorAtlasRole.Id
                    }
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // add user to custom group
            response = await Browser.Post($"/groups/{UserAtlasGroupName}/users", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    new
                    {
                        SubjectId = AtlasUserName,
                        IdentityProvider,
                        IdentityProviderUserPrincipalName = "*****@*****.**"
                    }
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            //add role to user
            response = await Browser.Post($"/user/{IdentityProvider}/{AtlasUserName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new []
                {
                    contributorAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>()
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // add a second role to the user (role is tied to a different client)
            response = await browser.Post($"/user/{IdentityProvider}/{AtlasUserName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    adminPatientSafetyRole.Body.DeserializeJson <RoleApiModel>()
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            //add user with role but no group
            response = await Browser.Post("/user/", with =>
            {
                with.HttpRequest();
                with.JsonBody(new
                {
                    SubjectId = AtlasUserNoGroupName,
                    IdentityProvider,
                    IdentityProviderUserPrincipalName = "*****@*****.**"
                });
            });

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            //add roles to user
            response = await Browser.Post($"/user/{IdentityProvider}/{AtlasUserNoGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    contributorAtlasRoleResponse.Body.DeserializeJson <RoleApiModel>(),
                    adminAtlasRole,
                    userAtlasRole
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            //delete the userAtlasRole from the user
            response = await Browser.Delete($"/user/{IdentityProvider}/{AtlasUserNoGroupName}/roles", with =>
            {
                with.HttpRequest();
                with.JsonBody(new[]
                {
                    userAtlasRole
                });
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }