public async Task GetMembersFromSourceAsync(GroupMemberCollection memberCollection, GrouperDocumentMember grouperMember) { await GetGroupMembersAsync( memberCollection, Guid.Parse(grouperMember.Rules.Where(r => r.Name.IEquals("Group")).First().Value) ); }
public async Task GetMembersFromSourceAsync(GroupMemberCollection memberCollection, GrouperDocumentMember grouperMember, GroupMemberTypes memberType) { if (memberType != GroupMemberTypes.OnPremAd) { throw new ArgumentException("Invalid member type", nameof(memberType)); } switch (grouperMember.Source) { case GroupMemberSources.OnPremAdGroup: await GetGroupMembersAsync( memberCollection, Guid.Parse(grouperMember.Rules.Where(r => r.Name.IEquals("Group")).First().Value) ); break; case GroupMemberSources.OnPremAdQuery: string filter = grouperMember.Rules.Where(r => r.Name.IEquals("LdapFilter")).FirstOrDefault()?.Value; string searchBase = grouperMember.Rules.Where(r => r.Name.IEquals("SearchBase")).FirstOrDefault()?.Value; QueryGroupMembers(memberCollection, filter, searchBase); break; default: throw new ArgumentException(nameof(grouperMember)); } }
public void TestCountOne() { GroupMemberCollection collection = new GroupMemberCollection(); collection.Add(azureMember1); Assert.Equal(1, collection.Count); }
private async Task GetMembersFromPersonalsystemAsync(GroupMemberCollection memberCollection, GrouperDocumentMember member) { var befattning = new List <string>(); string organisation = null; bool includeManager = false; foreach (GrouperDocumentRule rule in member.Rules) { if (rule.Name.IEquals("Organisation")) { organisation = rule.Value.NullIfEmpty(); } else if (rule.Name.IEquals("Befattning") && !string.IsNullOrEmpty(rule.Value)) { befattning.Add(rule.Value); } else if (rule.Name.IEquals("IncludeManager")) { includeManager = rule.Value.IEquals("true"); } } await GetMembersAsync("dbo.spGrouperPersonalsystem", member.MemberType, memberCollection, new Dictionary <string, object>() { { "organisation", organisation }, { "befattning", befattning.ToArray() }, { "include_manager", includeManager } } ); }
public async Task GetGroupMembersAsync(GroupMemberCollection memberCollection, Guid groupId) { string command = $"Get-DistributionGroupMember -Identity '{groupId.ToString()}' -ErrorAction 'Stop'"; Collection <PSObject> result; try { result = InvokeCommand(command); } catch (RemoteException ex) { if (IsNotFoundError(ex)) { Exception notFoundException = CreateNotFoundException(groupId, null, ex); if (notFoundException != null) { throw notFoundException; } } throw; } if (result != null) { foreach (var member in result) { memberCollection.Add(new GroupMember( id: (string)member.Properties["ExternalDirectoryObjectId"].Value, displayName: (string)member.Properties["PrimarySmtpAddress"].Value, memberType: GroupMemberTypes.AzureAd )); } } await Task.FromResult(0); }
private void QueryGroupMembers(GroupMemberCollection memberCollection, string ldapFilter, string searchBase) { if (ldapFilter == null) { throw new ArgumentNullException(nameof(ldapFilter)); } using (DirectoryEntry searchRoot = GetDirectoryEntry(searchBase)) using (DirectorySearcher directorySearcher = new DirectorySearcher(searchRoot, ldapFilter, new string[] { "objectGUID", "userPrincipalName" })) { directorySearcher.PageSize = 1000; SearchResultCollection result = directorySearcher.FindAll(); foreach (SearchResult item in result) { Guid identity = new Guid((byte[])item.Properties["objectGuid"][0]); string displayName; if (item.Properties["userPrincipalName"].Count == 1) { displayName = (string)item.Properties["userPrincipalName"][0]; } else { displayName = identity.ToString(); } memberCollection.Add(new GroupMember(identity, displayName, GroupMemberTypes.OnPremAd)); } } }
public void TestConstructionWithUnchangedCollectionNull() { GroupMemberCollection col1 = new GroupMemberCollection(); GroupMemberCollection col2 = new GroupMemberCollection(); Assert.Throws <ArgumentNullException>(() => { new GroupMemberDiff(TestHelpers.MakeDocument(), col1, col2, unchangedMemberCollection: null, 0.5); }); }
public async Task GetGroupMembersAsync(GroupMemberCollection memberCollection, Guid groupId) { await AssureGraphClient(); try { var members = await _graphClient.Groups[groupId.ToString()].Members.Request().GetAsync(); do { foreach (var member in members) { if (member is User u) { memberCollection.Add(new GroupMember(Guid.Parse(u.Id), u.UserPrincipalName, GroupMemberTypes.AzureAd)); } else { memberCollection.Add(new GroupMember(Guid.Parse(member.Id), member.Id, GroupMemberTypes.AzureAd)); } } }while (members.NextPageRequest != null && (members = await members.NextPageRequest.GetAsync()).Count > 0); } catch (ServiceException ex) { if (IsNotFoundError(ex)) { throw GroupNotFoundException.Create(groupId, ex); } throw; } }
public async Task GetMembersFromSourceAsync(GroupMemberCollection memberCollection, GrouperDocumentMember grouperMember) { switch (grouperMember.Source) { case GroupMemberSources.Elevregister: await GetMembersFromElevregisterAsync(memberCollection, grouperMember); break; case GroupMemberSources.Personalsystem: await GetMembersFromPersonalsystemAsync(memberCollection, grouperMember); break; case GroupMemberSources.Static: await GetMembersFromUpnAsync(memberCollection, grouperMember); break; case GroupMemberSources.CustomView: await GetMembersFromCustomViewAsync(memberCollection, grouperMember); break; default: throw new ArgumentException(nameof(grouperMember)); } }
private async Task <GroupMemberCollection> GetCurrentMembersAsync(GrouperDocument document) { var memberCollection = new GroupMemberCollection(); IGroupStore store = GetGroupStore(document); await store.GetGroupMembersAsync(memberCollection, document.GroupId); return(memberCollection); }
public void TestConstructionWithDocumentNull() { GroupMemberCollection col1 = new GroupMemberCollection(); GroupMemberCollection col2 = new GroupMemberCollection(); GroupMemberCollection col3 = new GroupMemberCollection(); Assert.Throws <ArgumentNullException>(() => { new GroupMemberDiff(document: null, col1, col2, col3, 0.5); }); }
private async Task GetMembersFromUpnAsync(GroupMemberCollection memberCollection, GrouperDocumentMember member) { await GetMembersAsync("dbo.spGrouperStaticMember", member.MemberType, memberCollection, new Dictionary <string, object>() { { "upn", member.Rules.Where(r => r.Name.IEquals("Upn") && !string.IsNullOrEmpty(r.Value)).Select(r => r.Value).ToArray() } } ); }
private async Task GetMembersFromElevregisterAsync(GroupMemberCollection memberCollection, GrouperDocumentMember member) { var arskurs = new List <string>(); bool elev = true; bool personal = true; string skolform = null; string enhet = null; string klass = null; string grupp = null; foreach (GrouperDocumentRule rule in member.Rules) { if (rule.Name.IEquals("Roll")) { if (rule.Value.IEquals("Elev")) { personal = false; } else if (rule.Value.IEquals("Personal")) { elev = false; } } else if (rule.Name.IEquals("Skolform")) { skolform = rule.Value.NullIfEmpty(); } else if (rule.Name.IEquals("Enhet")) { enhet = rule.Value.NullIfEmpty(); } else if (rule.Name.IEquals("Klass")) { klass = rule.Value.NullIfEmpty(); } else if (rule.Name.IEquals("Grupp")) { grupp = rule.Value.NullIfEmpty(); } else if (rule.Name.IEquals("Årskurs") && !string.IsNullOrEmpty(rule.Value)) { arskurs.Add(rule.Value); } } await GetMembersAsync("dbo.spGrouperElevregister", member.MemberType, memberCollection, new Dictionary <string, object>() { { "skolform", skolform }, { "enhet", enhet }, { "klass", klass }, { "grupp", grupp }, { "arskurs", arskurs.ToArray() }, { "elev", elev }, { "personal", personal } } ); }
public void TestAddMember() { GroupMemberCollection collection = new GroupMemberCollection(); collection.Add(azureMember1); GroupMember member = collection.AsEnumerable().First(); Assert.Equal(azureMember1.Id, member.Id); }
private async Task GetMembersFromCustomViewAsync(GroupMemberCollection memberCollection, GrouperDocumentMember member) { await GetMembersAsync("dbo.spGrouperCustomView", member.MemberType, memberCollection, new Dictionary <string, object>() { { "view", member.Rules.Where(r => r.Name.IEquals("View")).First().Value } } ); }
public void TestAddCollection() { GroupMemberCollection collection1 = new GroupMemberCollection(); GroupMemberCollection collection2 = new GroupMemberCollection(); collection1.Add(azureMember1); collection2.Add(azureMember2); collection1.Add(collection2); Assert.Equal(2, collection1.Count); }
public async Task GetMembersFromSourceAsync(GroupMemberCollection memberCollection, GrouperDocumentMember grouperMember, GroupMemberTypes memberType) { if (memberType != GroupMemberTypes.AzureAd) { throw new ArgumentException("Invalid member type", nameof(memberType)); } await GetGroupMembersAsync( memberCollection, Guid.Parse(grouperMember.Rules.Where(r => r.Name.IEquals("Group")).First().Value) ); }
public async Task <GroupMemberDiff> GetMemberDiffAsync(GrouperDocument document, bool includeUnchanged = false) { if (document is null) { throw new ArgumentNullException(nameof(document)); } var currentMembers = await GetCurrentMembersAsync(document); var targetMembers = await GetTargetMembersAsync(document); IGroupOwnerSource ownerSource = GetOwnerSource(document); if (ownerSource != null) { if (document.Owner != GroupOwnerActions.MatchSource) { var owners = new GroupMemberCollection(); await ownerSource.GetGroupOwnersAsync(owners, document.GroupId); if (document.Owner == GroupOwnerActions.KeepExisting) { owners.IntersectWith(currentMembers); } targetMembers.Add(owners); } } if (!currentMembers.ContainsMatchingMemberType(targetMembers)) { throw new InvalidOperationException("Member types does not match"); } GroupMemberCollection unchangedMembers = new GroupMemberCollection(); if (includeUnchanged) { unchangedMembers = currentMembers.Clone(); unchangedMembers.IntersectWith(targetMembers); } int currentCount = currentMembers.Count; currentMembers.FilterUniqueMember(targetMembers); double changeRatio; if (currentCount == 0) { changeRatio = targetMembers.Count == 0 ? 1.0 : targetMembers.Count; } else { changeRatio = (currentCount - currentMembers.Count + targetMembers.Count) / (double)currentCount; } return(new GroupMemberDiff(document, targetMembers, currentMembers, unchangedMembers, changeRatio)); }
public async Task GetGroupMembersAsync(GroupMemberCollection memberCollection, Guid groupId) { string groupDn = GetDistinguishedName(groupId); if (groupDn == null) { throw GroupNotFoundException.Create(groupId); } string filter = $"(memberOf={groupDn})"; QueryGroupMembers(memberCollection, filter, null); await Task.FromResult(0); }
public void TestExceptWith() { GroupMemberCollection collection1 = new GroupMemberCollection(); GroupMemberCollection collection2 = new GroupMemberCollection(); collection1.Add(azureMember1); collection1.Add(azureMember2); collection2.Add(azureMember2); collection1.ExceptWith(collection2); Assert.Equal(1, collection1.Count); Exception exception = Record.Exception(() => collection1.AsEnumerable().First(m => m.Id == azureMember1.Id)); Assert.Null(exception); }
private async Task <GroupMemberCollection> GetTargetMembersAsync(GrouperDocument document) { var include = new GroupMemberCollection(); var exclude = new GroupMemberCollection(); foreach (GrouperDocumentMember member in document.Members) { var memberCollection = member.Action == GroupMemberActions.Exclude ? exclude : include; IMemberSource source = GetMemberSource(member); await source.GetMembersFromSourceAsync(memberCollection, member); } include.ExceptWith(exclude); return(include); }
private async Task <GroupMemberCollection> GetTargetMembersAsync(GrouperDocument document, GroupMemberCollection currentMembers) { var include = new GroupMemberCollection(); var exclude = new GroupMemberCollection(); if (!(document.Members.Any(m => m.Action == GroupMemberActions.Include))) { include.Add(currentMembers); } foreach (GrouperDocumentMember member in document.Members) { var memberCollection = member.Action == GroupMemberActions.Exclude ? exclude : include; IMemberSource source = GetMemberSource(member); await source.GetMembersFromSourceAsync(memberCollection, member, document.MemberType); } include.ExceptWith(exclude); return(include); }
public async Task GetGroupMembersAsync(GroupMemberCollection memberCollection, Guid groupId) { using (var conn = new SqlConnection(_connectionString)) { await conn.OpenAsync(); using (var cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dbo.spOpenEGetGroupMember"; cmd.Parameters.AddWithValue("groupId", groupId); SqlDataReader reader = null; try { reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { memberCollection.Add(new GroupMember( reader.GetGuid(1), reader.GetString(2), GroupMemberTypes.OnPremAd )); } } catch (SqlException e) { if (e.Number == 50001) { throw GroupNotFoundException.Create(groupId, e); } throw; } finally { if (reader != null) { reader.Dispose(); } } } } }
public void TestConstruction() { double ratio = 0.5; GrouperDocument doc = TestHelpers.MakeDocument(); GroupMemberCollection add = new GroupMemberCollection(); add.Add(new GroupMember(Guid.Empty, "M1", GroupMemberTypes.AzureAd)); GroupMemberCollection remove = new GroupMemberCollection(); remove.Add(new GroupMember(Guid.Empty, "M2", GroupMemberTypes.AzureAd)); GroupMemberCollection unchanged = new GroupMemberCollection(); unchanged.Add(new GroupMember(Guid.Empty, "M3", GroupMemberTypes.AzureAd)); GroupMemberDiff diff = new GroupMemberDiff(doc, add, remove, unchanged, ratio); Assert.NotNull(diff.Add.FirstOrDefault(m => m.DisplayName == "M1")); Assert.NotNull(diff.Remove.FirstOrDefault(m => m.DisplayName == "M2")); Assert.NotNull(diff.Unchanged.FirstOrDefault(m => m.DisplayName == "M3")); Assert.Equal(ratio, diff.ChangeRatio); Assert.Equal(doc, diff.Document); }
public void TestConstructionWithSameCollection() { GroupMemberCollection col = new GroupMemberCollection(); Assert.Throws <ArgumentException>(() => { new GroupMemberDiff(TestHelpers.MakeDocument(), col, col, col, 0.5); }); }
public void TestAsEnumerable() { GroupMemberCollection collection = new GroupMemberCollection(); Assert.NotNull(collection.AsEnumerable()); }
private async Task GetMembersAsync(string storedProcedure, GroupMemberTypes memberType, GroupMemberCollection memberCollection, IDictionary <string, object> parameters) { using (var conn = new SqlConnection(_connectionString)) { await conn.OpenAsync(); using (var cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = storedProcedure; // Something makes queries that normally takes seconds to sometimes time out // This is a workaround until I can find the root cause. cmd.CommandTimeout = 300; cmd.AddParameters(parameters); using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { if (memberType == GroupMemberTypes.OnPremAd) { Guid id = reader.GetNullable <Guid>(1); if (id != Guid.Empty) { memberCollection.Add(new GroupMember( id: id, displayName: reader.GetNullable <string>(0), memberType: GroupMemberTypes.OnPremAd )); } } else { Guid id = reader.GetNullable <Guid>(2); if (id != Guid.Empty) { memberCollection.Add(new GroupMember( id: id, displayName: reader.GetNullable <string>(0), memberType: GroupMemberTypes.AzureAd )); } } } } } } }
public void TestCountZero() { GroupMemberCollection collection = new GroupMemberCollection(); Assert.Equal(0, collection.Count); }
public Group() { GroupMembers = new GroupMemberCollection(); }