Exemplo n.º 1
0
        public void AssignGroup(Group group, GroupMemberService groupMemberService)
        {
            AssertionConcern.AssertStateTrue(this.SupportsNesting, "This role does not support group nesting.");
            AssertionConcern.AssertArgumentNotNull(group, "Group must not be null.");
            AssertionConcern.AssertArgumentEquals(this.TenantId, group.TenantId, "Wrong tenant for this group.");

            this.Group.AddGroup(group, groupMemberService);

            DomainEventPublisher
                .Instance
                .Publish(new GroupAssignedToRole(
                        this.TenantId,
                        this.Name,
                        group.Name));
        }
Exemplo n.º 2
0
        public void AddGroup(Group group, GroupMemberService groupMemberService)
        {
            AssertionConcern.AssertArgumentNotNull(group, "Group must not be null.");
            AssertionConcern.AssertArgumentEquals(this.TenantId, group.TenantId, "Wrong tenant for this group.");
            AssertionConcern.AssertArgumentFalse(groupMemberService.IsMemberGroup(group, this.ToGroupMember()), "Group recurrsion.");

            if (this.GroupMembers.Add(group.ToGroupMember()) && !this.IsInternalGroup())
            {
                DomainEventPublisher
                    .Instance
                    .Publish(new GroupGroupAdded(
                            this.TenantId,
                            this.Name,
                            group.Name));
            }
        }
        public bool IsUserInRole(User user, string roleName)
        {
            AssertionConcern.AssertArgumentNotNull(user, "User must not be null.");
            AssertionConcern.AssertArgumentNotEmpty(roleName, "Role name must not be null.");

            bool authorized = false;

            if (user.Enabled)
            {
                Role role = this.RoleRepository.RoleNamed(user.TenantId, roleName);

                if (role != null)
                {
                    GroupMemberService groupMemberService =
                            new GroupMemberService(
                                    this.UserRepository,
                                    this.GroupRepository);

                    authorized = role.IsInRole(user, groupMemberService);
                }
            }

            return authorized;
        }
Exemplo n.º 4
0
        public bool IsMember(User user, GroupMemberService groupMemberService)
        {
            AssertionConcern.AssertArgumentNotNull(user, "User must not be null.");
            AssertionConcern.AssertArgumentEquals(this.TenantId, user.TenantId, "Wrong tenant for this group.");
            AssertionConcern.AssertArgumentTrue(user.Enabled, "User is not enabled.");

            var isMember = this.GroupMembers.Contains(user.ToGroupMember());

            if (isMember)
            {
                isMember = groupMemberService.ConfirmUser(this, user);
            }
            else
            {
                isMember = groupMemberService.IsUserInNestedGroup(this, user);
            }

            return isMember;
        }
Exemplo n.º 5
0
		/// <summary>
		/// Uses a <see cref="GroupMemberService"/> to determine
		/// whether a given <see cref="User"/> has this role, including
		/// by way of nested <see cref="Group"/> membership.
		/// </summary>
		/// <param name="user">
		/// A <see cref="User"/> entity to check.
		/// </param>
		/// <param name="groupMemberService">
		/// The instance of <see cref="GroupMemberService"/>
		/// relayed to the <see cref="Group.IsMember"/> method.
		/// </param>
		/// <returns>
		/// <c>true</c> if the given <paramref name="user"/>
		/// has this role; otherwise, <c>false</c>.
		/// </returns>
		public bool IsInRole(User user, GroupMemberService groupMemberService)
		{
			return this.internalGroup.IsMember(user, groupMemberService);
		}