private bool LoadProfile(LdapConnection connection, LdapIdentity domain, LdapIdentity user, out LdapProfile profile)
        {
            profile = null;

            var attributes   = new[] { "DistinguishedName", "displayName", "mail", "telephoneNumber", "mobile" };
            var searchFilter = $"(&(objectClass=user)({user.TypeName}={user.Name}))";

            var baseDn = SelectBestDomainToQuery(connection, user, domain);

            _logger.Debug($"Querying user '{user.Name}' in {baseDn.Name}");

            var response = Query(connection, baseDn.Name, searchFilter, SearchScope.Subtree, attributes);

            if (response.Entries.Count == 0)
            {
                _logger.Error($"Unable to find user '{user.Name}' in {baseDn.Name}");
                return(false);
            }

            var entry = response.Entries[0];

            profile = new LdapProfile
            {
                BaseDn            = LdapIdentity.BaseDn(entry.DistinguishedName),
                DistinguishedName = entry.DistinguishedName,
                DisplayName       = entry.Attributes["displayName"]?[0]?.ToString(),
                Email             = entry.Attributes["mail"]?[0]?.ToString(),
                Phone             = entry.Attributes["telephoneNumber"]?[0]?.ToString(),
                Mobile            = entry.Attributes["mobile"]?[0]?.ToString(),
            };

            _logger.Debug($"User '{user.Name}' profile loaded: {profile.DistinguishedName}");

            return(true);
        }
        protected override bool IsMemberOf(LdapConnection connection, LdapIdentity domain, LdapIdentity user, LdapProfile profile, string groupName)
        {
            var isValidGroup = IsValidGroup(connection, domain, groupName, out var group);

            if (!isValidGroup)
            {
                _logger.Warning($"Security group '{groupName}' not exists in {domain.Name}");
                return(false);
            }

            var searchFilter = $"(&({Names.Identity(user)}={user.Name})(memberOf:1.2.840.113556.1.4.1941:={group.Name}))";
            var response     = Query(connection, domain.Name, searchFilter, LdapSearchScope.LDAP_SCOPE_SUB, "DistinguishedName");

            return(response.Any());
        }
Ejemplo n.º 3
0
        protected override async Task LoadAllUserGroups(LdapConnection connection, LdapIdentity domain, LdapProfile profile, ClientConfiguration clientConfig)
        {
            var searchFilter = $"(member:1.2.840.113556.1.4.1941:={profile.DistinguishedName})";
            var response     = await Query(connection, domain.Name, searchFilter, LdapSearchScope.LDAP_SCOPE_SUB, "DistinguishedName");

            profile.MemberOf = response.Select(entry => entry.Dn).ToList();
        }