Beispiel #1
0
        public void CanGetPrivateUsersWithGlobalClaims()
        {
            var userName        = "******";
            var privateUserName = userName + "_private";
            var newUser         = CreateUser(userName, false);


            //_actorRoleController.Create(ClaimScope.Global, newUser.Id, -1);

            // add private user
            var newPrivateUser = CreateUser(privateUserName, true);

            // Assign claim to user
            var claim = new ActorClaim()
            {
                ActorId = newUser.Id,
                Claim   = new Claim {
                    ClaimScope = ClaimScope.User
                },
                EntityId = newPrivateUser.Id
            };

            _actorClaimController.Create(claim);


            var user = _userController.Get(newPrivateUser.Id, ActorVisibilityFilter.All);

            Assert.NotNull(user);
            Assert.Equal(privateUserName, user.Name);
        }
        public ActorClaim Create(ActorClaim newClaim)
        {
            newClaim = _actorClaimDbController.Create(newClaim);

            _logger.LogInformation($"{newClaim?.Id}");

            return(newClaim);
        }
        public ActorClaim Create(ActorClaim actorClaim)
        {
            using (var context = ContextFactory.Create())
            {
                context.ActorClaims.Add(actorClaim);
                context.SaveChanges();
                actorClaim.Claim = context.Claims.Find(actorClaim.ClaimId);

                return(actorClaim);
            }
        }
        // TODO This is assigning new users default claims to the group, to be moved to its own table
        /// <summary>
        /// Assign the user claims to resources for a newly created relationship with a group
        /// </summary>
        /// <param name="relation">the user/group relationship</param>
        private void AssignUserResourceClaims(ActorRelationship relation)
        {
            relation.Requestor = _actorController.Get(relation.RequestorId);
            relation.Acceptor  = _actorController.Get(relation.AcceptorId);
            // Group to user relationship
            if (relation.Requestor.ActorType == ActorType.Group && relation.Acceptor.ActorType == ActorType.User || relation.Acceptor.ActorType == ActorType.Group && relation.Requestor.ActorType == ActorType.User)
            {
                // Get user
                var user = relation.Requestor.ActorType == ActorType.User
                                    ? relation.Requestor
                                    : relation.Acceptor;

                var group = relation.Requestor.ActorType == ActorType.Group
                                    ? relation.Requestor
                                    : relation.Acceptor;

                var GetClaim    = _claimController.Get(ClaimScope.Group, "Get-Resource");
                var CreateClaim = _claimController.Get(ClaimScope.Group, "Create-Resource");
                var UpdateClaim = _claimController.Get(ClaimScope.Group, "Update-Resource");
                if (GetClaim != null)
                {
                    var getActorClaim = new ActorClaim
                    {
                        ActorId  = user.Id,
                        ClaimId  = GetClaim.Id,
                        EntityId = group.Id,
                    };
                    _actorClaimController.Create(getActorClaim);
                }
                if (UpdateClaim != null)
                {
                    var updateActorClaim = new ActorClaim
                    {
                        ActorId  = user.Id,
                        ClaimId  = UpdateClaim.Id,
                        EntityId = group.Id,
                    };
                    _actorClaimController.Create(updateActorClaim);
                }
                if (CreateClaim != null)
                {
                    var createActorClaim = new ActorClaim
                    {
                        ActorId  = user.Id,
                        ClaimId  = CreateClaim.Id,
                        EntityId = group.Id,
                    };
                    _actorClaimController.Create(createActorClaim);
                }
            }
        }
Beispiel #5
0
        public static ActorClaimResponse ToContract(this ActorClaim actorClaimModel)
        {
            if (actorClaimModel == null)
            {
                return(null);
            }

            return(new ActorClaimResponse
            {
                Id = actorClaimModel.Id,
                ActorId = actorClaimModel.ActorId,
                ClaimId = actorClaimModel.Claim.Id,
                ClaimName = actorClaimModel.Claim.Name,
                EntityId = actorClaimModel.EntityId
            });
        }