public void ShouldOverrideAuthorizationStrategiesForParentResourcesOnClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet
            {
                ClaimSetName = "TestClaimSet",
                Application  = testApplication
            };

            Save(testClaimSet);

            var appAuthorizationStrategies = SetupApplicationAuthorizationStrategies(testApplication).ToList();
            var testResourceClaims         = SetupParentResourceClaimsWithChildren(testClaimSet, testApplication);

            SetupResourcesWithDefaultAuthorizationStrategies(appAuthorizationStrategies, testResourceClaims.ToList());

            var testResource1ToEdit    = testResourceClaims.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim1");
            var testResource2ToNotEdit = testResourceClaims.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim2");

            var overrideModel = new OverrideDefaultAuthorizationStrategyModel
            {
                ResourceClaimId = testResource1ToEdit.ResourceClaimId,
                ClaimSetId      = testClaimSet.ClaimSetId,
                AuthorizationStrategyForCreate = appAuthorizationStrategies.Single(x => x.AuthorizationStrategyName == "TestAuthStrategy4").AuthorizationStrategyId,
                AuthorizationStrategyForRead   = 0,
                AuthorizationStrategyForUpdate = 0,
                AuthorizationStrategyForDelete = 0
            };

            Scoped <ISecurityContext>(securityContext =>
            {
                var command = new OverrideDefaultAuthorizationStrategyCommand(securityContext);
                command.Execute(overrideModel);
            });

            var resourceClaimsForClaimSet =
                Scoped <IGetResourcesByClaimSetIdQuery, List <Management.ClaimSetEditor.ResourceClaim> >(
                    query => query.AllResources(testClaimSet.ClaimSetId).ToList());

            var resultResourceClaim1 = resourceClaimsForClaimSet.Single(x => x.Id == overrideModel.ResourceClaimId);

            resultResourceClaim1.AuthStrategyOverridesForCRUD[0].AuthStrategyName.ShouldBe("TestAuthStrategy4");
            resultResourceClaim1.AuthStrategyOverridesForCRUD[1].ShouldBeNull();
            resultResourceClaim1.AuthStrategyOverridesForCRUD[2].ShouldBeNull();
            resultResourceClaim1.AuthStrategyOverridesForCRUD[3].ShouldBeNull();

            var resultResourceClaim2 = resourceClaimsForClaimSet.Single(x => x.Id == testResource2ToNotEdit.ResourceClaimId);

            resultResourceClaim2.AuthStrategyOverridesForCRUD[0].ShouldBeNull();
            resultResourceClaim2.AuthStrategyOverridesForCRUD[1].ShouldBeNull();
            resultResourceClaim2.AuthStrategyOverridesForCRUD[2].ShouldBeNull();
            resultResourceClaim2.AuthStrategyOverridesForCRUD[3].ShouldBeNull();
        }
        private void SetupOverridesForResourceCreateAction(int resourceClaimId, int claimSetId, int authorizationStrategyId)
        {
            var overrideModel = new OverrideDefaultAuthorizationStrategyModel
            {
                ResourceClaimId = resourceClaimId,
                ClaimSetId      = claimSetId,
                AuthorizationStrategyForCreate = authorizationStrategyId,
                AuthorizationStrategyForRead   = 0,
                AuthorizationStrategyForUpdate = 0,
                AuthorizationStrategyForDelete = 0
            };

            var command = new OverrideDefaultAuthorizationStrategyCommand(TestContext);

            command.Execute(overrideModel);
        }
 public ClaimSetsController(IGetClaimSetByIdQuery getClaimSetByIdQuery
                            , IGetApplicationsByClaimSetIdQuery getApplicationsByClaimSetIdQuery
                            , IGetResourcesByClaimSetIdQuery getResourcesByClaimSetIdQuery
                            , IGetClaimSetsByApplicationNameQuery getClaimSetsByApplicationNameQuery
                            , IGetAuthStrategiesByApplicationNameQuery getAuthStrategiesByApplicationNameQuery
                            , ITabDisplayService tabDisplayService
                            , CopyClaimSetCommand copyClaimSetCommand
                            , AddClaimSetCommand addClaimSetCommand
                            , EditClaimSetCommand editClaimSetCommand
                            , GetResourceClaimsQuery getResourceClaimsQuery
                            , GetChildResourceClaimsForParentQuery getChildResourceClaimsForParentQuery
                            , DeleteClaimSetCommand deleteClaimSetCommand
                            , EditResourceOnClaimSetCommand editResourceOnClaimSetCommand
                            , DeleteResourceOnClaimSetCommand deleteResourceOnClaimSetCommand
                            , ClaimSetFileExportCommand claimSetFileExportCommand
                            , ClaimSetFileImportCommand claimSetFileImportCommand
                            , OverrideDefaultAuthorizationStrategyCommand overrideDefaultAuthorizationStrategyCommand
                            , ResetToDefaultAuthStrategyCommand resetToDefaultAuthStrategyCommand)
 {
     _getClaimSetByIdQuery                    = getClaimSetByIdQuery;
     _getApplicationsByClaimSetIdQuery        = getApplicationsByClaimSetIdQuery;
     _getResourcesByClaimSetIdQuery           = getResourcesByClaimSetIdQuery;
     _getClaimSetsByApplicationNameQuery      = getClaimSetsByApplicationNameQuery;
     _getAuthStrategiesByApplicationNameQuery = getAuthStrategiesByApplicationNameQuery;
     _tabDisplayService      = tabDisplayService;
     _copyClaimSetCommand    = copyClaimSetCommand;
     _addClaimSetCommand     = addClaimSetCommand;
     _editClaimSetCommand    = editClaimSetCommand;
     _getClaimSetByIdQuery   = getClaimSetByIdQuery;
     _getResourceClaimsQuery = getResourceClaimsQuery;
     _getChildResourceClaimsForParentQuery = getChildResourceClaimsForParentQuery;
     _deleteClaimSetCommand                       = deleteClaimSetCommand;
     _editResourceOnClaimSetCommand               = editResourceOnClaimSetCommand;
     _deleteResourceOnClaimSetCommand             = deleteResourceOnClaimSetCommand;
     _claimSetFileExportCommand                   = claimSetFileExportCommand;
     _claimSetFileImportCommand                   = claimSetFileImportCommand;
     _overrideDefaultAuthorizationStrategyCommand = overrideDefaultAuthorizationStrategyCommand;
     _resetToDefaultAuthStrategyCommand           = resetToDefaultAuthStrategyCommand;
 }
