/// <summary> /// This method will do a simple check by just comparing email /// address to email address. /// </summary> /// <param name="policyList">The policy control list to check against</param> /// <returns>True if all entries do exist in the policy list</returns> private bool CheckSimple(IAddressCollection policyList) { bool res = false; // Check this list against the policy list foreach( Address adr in List ) { if ( policyList[adr.Email] != null ) { adr.IsFound = true; m_found++; } } // Where all the of the email detected if ( Found == Count ) res = true; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Simple Check result = {0}", res.ToString(System.Threading.Thread.CurrentThread.CurrentCulture)); Logger.LogInfo(sb.ToString()); return res; }
/// <summary> /// This method will check that all the addresses appear at /// least once in the policy list. /// </summary> /// <param name="addresses">The addresses to be checked</param> /// <param name="policyList">The list to be checked against</param> /// <returns>True if all the addresses appear at least once in the policy list</returns> public bool IsMemberOf(IAddressCollection addresses, System.Collections.ArrayList policyList) { return m_impl.IsMemberOf(addresses, policyList); }
/// <summary> /// This method will check that all the addresses appear at /// least once in the policy list. /// </summary> /// <param name="addresses">The addresses to be checked</param> /// <param name="policyList">The list to be checked against</param> /// <returns>True if all the addresses appear at least once in the policy list</returns> public bool IsMemberOf(IAddressCollection addresses, IAddressCollection policyList) { return m_impl.IsMemberOf(addresses, policyList); }
/// <summary> /// This method will process the policy list to see if this /// collection is contained within it. /// </summary> /// <param name="policyList">The policy control list to check against</param> /// <returns>True if all addresses are contained in the policyList</returns> public bool ContainMembersOf(IAddressCollection policyList) { bool res = true; ResetFoundStatus(); if ( CheckSimple(policyList) == false ) if ( CheckWildCard(policyList) == false ) if ( CheckLdapGroup(policyList) == false ) res = false; if ( res == false ) { // Check to see if they have all been the hard way if ( Found == Count ) res = true; } return res; }
/// <summary> /// This method will return an array of members that belong to any /// groups and any individual members. /// </summary> /// <remarks>Will only add members if they have not been found already</remarks> /// <param name="addresses">The list of addresses to check</param> /// <returns>An array of members found.</returns> private ArrayList GetMemberList(IAddressCollection addresses) { ArrayList al = new ArrayList(); // Process the list foreach( Address addr in addresses ) { // Check to see if any have been found already if ( addr.IsFound ) continue; // Check for Ldap Users if ( addr.LdapType == ClassType.User || addr.LdapType == ClassType.NotLdap) { al.Add(addr); continue; } // Check for group if ( addr.LdapType == ClassType.Group ) { GetMembers(addr, al); } } return al; }
/// <summary> /// This method will do a group check by just comparing email /// address to email address and check group membership. /// </summary> /// <param name="policyList">The policy control list to check against</param> /// <returns>True if all entries do exist in the policy list</returns> private bool CheckLdapGroup(IAddressCollection policyList) { ArrayList m1 = null; ArrayList m2 = null; bool res = false; if ( m_isAvailable && (ContainsGroups || ((AddressCollection)policyList).ContainsGroups )) { // Either side could have a group which we will need to process. m1 = GetMemberList(this); // Check if we need to the processing or not. if ( m1.Count > 0 ) { m2 = GetMemberList(policyList); m2.Sort(); foreach( IAddress mem in m1 ) { int idx = m2.BinarySearch(0, m2.Count, mem, null); if ( idx > -1 ) { ((Address)mem).IsFound = true; m_found++; } } } } if ( Found == Count ) res = true; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Ldap Group Check result = {0}", res.ToString(System.Threading.Thread.CurrentThread.CurrentCulture)); Logger.LogInfo(sb.ToString()); return res; }
/// <summary> /// This method will do a group check by check for any policy /// addresses that have * in them. Then breaking down the /// local and domain information to compare with any email /// address in the internal list. /// </summary> /// <param name="policyList">The policy control list to check against</param> /// <returns>True if all entries do exist in the policy list</returns> private bool CheckWildCard(IAddressCollection policyList) { bool res = false; AddressCollection ac = policyList as AddressCollection; // Need to first check if any policy emails has a wild card in them if ( ac.ContainsWildCards ) { string[] wildCards = ac.RetrieveWildCards(); foreach( Address addr in List ) { if ( addr.IsFound == false ) { foreach( string wildCard in wildCards ) { if ( Regex.Match(addr.Email, wildCard, RegexOptions.IgnoreCase).Success ) { addr.IsFound = true; m_found++; break; } } } } } // Where all the of the email detected if ( Found == Count ) res = true; StringBuilder sb = new StringBuilder(); sb.AppendFormat("WildCard Check result = {0}", res.ToString(System.Threading.Thread.CurrentThread.CurrentCulture)); Logger.LogInfo(sb.ToString()); return res; }
public bool IsMemberOf(IAddressCollection addresses, System.Collections.ArrayList policyList) { if (addresses == null) { string msg = ResourceManager.GetString("LDAP_INVALIDADDR", "Workshare.DirectorySearcher.Exceptions", typeof(DirectoryAnalyzerImpl).Assembly); Logger.LogInfo(msg); throw (new ArgumentNullException(msg)); } if (policyList == null) { string msg = ResourceManager.GetString("LDAP_INVALIDADDR", "Workshare.DirectorySearcher.Exceptions", typeof(DirectoryAnalyzerImpl).Assembly); Logger.LogInfo(msg); throw (new ArgumentNullException(msg)); } try { string[] ads = new string[policyList.Count]; for (int i = 0; i < policyList.Count; i++) ads[i] = (policyList[i] as string); IAddressCollection policyaddresses = GetAddressCollectionInformation(ads); bool res = false; try { if (IsLdapAvailable) res = IsMemberOf(addresses, policyaddresses); } catch (LdapException) { //ignore for now res = false; } return res; } catch (InvalidOperationException e) { System.Diagnostics.Debug.Assert(false, e.Message); } return false; }
public bool IsMemberOf(IAddressCollection addresses, IAddressCollection policyList) { if (addresses == null ) { string msg = ResourceManager.GetString("LDAP_INVALIDADDR", "Workshare.DirectorySearcher.Exceptions", typeof(DirectoryAnalyzerImpl).Assembly); Logger.LogInfo(msg); throw (new ArgumentNullException(msg)); } if (policyList == null) { string msg = ResourceManager.GetString("LDAP_INVALIDADDR", "Workshare.DirectorySearcher.Exceptions", typeof(DirectoryAnalyzerImpl).Assembly); Logger.LogInfo(msg); throw (new ArgumentNullException(msg)); } StringBuilder sb = new StringBuilder(); sb.AppendFormat("Processing Addresses ({0}) against Policy List ({1}) - LDAP is {2}enabled.", addresses.Count, policyList.Count, (IsLdapAvailable ? "" : "NOT ")); Logger.LogInfo(sb.ToString()); bool res = false; try { if ( IsLdapAvailable ) res = addresses.ContainMembersOf(policyList); } catch( LdapException ) { //ignore for now res = false; } return res; }