Пример #1
0
        /// <summary>
        /// Returns LDAP member info which are stored in the directory.
        /// </summary>
        /// <returns></returns>
        public LDAPMemberInfo GetMemberInfo()
        {
            DirectoryEntry DirEntry = new DirectoryEntry();
            {
                DirEntry.Path               = DirectoryPath;
                DirEntry.Username           = UserName;
                DirEntry.Password           = Password;
                DirEntry.AuthenticationType = AuthenticationTypes.Secure;
            }

            LDAPMemberInfo memberInfo = new LDAPMemberInfo();

            string[] nameParts = UserName.Split(new string[] { "@" }, StringSplitOptions.RemoveEmptyEntries);

            DirectorySearcher search = new DirectorySearcher(DirEntry);

            search.Filter = "(SAMAccountName=" + nameParts[0] + ")";
            search.PropertiesToLoad.Add("cn");
            search.PropertiesToLoad.Add("mail");
            try{
                SearchResult result = search.FindOne();
                if (null != result)
                {
                    memberInfo.DisplayName = (String)result.Properties["cn"][0];
                    memberInfo.Email       = (String)result.Properties["mail"][0];
                }
            }
            catch (Exception ex)
            {
                String Message = String.Format("Member:{0}, Message:{1}", UserName, ex.Message);
                AuditEvent.AppEventError(AppSession.Parameters.GeneralAdminEmail.Value, "LDAP obtaining member name failed. " + Message, AuditEvent.GetSessionDetails(Message), true);
            }

            return(memberInfo);
        }
Пример #2
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public LDAPTools()
 {
     MemberInfo = new LDAPMemberInfo();
 }