Ejemplo n.º 4
0
        public void ShouldOverrideAuthorizationStrategiesForChildResourcesOnClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet
            {
                ClaimSetName = "TestClaimSet",
                Application  = testApplication
            };

            Save(testClaimSet);

            var appAuthorizationStrategies = SetupApplicationAuthorizationStrategies(testApplication).ToList();
            var testResourceClaims         = SetupParentResourceClaimsWithChildren(testClaimSet, testApplication);

            SetupResourcesWithDefaultAuthorizationStrategies(appAuthorizationStrategies, testResourceClaims.ToList());

            var testParentResource      = testResourceClaims.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim1");
            var testChildResourceToEdit = testResourceClaims.Select(x => x.ResourceClaim).Single(x =>
                                                                                                 x.ResourceName == "TestChildResourceClaim1" &&
                                                                                                 x.ParentResourceClaimId == testParentResource.ResourceClaimId);
            var testChildResourceNotToEdit = testResourceClaims.Select(x => x.ResourceClaim).Single(x =>
                                                                                                    x.ResourceName == "TestChildResourceClaim2" &&
                                                                                                    x.ParentResourceClaimId == testParentResource.ResourceClaimId);

            var overrideModel = new OverrideDefaultAuthorizationStrategyModel
            {
                ResourceClaimId = testChildResourceToEdit.ResourceClaimId,
                ClaimSetId      = testClaimSet.ClaimSetId,
                AuthorizationStrategyForCreate = appAuthorizationStrategies.Single(x => x.AuthorizationStrategyName == "TestAuthStrategy4").AuthorizationStrategyId,
                AuthorizationStrategyForRead   = 0,
                AuthorizationStrategyForUpdate = 0,
                AuthorizationStrategyForDelete = 0
            };

            var command = new OverrideDefaultAuthorizationStrategyCommand(TestContext);

            command.Execute(overrideModel);

            var resourceClaimsForClaimSet = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()).AllResources(testClaimSet.ClaimSetId).ToList();

            var resultParentResource = resourceClaimsForClaimSet.Single(x => x.Id == testParentResource.ResourceClaimId);
            var resultChildResource1 =
                resultParentResource.Children.Single(x => x.Id == testChildResourceToEdit.ResourceClaimId);

            resultChildResource1.AuthStrategyOverridesForCRUD[0].AuthStrategyName.ShouldBe("TestAuthStrategy4");
            resultChildResource1.AuthStrategyOverridesForCRUD[1].ShouldBeNull();
            resultChildResource1.AuthStrategyOverridesForCRUD[2].ShouldBeNull();
            resultChildResource1.AuthStrategyOverridesForCRUD[3].ShouldBeNull();

            var resultResourceClaim2 = resultParentResource.Children.Single(x => x.Id == testChildResourceNotToEdit.ResourceClaimId);

            resultResourceClaim2.AuthStrategyOverridesForCRUD[0].ShouldBeNull();
            resultResourceClaim2.AuthStrategyOverridesForCRUD[1].ShouldBeNull();
            resultResourceClaim2.AuthStrategyOverridesForCRUD[2].ShouldBeNull();
            resultResourceClaim2.AuthStrategyOverridesForCRUD[3].ShouldBeNull();
        }