public bool IsMemberGroup(Group group, GroupMember memberGroup) { var isMember = false; foreach (var member in group.GroupMembers.Where(x => x.IsGroup)) { if (memberGroup.Equals(member)) { isMember = true; } else { var nestedGroup = this.groupRepository.GroupNamed(member.TenantId, member.Name); if (nestedGroup != null) { isMember = IsMemberGroup(nestedGroup, memberGroup); } } if (isMember) { break; } } return isMember; }
public bool IsMemberGroup(Group group, GroupMember memberGroup) { bool isMember = false; foreach (GroupMember member in group.GroupMembers) { if (member.IsGroup()) { if (memberGroup.Equals(member)) { isMember = true; } else { Group nestedGroup = this.GroupRepository.GroupNamed(member.TenantId, member.Name); if (nestedGroup != null) { isMember = this.IsMemberGroup(nestedGroup, memberGroup); } } } if (isMember) { break; } } return isMember; }
public Role(TenantId tenantId, string name, string description, bool supportsNesting) { this.Description = description; this.Name = name; this.SupportsNesting = supportsNesting; this.TenantId = tenantId; this.group = CreateInternalGroup(); }
/// <summary> /// Initializes a new instance of the <see cref="Role"/> class. /// </summary> /// <param name="tenantId"> /// Initial value of the <see cref="TenantId"/> property. /// </param> /// <param name="name"> /// Initial value of the <see cref="Name"/> property. /// </param> /// <param name="description"> /// Initial value of the <see cref="Description"/> property. /// </param> /// <param name="supportsNesting"> /// Initial value of the <see cref="SupportsNesting"/> property. /// </param> public Role(TenantId tenantId, string name, string description, bool supportsNesting) { // Defer validation to the property setters. this.Description = description; this.Name = name; this.SupportsNesting = supportsNesting; this.TenantId = tenantId; this.internalGroup = this.CreateInternalGroup(); }
public bool IsUserInNestedGroup(Group group, User user) { foreach (var member in group.GroupMembers.Where(x => x.IsGroup())) { var nestedGroup = this.groupRepository.GroupNamed(member.TenantId, member.Name); if (nestedGroup != null) { var isInNestedGroup = nestedGroup.IsMember(user, this); if (isInNestedGroup) return true; } } return false; }
public bool ConfirmUser(Group group, User user) { bool userConfirmed = true; User confirmedUser = this.UserRepository .UserWithUsername(group.TenantId, user.Username); if (confirmedUser == null || !confirmedUser.Enabled) { userConfirmed = false; } return userConfirmed; }
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)); }
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 void RemoveGroup(Group group) { AssertionConcern.AssertArgumentNotNull(group, "Group must not be null."); AssertionConcern.AssertArgumentEquals(this.TenantId, group.TenantId, "Wrong tenant for this group."); // not a nested remove, only direct member if (this.GroupMembers.Remove(group.ToGroupMember()) && !this.IsInternalGroup()) { DomainEventPublisher .Instance .Publish(new GroupGroupRemoved( this.TenantId, this.Name, group.Name)); } }
/// <summary> /// Recursive function which determines whether /// a <see cref="Group"/> is a member of a group /// or of a descendant group. /// </summary> /// <param name="group"> /// An instance of <see cref="Group"/> to check for /// the presence of <paramref name="memberGroup"/> /// among its members or descendants. /// </param> /// <param name="memberGroup"> /// Another group which may potentially be added to the /// members of <paramref name="group"/> if it's allowed. /// </param> /// <returns> /// <c>true</c> if the given <paramref name="memberGroup"/> /// is a member of the given <paramref name="group"/> or of /// a descendant group; otherwise, <c>false</c>. /// </returns> public bool IsMemberGroup(Group group, GroupMember memberGroup) { return this.IsMemberGroup(group, memberGroup, 0); }
public void UnassignGroup(Group group) { 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.internalGroup.RemoveGroup(group); DomainEventPublisher .Instance .Publish(new GroupUnassignedFromRole( this.TenantId, this.Name, group.Name)); }
public bool ConfirmUser(Group group, User user) { var confirmedUser = this.userRepository.UserWithUsername(group.TenantId, user.Username); var userConfirmed = confirmedUser == null || !confirmedUser.Enabled; return userConfirmed; }
public Group ProvisionGroup(string name, string description) { AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active."); Group group = new Group(this.TenantId, name, description); DomainEventPublisher.Instance.Publish(new GroupProvisioned(this.TenantId, name)); return group; }
private void CreateInternalGroup() { String groupName = Group.ROLE_GROUP_PREFIX + Guid.NewGuid().ToString(); this.Group = new Group(this.TenantId, groupName, "Role backing group for: " + this.Name); }
/// <summary> /// Determines whether a <see cref="User"/>'s declared /// membership in a <see cref="Group"/> is valid. /// </summary> /// <param name="group"> /// An instance of <see cref="Group"/> which may have /// the <paramref name="user"/> as a member. /// </param> /// <param name="user"> /// An instance of <see cref="User"/> which may be /// a member of the <paramref name="group"/>. /// </param> /// <returns> /// <c>true</c> if the <paramref name="user"/>'s /// <see cref="User.TenantId"/> matches that of /// the <paramref name="group"/> and the user's /// <see cref="User.IsEnabled"/> property is true; /// otherwise, <c>false</c>. /// </returns> public bool ConfirmUser(Group group, User user) { User confirmedUser = this.userRepository.UserWithUsername(group.TenantId, user.Username); return ((confirmedUser == null) || (!confirmedUser.IsEnabled)); }
private bool IsMemberGroup(Group group, GroupMember memberGroup, int recursionCount) { if (recursionCount > MaxGroupNestingRecursion) { throw new InvalidOperationException("The maximum depth of group nesting has been exceeded, stopping recursive function."); } bool isMember = false; foreach (GroupMember member in group.GroupMembers.Where(x => x.IsGroup)) { if (memberGroup.Equals(member)) { isMember = true; } else { Group nestedGroup = this.groupRepository.GroupNamed(member.TenantId, member.Name); if (nestedGroup != null) { int nextRecursionCount = (recursionCount + 1); isMember = this.IsMemberGroup(nestedGroup, memberGroup, nextRecursionCount); } } if (isMember) { break; } } return isMember; }
public bool IsUserInNestedGroup(Group group, User user) { bool isInNestedGroup = false; foreach (GroupMember member in group.GroupMembers) { if (member.IsGroup()) { Group nestedGroup = this.GroupRepository .GroupNamed(member.TenantId, member.Name); if (nestedGroup != null) { isInNestedGroup = nestedGroup.IsMember(user, this); } } if (isInNestedGroup) { break; } } return isInNestedGroup; }