Example #1
0
        private static bool FindUser(string username, string domain, out ADUser user)
        {
            UmConnectivityCredentialsHelper.DebugTrace("Inside FindUser()", new object[0]);
            user = null;
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domain), 500, "FindUser", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\um\\UmConnectivityCredentialsHelper.cs");
            string            sUserPrincipalName = username + "@" + domain;

            try
            {
                using (WindowsIdentity windowsIdentity = new WindowsIdentity(sUserPrincipalName))
                {
                    user = (ADUser)tenantOrRootOrgRecipientSession.FindBySid(windowsIdentity.User);
                }
            }
            catch (SecurityException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (ArgumentException)
            {
            }
            catch (LocalizedException)
            {
            }
            if (user == null)
            {
                string accountName = domain + "\\" + username;
                try
                {
                    user = (ADUser)tenantOrRootOrgRecipientSession.FindByAccountName <ADRecipient>(domain, accountName);
                }
                catch (LocalizedException)
                {
                }
            }
            if (user == null)
            {
                if (username.Length > 20)
                {
                    username = username.Substring(0, 20);
                }
                try
                {
                    user = (ADUser)tenantOrRootOrgRecipientSession.FindByAccountName <ADRecipient>(domain, username);
                }
                catch (LocalizedException)
                {
                }
            }
            return(user != null);
        }
        internal IEnumerable <T> GetObjectsByAccountName <T>(string accountName, ADObjectId rootId, IRecipientSession session, OptionalIdentityData optionalData) where T : IConfigurable, new()
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            QueryFilter queryFilter = RecipientIdParameter.GetRecipientTypeFilter(this.RecipientTypes);

            queryFilter = QueryFilter.AndTogether(new QueryFilter[]
            {
                queryFilter,
                this.AdditionalQueryFilter,
                (optionalData != null) ? optionalData.AdditionalFilter : null
            });
            return(session.FindByAccountName <T>(null, accountName, rootId, queryFilter));
        }