5 define(
'IL_LDAP_BIND_ANONYMOUS',0);
6 define(
'IL_LDAP_BIND_USER',1);
8 define(
'IL_LDAP_SCOPE_SUB',0);
9 define(
'IL_LDAP_SCOPE_ONE',1);
10 define(
'IL_LDAP_SCOPE_BASE',2);
47 $this->server_id = $a_server_id;
54 if(isset(self::$instances[$a_server_id]))
56 return self::$instances[$a_server_id];
58 return self::$instances[$a_server_id] =
new ilLDAPServer($a_server_id);
67 return function_exists(
'ldap_bind');
79 $query =
"SELECT server_id FROM ldap_server_settings ".
80 "WHERE active = 1 AND authentication = 1 ".
83 $server_ids = array();
84 while(
$row = $ilDB->fetchObject(
$res))
86 $server_ids[] =
$row->server_id;
100 $query =
"SELECT server_id FROM ldap_server_settings ".
102 "AND sync_per_cron = 1 ".
106 while(
$row = $ilDB->fetchObject(
$res))
108 $server_ids[] =
$row->server_id;
110 return $server_ids ? $server_ids : array();
124 $query =
"SELECT server_id FROM ldap_server_settings ".
126 "AND role_sync_active = 1 ";
129 $server_ids = array();
130 while(
$row = $ilDB->fetchObject(
$res))
132 $server_ids[] =
$row->server_id;
174 $query =
"SELECT server_id FROM ldap_server_settings ORDER BY name";
177 while(
$row = $ilDB->fetchObject(
$res))
179 $server_ids[] =
$row->server_id;
181 return $server_ids ? $server_ids : array();
205 $query =
"SELECT server_id FROM ldap_server_settings ".
206 "WHERE active = ".$ilDB->quote(1,
'integer').
" ".
207 "AND authentication = ".$ilDB->quote(0,
'integer').
" ".
208 "AND ( authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
209 "OR authentication_type = ".$ilDB->quote(0,
'integer').
")";
212 $server_ids = array();
215 $server_ids[] =
$row->server_id;
230 $query =
"SELECT server_id FROM ldap_server_settings ".
231 "WHERE authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
232 "AND authentication = ".$ilDB->quote(0,
'integer');
245 $query =
"SELECT server_id FROM ldap_server_settings ".
246 "WHERE authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
247 "AND authentication = ".$ilDB->quote(0,
'integer');
251 return $row->server_id;
268 $query =
"UPDATE ldap_server_settings ".
269 "SET authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
270 "WHERE authentication = ".$ilDB->quote(0,
'integer');
275 $query =
"UPDATE ldap_server_settings ".
276 "SET authentication_type = ".$ilDB->quote(0,
'integer').
" ".
277 "WHERE authentication = ".$ilDB->quote(0,
'integer');
295 $this->enabled_authentication = (bool) $a_status;
313 $this->authentication_mapping = $a_map;
341 $this->active = $a_status;
345 return $this->active;
353 $this->url_string = $a_url;
356 $urls = explode(
',',$a_url);
359 foreach($urls as $url)
368 $this->fallback_urls[] = $url;
374 return $this->url_string;
388 include_once(
'Services/LDAP/classes/class.ilLDAPQuery.php');
390 foreach(array_merge(array(0 => $this->url),$this->fallback_urls) as $url)
398 $ilLog->write(__METHOD__.
': Using url: '.$url.
'.');
403 $ilLog->write(__METHOD__.
': Cannot connect to LDAP server: '.$url.
'. Trying fallback...');
406 $ilLog->write(__METHOD__.
': No valid LDAP server found.');
417 $this->name = $a_name;
425 $this->version = $a_version;
429 return $this->base_dn;
433 $this->base_dn = $a_base_dn;
437 return $this->referrals ?
true :
false;
441 $this->referrals = $a_status;
445 return $this->tls ?
true :
false;
449 $this->tls = $a_status;
453 return $this->binding_type;
468 return $this->bind_user;
472 $this->bind_user = $a_user;
476 return $this->bind_password;
480 $this->bind_password = $a_password;
484 return $this->search_base;
488 $this->search_base = $a_search_base;
492 return $this->user_attribute;
496 $this->user_attribute = $a_user_attr;
504 $this->filter = $a_filter;
508 return $this->group_dn;
512 $this->group_dn = $a_value;
520 $this->group_filter = $a_value;
524 return $this->group_member;
528 $this->group_member = $a_value;
532 return $this->group_name;
536 $this->group_name = $a_value;
549 if(!is_array($names))
553 foreach($names as $name)
555 $new_names[] = trim($name);
563 return $this->group_attribute;
567 $this->group_attribute = $a_value;
572 $this->group_optional = (bool) $a_status;
576 return (
bool) $this->group_optional;
580 $this->group_user_filter = $a_filter;
584 return $this->group_user_filter;
589 return (
bool) $this->memberisdn;
593 $this->memberisdn = (bool) $a_value;
597 $this->group_scope = $a_value;
601 return $this->group_scope;
605 $this->user_scope = $a_value;
609 return $this->user_scope;
613 return $this->sync_on_login;
617 $this->sync_on_login = (int) $a_value;
621 return $this->sync_per_cron;
625 $this->sync_per_cron = (int) $a_value;
629 $this->global_role = $a_role;
637 $this->role_bind_dn = $a_value;
645 $this->role_bind_pass = $a_value;
653 $this->role_sync_active = $a_value;
665 $this->account_migration = $a_status;
676 return $this->account_migration ?
true :
false;
689 $ilErr->setMessage(
'');
690 if(!strlen($this->
getName()) ||
691 !strlen($this->
getUrl()) ||
695 $ilErr->setMessage($this->lng->txt(
'fill_out_all_required_fields'));
701 $ilErr->appendMessage($this->lng->txt(
'ldap_missing_bind_user'));
706 $ilErr->appendMessage($this->lng->txt(
'ldap_missing_role_assignment'));
710 $ilErr->appendMessage($this->lng->txt(
'ldap_tls_conflict'));
713 return strlen($ilErr->getMessage()) ?
false :
true;
720 $next_id = $ilDB->nextId(
'ldap_server_settings');
722 $query =
'INSERT INTO ldap_server_settings (server_id,active,name,url,version,base_dn,referrals,tls,bind_type,bind_user,bind_pass,'.
723 'search_base,user_scope,user_attribute,filter,group_dn,group_scope,group_filter,group_member,group_memberisdn,group_name,'.
724 'group_attribute,group_optional,group_user_filter,sync_on_login,sync_per_cron,role_sync_active,role_bind_dn,role_bind_pass,migration, '.
725 'authentication,authentication_type) '.
726 'VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)';
729 'integer',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
'text',
'text',
'text',
'integer',
730 'text',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
731 'text',
'text',
'integer',
'integer',
'integer'),
774 $query =
"UPDATE ldap_server_settings SET ".
775 "active = ".$this->db->quote($this->
isActive(),
'integer').
", ".
776 "name = ".$this->db->quote($this->
getName(),
'text').
", ".
777 "url = ".$this->db->quote($this->
getUrlString(),
'text').
", ".
778 "version = ".$this->db->quote($this->
getVersion(),
'integer').
", ".
779 "base_dn = ".$this->db->quote($this->
getBaseDN(),
'text').
", ".
781 "tls = ".$this->db->quote($this->
isActiveTLS(),
'integer').
", ".
782 "bind_type = ".$this->db->quote($this->
getBindingType(),
'integer').
", ".
783 "bind_user = ".$this->db->quote($this->
getBindUser(),
'text').
", ".
785 "search_base = ".$this->db->quote($this->
getSearchBase(),
'text').
", ".
786 "user_scope = ".$this->db->quote($this->
getUserScope(),
'integer').
", ".
787 "user_attribute = ".$this->db->quote($this->
getUserAttribute(),
'text').
", ".
788 "filter = ".$this->db->quote($this->
getFilter(),
'text').
", ".
789 "group_dn = ".$this->db->quote($this->
getGroupDN(),
'text').
", ".
790 "group_scope = ".$this->db->quote($this->
getGroupScope(),
'integer').
", ".
791 "group_filter = ".$this->db->quote($this->
getGroupFilter(),
'text').
", ".
792 "group_member = ".$this->db->quote($this->
getGroupMember(),
'text').
", ".
794 "group_name = ".$this->db->quote($this->
getGroupName(),
'text').
", ".
798 "sync_on_login = ".$this->db->quote(($this->
enabledSyncOnLogin() ? 1 : 0),
'integer').
", ".
799 "sync_per_cron = ".$this->db->quote(($this->
enabledSyncPerCron() ? 1 : 0),
'integer').
", ".
801 "role_bind_dn = ".$this->db->quote($this->
getRoleBindDN(),
'text').
", ".
806 "WHERE server_id = ".$this->db->quote($this->
getServerId(),
'integer');
830 $options[
'start_tls'] = (bool) $this->
isActiveTLS();
835 $options[
'userscope'] =
'one';
838 $options[
'userscope'] =
'sub';
843 $options[
'userfilter'] = $this->
getFilter();
847 if(@include_once(
'Log.php'))
849 if(@include_once(
'Log/observer.php'))
851 $options[
'enableLogging'] =
true;
857 $options[
'groupscope'] =
'base';
860 $options[
'groupscope'] =
'one';
863 $options[
'groupscope'] =
'sub';
886 $filter = trim($a_filter);
893 if(strpos($filter,
'(') !== 0)
895 $filter = (
'('.$filter);
897 if(substr($filter,-1) !=
')')
899 $filter = ($filter.
')');
915 include_once(
'Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
916 include_once(
'Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php');
920 $mapping->getFields(),
939 if(!$this->server_id)
943 $query =
"SELECT * FROM ldap_server_settings WHERE server_id = ".$this->db->quote($this->server_id).
"";