protected function _getLdapGroups(): array
    {
        $result = [];

        $config = (array)Configure::read('Groups.remoteGroups.LDAP');
        if (!empty(array_diff($this->ldapRequiredParams, array_keys($config)))) {
            return $result;
        }

        $connection = $this->_ldapConnect($config);
        if (!is_resource($connection)) {
            return $result;
        }

        $search = ldap_search($connection, $config['baseDn'], $config['groupsFilter'], ['cn']);
        if (!is_resource($search)) {
            Log::critical('Failed to search LDAP');

            return $result;
        }

        $result = ldap_get_entries($connection, $search);

        if (empty($result)) {
            return $result;
        }

        return $this->_normalizeResult($result);
    }