Example #1
0
        public void Execute(SharingModel model)
        {
            var sharingClaimSets = model.Template.ClaimSets;
            var allResources     = GetDbResources();

            foreach (var claimSet in sharingClaimSets)
            {
                var claimSetId = _addClaimSetCommand.Execute(new AddClaimSetModel
                {
                    ClaimSetName = claimSet.Name
                });

                var resources      = claimSet.ResourceClaims.Select(x => x.ToObject <ResourceClaim>()).ToList();
                var childResources = new List <ResourceClaim>();
                foreach (var resourceClaims in resources.Select(x => x.Children))
                {
                    childResources.AddRange(resourceClaims);
                }
                resources.AddRange(childResources);
                var currentResources = resources.Select(r =>
                {
                    var resource = allResources.FirstOrDefault(dr => dr.Name.Equals(r.Name));
                    if (resource != null)
                    {
                        resource.Create = r.Create;
                        resource.Read   = r.Read;
                        resource.Update = r.Update;
                        resource.Delete = r.Delete;
                        resource.AuthStrategyOverridesForCRUD = r.AuthStrategyOverridesForCRUD;
                    }
                    return(resource);
                }).ToList();
                currentResources.RemoveAll(x => x == null);
                foreach (var resource in currentResources)
                {
                    var editResourceModel = new EditResourceOnClaimSetModel
                    {
                        ClaimSetId    = claimSetId,
                        ResourceClaim = resource
                    };

                    _editResourceOnClaimSetCommand.Execute(editResourceModel);

                    if (resource.AuthStrategyOverridesForCRUD != null && resource.AuthStrategyOverridesForCRUD.Any())
                    {
                        var overrideAuthStrategyModel = new OverrideAuthorizationStrategyModel
                        {
                            ClaimSetId      = claimSetId,
                            ResourceClaimId = resource.Id,
                            AuthorizationStrategyForCreate = AuthStrategyOverrideForAction(resource.AuthStrategyOverridesForCRUD.Create()),
                            AuthorizationStrategyForRead   = AuthStrategyOverrideForAction(resource.AuthStrategyOverridesForCRUD.Read()),
                            AuthorizationStrategyForUpdate = AuthStrategyOverrideForAction(resource.AuthStrategyOverridesForCRUD.Update()),
                            AuthorizationStrategyForDelete = AuthStrategyOverrideForAction(resource.AuthStrategyOverridesForCRUD.Delete())
                        };
                        _overrideDefaultAuthorizationStrategyCommand.Execute(overrideAuthStrategyModel);
                    }
                }
Example #2
0
        public void Execute(IClaimSetFileImportModel model)
        {
            var sharingModel     = SharingModel.Deserialize(model.ImportFile);
            var sharingClaimSets = sharingModel.Template.ClaimSets;
            var allResources     = GetDbResources();

            foreach (var claimSet in sharingClaimSets)
            {
                var claimSetId = _addClaimSetCommand.Execute(new AddClaimSetModel
                {
                    ClaimSetName = claimSet.Name
                });

                var resources      = claimSet.ResourceClaims.Select(x => x.ToObject <ResourceClaim>()).ToList();
                var childResources = new List <ResourceClaim>();
                foreach (var resourceClaims in resources.Select(x => x.Children))
                {
                    childResources.AddRange(resourceClaims);
                }
                resources.AddRange(childResources);
                var currentResources = resources.Select(r =>
                {
                    var resource = allResources.FirstOrDefault(dr => dr.Name.Equals(r.Name));
                    if (resource != null)
                    {
                        resource.Create = r.Create;
                        resource.Read   = r.Read;
                        resource.Update = r.Update;
                        resource.Delete = r.Delete;
                    }
                    return(resource);
                }).ToList();
                currentResources.RemoveAll(x => x == null);
                foreach (var resource in currentResources)
                {
                    var editResourceModel = new EditResourceOnClaimSetModel
                    {
                        ClaimSetId    = claimSetId,
                        ResourceClaim = resource
                    };

                    _editResourceOnClaimSetCommand.Execute(editResourceModel);
                }
            }
        }