5define(
'IL_LDAP_BIND_ANONYMOUS', 0);
 
    6define(
'IL_LDAP_BIND_USER', 1);
 
    8define(
'IL_LDAP_SCOPE_SUB', 0);
 
    9define(
'IL_LDAP_SCOPE_ONE', 1);
 
   10define(
'IL_LDAP_SCOPE_BASE', 2);
 
   52        $this->server_id = $a_server_id;
 
   64        if (isset(self::$instances[$a_server_id])) {
 
   65            return self::$instances[$a_server_id];
 
   67        return self::$instances[$a_server_id] = 
new ilLDAPServer($a_server_id);
 
   80        if (!$this->fallback_urls) {
 
   84        $all_urls = array_merge($this->fallback_urls);
 
   85        $all_urls[] = $this->
getUrl();
 
   87        $query = 
'UPDATE ldap_server_settings SET ' .
 
   88                'url = ' . 
$ilDB->quote(implode(
',', $all_urls), 
'text') . 
' ' .
 
  101        return function_exists(
'ldap_bind');
 
  115        $query = 
"SELECT server_id FROM ldap_server_settings " .
 
  116            "WHERE active = 1 AND authentication = 1 " .
 
  119        $server_ids = array();
 
  120        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  121            $server_ids[] = $row->server_id;
 
  137        $query = 
"SELECT server_id FROM ldap_server_settings " .
 
  138            "WHERE active = 1 " .
 
  139            "AND sync_per_cron = 1 " .
 
  143        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  144            $server_ids[] = $row->server_id;
 
  146        return $server_ids ? $server_ids : array();
 
  162        $query = 
"SELECT server_id FROM ldap_server_settings " .
 
  163            "WHERE active = 1 " .
 
  164            "AND role_sync_active = 1 ";
 
  167        $server_ids = array();
 
  168        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  169            $server_ids[] = $row->server_id;
 
  195        if (count($servers)) {
 
  212        $query = 
"SELECT server_id FROM ldap_server_settings ORDER BY name";
 
  215        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  216            $server_ids[] = $row->server_id;
 
  218        return $server_ids ? $server_ids : array();
 
  232        $query = 
"SELECT server_id FROM ldap_server_settings ORDER BY name";
 
  255        $query = 
"SELECT * FROM ldap_server_settings ORDER BY name";
 
  275        if (count($servers)) {
 
  288        $query = 
"SELECT server_id FROM ldap_server_settings " .
 
  289            "WHERE active = " . 
$ilDB->quote(1, 
'integer') . 
" " .
 
  290            "AND authentication = " . 
$ilDB->quote(0, 
'integer') . 
" " .
 
  291            "AND ( authentication_type = " . 
$ilDB->quote($a_auth_mode, 
'integer') . 
" " .
 
  292            "OR authentication_type = " . 
$ilDB->quote(0, 
'integer') . 
")";
 
  295        $server_ids = array();
 
  297            $server_ids[] = $row->server_id;
 
  314        $query = 
"SELECT server_id FROM ldap_server_settings " .
 
  315            "WHERE authentication_type = " . 
$ilDB->quote($a_auth_mode, 
'integer') . 
" " .
 
  316            "AND authentication = " . 
$ilDB->quote(0, 
'integer');
 
  330        $query = 
"SELECT server_id FROM ldap_server_settings " .
 
  331            "WHERE authentication_type = " . 
$ilDB->quote($a_auth_mode, 
'integer') . 
" ";
 
  334            return $row->server_id;
 
  348        $query = 
'UPDATE ldap_server_settings ' .
 
  349            'SET authentication_type = ' . 
$ilDB->quote(0, 
'integer') . 
' ' .
 
  350            'WHERE authentication_type = ' . 
$ilDB->quote($a_authmode, 
'integer');
 
  372            $query = 
"UPDATE ldap_server_settings " .
 
  373                'SET authentication_type = ' . 
$ilDB->quote($a_auth_mode, 
'integer') . 
" " .
 
  374                'WHERE server_id = ' . 
$ilDB->quote($a_ldap_server_id, 
'integer');
 
  388            $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ . 
': No auth mode given..............');
 
  391        $auth_arr = explode(
'_', $a_auth_mode);
 
  392        return ($auth_arr[0] == 
AUTH_LDAP) and $auth_arr[1];
 
  402        if (self::isAuthModeLDAP($a_auth_mode)) {
 
  403            $auth_arr = explode(
'_', $a_auth_mode);
 
  415        $auth_arr = explode(
'_', $a_auth_key);
 
  416        if (count((array) $auth_arr) > 1) {
 
  417            return 'ldap_' . $auth_arr[1];
 
  429        $auth_arr = explode(
'_', $a_auth_mode);
 
  430        if (count((array) $auth_arr) > 1) {
 
  450        $this->enabled_authentication = (bool) $a_status;
 
  468        $this->authentication_mapping = $a_map;
 
  498        $this->active = $a_status;
 
  502        return $this->active;
 
  510        $this->url_string = $a_url;
 
  513        $urls = explode(
',', $a_url);
 
  516        foreach ($urls as 
$url) {
 
  521                $this->fallback_urls[] = 
$url;
 
  527        return $this->url_string;
 
  539        include_once(
'Services/LDAP/classes/class.ilLDAPQuery.php');
 
  541        foreach (array_merge(array(0 => $this->url), $this->fallback_urls) as 
$url) {
 
  551                ilLoggerFactory::getLogger(
'auth')->error(
'Cannot connect to LDAP server: ' . $url . 
' ' . $exc->getCode() . 
' ' . $exc->getMessage());
 
  565        $this->name = $a_name;
 
  573        $this->version = $a_version;
 
  577        return $this->base_dn;
 
  581        $this->base_dn = $a_base_dn;
 
  585        return $this->referrals ? 
true : 
false;
 
  589        $this->referrals = $a_status;
 
  593        return $this->tls ? 
true : 
false;
 
  597        $this->tls = $a_status;
 
  601        return $this->binding_type;
 
  613        return $this->bind_user;
 
  617        $this->bind_user = $a_user;
 
  621        return $this->bind_password;
 
  625        $this->bind_password = $a_password;
 
  629        return $this->search_base;
 
  633        $this->search_base = $a_search_base;
 
  637        return $this->user_attribute;
 
  641        $this->user_attribute = $a_user_attr;
 
  649        $this->
filter = $a_filter;
 
  653        return $this->group_dn;
 
  657        $this->group_dn = $a_value;
 
  665        $this->group_filter = $a_value;
 
  669        return $this->group_member;
 
  673        $this->group_member = $a_value;
 
  677        return $this->group_name;
 
  681        $this->group_name = $a_value;
 
  692        if (!is_array($names)) {
 
  696        return array_filter(array_map(
'trim', $names));
 
  702        return $this->group_attribute;
 
  706        $this->group_attribute = $a_value;
 
  711        $this->group_optional = (bool) $a_status;
 
  715        return (
bool) $this->group_optional;
 
  719        $this->group_user_filter = $a_filter;
 
  723        return $this->group_user_filter;
 
  728        return (
bool) $this->memberisdn;
 
  732        $this->memberisdn = (bool) $a_value;
 
  736        $this->group_scope = $a_value;
 
  740        return $this->group_scope;
 
  744        $this->user_scope = $a_value;
 
  748        return $this->user_scope;
 
  752        return $this->sync_on_login;
 
  756        $this->sync_on_login = (int) $a_value;
 
  760        return $this->sync_per_cron;
 
  764        $this->sync_per_cron = (int) $a_value;
 
  768        $this->global_role = $a_role;
 
  776        $this->role_bind_dn = $a_value;
 
  784        $this->role_bind_pass = $a_value;
 
  792        $this->role_sync_active = $a_value;
 
  797        return $this->username_filter;
 
  801        $this->username_filter = $a_value;
 
  806        $this->escape_dn = $a_value;
 
  823        $this->account_migration = $a_status;
 
  834        return $this->account_migration ? 
true : 
false;
 
  850        if (!strlen($this->
getName()) ||
 
  851            !strlen($this->
getUrl()) ||
 
  854            $ilErr->setMessage($this->lng->txt(
'fill_out_all_required_fields'));
 
  859            $ilErr->appendMessage($this->lng->txt(
'ldap_missing_bind_user'));
 
  863            $ilErr->appendMessage($this->lng->txt(
'ldap_missing_role_assignment'));
 
  866            $ilErr->appendMessage($this->lng->txt(
'ldap_tls_conflict'));
 
  869        return strlen(
$ilErr->getMessage()) ? false : 
true;
 
  877        $next_id = 
$ilDB->nextId(
'ldap_server_settings');
 
  879        $query = 
'INSERT INTO ldap_server_settings (server_id,active,name,url,version,base_dn,referrals,tls,bind_type,bind_user,bind_pass,' .
 
  880            'search_base,user_scope,user_attribute,filter,group_dn,group_scope,group_filter,group_member,group_memberisdn,group_name,' .
 
  881            'group_attribute,group_optional,group_user_filter,sync_on_login,sync_per_cron,role_sync_active,role_bind_dn,role_bind_pass,migration, ' .
 
  882            'authentication,authentication_type,username_filter, escape_dn) ' .
 
  883            '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,%s,%s)';
 
  887                'integer',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
'text',
'text',
'text',
'integer',
 
  888                'text',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
 
  889                'text',
'text', 
'integer',
'integer',
'integer',
"text", 
'integer'),
 
  928        $this->server_id = $next_id;
 
  938        $query = 
"UPDATE ldap_server_settings SET " .
 
  939            "active = " . $this->db->quote($this->
isActive(), 
'integer') . 
", " .
 
  940            "name = " . $this->db->quote($this->
getName(), 
'text') . 
", " .
 
  941            "url = " . $this->db->quote($this->
getUrlString(), 
'text') . 
", " .
 
  942            "version = " . $this->db->quote($this->
getVersion(), 
'integer') . 
", " .
 
  943            "base_dn = " . $this->db->quote($this->
getBaseDN(), 
'text') . 
", " .
 
  944            "referrals = " . $this->db->quote($this->
isActiveReferrer(), 
'integer') . 
", " .
 
  945            "tls = " . $this->db->quote($this->
isActiveTLS(), 
'integer') . 
", " .
 
  946            "bind_type = " . $this->db->quote($this->
getBindingType(), 
'integer') . 
", " .
 
  947            "bind_user = " . $this->db->quote($this->
getBindUser(), 
'text') . 
", " .
 
  948            "bind_pass = " . $this->db->quote($this->
getBindPassword(), 
'text') . 
", " .
 
  949            "search_base = " . $this->db->quote($this->
getSearchBase(), 
'text') . 
", " .
 
  950            "user_scope = " . $this->db->quote($this->
getUserScope(), 
'integer') . 
", " .
 
  951            "user_attribute = " . $this->db->quote($this->
getUserAttribute(), 
'text') . 
", " .
 
  952            "filter = " . $this->db->quote($this->
getFilter(), 
'text') . 
", " .
 
  953            "group_dn = " . $this->db->quote($this->
getGroupDN(), 
'text') . 
", " .
 
  954            "group_scope = " . $this->db->quote($this->
getGroupScope(), 
'integer') . 
", " .
 
  955            "group_filter = " . $this->db->quote($this->
getGroupFilter(), 
'text') . 
", " .
 
  956            "group_member = " . $this->db->quote($this->
getGroupMember(), 
'text') . 
", " .
 
  958            "group_name = " . $this->db->quote($this->
getGroupName(), 
'text') . 
", " .
 
  959            "group_attribute = " . $this->db->quote($this->
getGroupAttribute(), 
'text') . 
", " .
 
  961            "group_user_filter = " . $this->db->quote($this->
getGroupUserFilter(), 
'text') . 
", " .
 
  962            "sync_on_login = " . $this->db->quote(($this->
enabledSyncOnLogin() ? 1 : 0), 
'integer') . 
", " .
 
  963            "sync_per_cron = " . $this->db->quote(($this->
enabledSyncPerCron() ? 1 : 0), 
'integer') . 
", " .
 
  965            "role_bind_dn = " . $this->db->quote($this->
getRoleBindDN(), 
'text') . 
", " .
 
  970            ", username_filter = " . $this->db->quote($this->
getUsernameFilter(), 
"text") . 
" " .
 
  971            ", escape_dn = " . $this->db->quote($this->
enabledEscapeDN() ? 1 : 0, 
'integer') . 
" " .
 
  972            "WHERE server_id = " . $this->db->quote($this->
getServerId(), 
'integer');
 
  981    public function delete()
 
  987        include_once 
'Services/LDAP/classes/class.ilLDAPAttributeMapping.php';
 
  990        include_once 
'Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php';
 
  993        foreach ($rules as $ruleAssigment) {
 
  994            $ruleAssigment->delete();
 
  997        include_once 
'Services/LDAP/classes/class.ilLDAPRoleGroupMappingSettings.php';
 
 1000        $query = 
"DELETE FROM ldap_server_settings " .
 
 1001            "WHERE server_id = " . $this->db->quote($this->
getServerId(), 
'integer');
 
 1013            'url' => $this->
getUrl(),
 
 1021        $options[
'basedn'] = $this->
getBaseDN();
 
 1022        $options[
'start_tls'] = (bool) $this->
isActiveTLS();
 
 1026                $options[
'userscope'] = 
'one';
 
 1029                $options[
'userscope'] = 
'sub';
 
 1034        $options[
'userfilter'] = $this->
getFilter();
 
 1038        if (@include_once(
'Log.php')) {
 
 1039            if (@include_once(
'Log/observer.php')) {
 
 1040                $options[
'enableLogging'] = 
true;
 
 1045                $options[
'groupscope'] = 
'base';
 
 1048                $options[
'groupscope'] = 
'one';
 
 1051                $options[
'groupscope'] = 
'sub';
 
 1075        $filter = trim($a_filter);
 
 1077        if (!strlen($filter)) {
 
 1081        if (strpos($filter, 
'(') !== 0) {
 
 1082            $filter = (
'(' . $filter);
 
 1084        if (substr($filter, -1) != 
')') {
 
 1085            $filter = ($filter . 
')');
 
 1100            include_once(
'Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
 
 1101            include_once(
'Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php');
 
 1105                $mapping->getFields(),
 
 1122        if (!$this->server_id) {
 
 1125        $query = 
"SELECT * FROM ldap_server_settings WHERE server_id = " . $this->db->quote($this->server_id) . 
"";
 
 1131            $this->
setUrl($row->url);
 
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
const IL_LDAP_BIND_ANONYMOUS
static _getAuthModeName($a_auth_key)
static _delete($a_server_id)
Delete mapping rules by server id.
static _getInstanceByServerId($a_server_id)
Get instance of class.
static _getRules($a_server_id)
Get all rules.
static getAttributeNames($a_server_id)
get all possible attribute names
static _deleteByServerId($a_server_id)
static getServerIdByAuthMode($a_auth_mode)
Get auth id by auth mode.
static _getServerList()
Get list of all configured servers.
isAuthenticationEnabled()
Check if authentication is enabled.
enableEscapeDN(bool $a_value)
static getDataSource($a_auth_mode)
read()
Read server settings.
setGroupAttribute($a_value)
setAuthenticationMapping($a_map)
Set mapped authentication mapping.
static _getCronServerIds()
Get list of acticve servers with option 'SyncCron'.
static disableDataSourceForAuthMode($a_authmode)
Disable data source.
static checkLDAPLib()
Check if ldap module is installed.
setSearchBase($a_search_base)
static getInstanceByServerId($a_server_id)
Get instance by server id.
enableSyncOnLogin($a_value)
getAuthenticationMapping()
Get authentication mode that is mapped.
doConnectionCheck()
Check ldap connection and do a fallback to the next server if no connection is possible.
static _getActiveServerList()
Get active server list.
static _getPasswordServers()
Checks whether password synchronistation is enabled for an user.
static getAuthModeByKey($a_auth_key)
get auth mode by key
enableGroupMemberIsDN($a_value)
setUsernameFilter($a_value)
toPearAuthArray()
Creates an array of options compatible to PEAR Auth.
validate()
Validate user input.
static _getAllServer()
Get list of all configured servers.
enableSyncPerCron($a_value)
toggleReferrer($a_status)
setGroupUserFilter($a_filter)
enableRoleSynchronization($a_value)
const DEFAULT_NETWORK_TIMEOUT
static isAuthModeLDAP($a_auth_mode)
Check if user auth mode is LDAP.
static isDataSourceActive($a_auth_mode)
Check if a data source is active for a specific auth mode @global ilDB $ilDB.
getAuthenticationMappingKey()
Get authentication mapping key Default is ldap.
getGroupNames()
Get group names as array.
toggleMembershipOptional($a_status)
__construct($a_server_id=0)
setRoleBindPassword($a_value)
getPearAtributeArray()
Get attribute array for pear auth data.
isAccountMigrationEnabled()
enabled account migration
rotateFallbacks()
Rotate fallback urls in case of connect timeouts.
setBindPassword($a_password)
static toggleDataSource($a_ldap_server_id, $a_auth_mode, $a_status)
Toggle Data Source.
setUserAttribute($a_user_attr)
static _getRoleSyncServerIds()
Check whether there if there is an active server with option role_sync_active.
enableAccountMigration($a_status)
Enable account migration.
enableAuthentication($a_status)
Enable authentication for this ldap server.
static getAvailableDataSources($a_auth_mode)
static _getFirstActiveServer()
Get first active server.
static getKeyByAuthMode($a_auth_mode)
Get auth id by auth mode.
static getServerIds()
Get all server ids @global ilDB $ilDB.
prepareFilter($a_filter)
Create brackets for filters if they do not exist.
enabledRoleSynchronization()
static getLogger($a_component_id)
Get component logger.
foreach($_POST as $key=> $value) $res