Skip to content

Commit

Permalink
LDAP multiple: #1
Browse files Browse the repository at this point in the history
  • Loading branch information
smeyer-ilias committed Aug 26, 2015
1 parent 2d67713 commit 9a86145
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 154 deletions.
7 changes: 4 additions & 3 deletions Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ private function isGroupMember($a_user_data)
* Get all rules
*
* @access public
*
* @return ilLDAPRoleAssignmentRule
*/
public function _getRules()
public function _getRules($a_server_id)
{
global $ilDB;

$query = "SELECT rule_id FROM ldap_role_assignments ";
$query = "SELECT rule_id FROM ldap_role_assignments ".
"WHERE server_id = ".$ilDB->quote($a_server_id,'integer');
$res = $ilDB->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
Expand Down
78 changes: 72 additions & 6 deletions Services/LDAP/classes/class.ilLDAPServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,27 @@ public static function _getServerList()
return $server_ids ? $server_ids : array();
}

/**
* Get list of all configured servers
*
* @return array list of server
*/
public static function _getAllServer()
{
global $ilDB;

$query = "SELECT * FROM ldap_server_settings ORDER BY name";

$server = array();

$res = $ilDB->query($query);
while($row = $ilDB->fetchAssoc($res))
{
$server[] = $row;
}
return $server;
}

/*
* Get first server id
*
Expand Down Expand Up @@ -677,7 +698,15 @@ public function enabledRoleSynchronization()
public function enableRoleSynchronization($a_value)
{
$this->role_sync_active = $a_value;
}// start Patch Name Filter
public function getUsernameFilter()
{
return $this->username_filter;
}
public function setUsernameFilter($a_value)
{
$this->username_filter = $a_value;
}// end Patch Name Filter

/**
* Enable account migration
Expand Down Expand Up @@ -742,19 +771,19 @@ public function validate()
public function create()
{
global $ilDB;

// start Patch Name Filter remove ",username_filter", ",%s", ",$this->getUsernameFilter()"
$next_id = $ilDB->nextId('ldap_server_settings');

$query = 'INSERT INTO ldap_server_settings (server_id,active,name,url,version,base_dn,referrals,tls,bind_type,bind_user,bind_pass,'.
'search_base,user_scope,user_attribute,filter,group_dn,group_scope,group_filter,group_member,group_memberisdn,group_name,'.
'group_attribute,group_optional,group_user_filter,sync_on_login,sync_per_cron,role_sync_active,role_bind_dn,role_bind_pass,migration, '.
'authentication,authentication_type) '.
'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)';
'authentication,authentication_type,username_filter) '.
'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)';
$res = $ilDB->queryF($query,
array(
'integer','integer','text','text','integer','text','integer','integer','integer','text','text','text','integer',
'text','text','text','integer','text','text','integer','text','text','integer','text','integer','integer','integer',
'text','text', 'integer','integer','integer'),
'text','text', 'integer','integer','integer',"text"),
array(
$next_id,
$this->isActive(),
Expand Down Expand Up @@ -787,9 +816,10 @@ public function create()
$this->getRoleBindPassword(),
$this->isAccountMigrationEnabled(),
$this->isAuthenticationEnabled(),
$this->getAuthenticationMapping()
$this->getAuthenticationMapping(),
$this->getUsernameFilter()
));

// end Patch Name Filter
return $next_id;
}

Expand Down Expand Up @@ -829,12 +859,45 @@ public function update()
"migration = ".$this->db->quote((int)$this->isAccountMigrationEnabled(),'integer').", ".
'authentication = '.$this->db->quote((int) $this->isAuthenticationEnabled(),'integer').', '.
'authentication_type = '.$this->db->quote((int) $this->getAuthenticationMapping(),'integer').' '.
// start Patch Name Filter
", username_filter = ".$this->db->quote($this->getUsernameFilter(), "text")." ".
// end Patch Name Filter
"WHERE server_id = ".$this->db->quote($this->getServerId(),'integer');

$res = $ilDB->manipulate($query);
return true;
}

/**
* delete
*/
public function delete()
{
if(!$this->getServerId())
{
return false;
}

include_once 'Services/LDAP/classes/class.ilLDAPAttributeMapping.php';
ilLDAPAttributeMapping::_delete($this->getServerId());

include_once 'Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php';
$rules = ilLDAPRoleAssignmentRule::_getRules($this->getServerId());

foreach($rules as $ruleAssigment)
{
$ruleAssigment->delete();
}

include_once 'Services/LDAP/classes/class.ilLDAPRoleGroupMappingSettings.php';
ilLDAPRoleGroupMappingSettings::_deleteByServerId($this->getServerId());

$query = "DELETE FROM ldap_server_settings ".
"WHERE server_id = ".$this->db->quote($this->getServerId(),'integer');
$res = $this->db->manipulate($query);

}

/**
* Creates an array of options compatible to PEAR Auth
*
Expand Down Expand Up @@ -1002,6 +1065,9 @@ private function read()
$this->enableAccountMigration($row->migration);
$this->enableAuthentication($row->authentication);
$this->setAuthenticationMapping($row->authentication_type);
// start Patch Name Filter
$this->setUsernameFilter($row->username_filter);
// end Patch Name Filter
}
}
}
Expand Down
91 changes: 91 additions & 0 deletions Services/LDAP/classes/class.ilLDAPServerTableGUI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */

include_once './Services/Table/classes/class.ilTable2GUI.php';

/**
*
*
* @author Fabian Wolf <[email protected]>
* @version $Id: $
* @ingroup
*/
class ilLDAPServerTableGUI extends ilTable2GUI
{
public function __construct($a_parent_obj, $a_parent_cmd = "", $a_template_context = "")
{
parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context);

$this->setId('ldap_server_list');

$this->setTitle($this->lng->txt('ldap_servers'));
$this->setRowTemplate('tpl.ldap_server_row.html','Services/LDAP');

$this->addColumn($this->lng->txt('active'), '','1%');
$this->addColumn($this->lng->txt('title'), '','80%');
$this->addColumn($this->lng->txt('user'), "", "4%");
$this->addColumn($this->lng->txt('actions'), '', '15%');

$this->importData();
}

private function importData()
{
include_once './Services/LDAP/classes/class.ilLDAPServer.php';

$data = ilLDAPServer::_getAllServer();
$this->setData($data);
}

protected function fillRow($a_set)
{
global $ilCtrl;
if($a_set['active'])
{
$this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('icon_ok.png'));
$this->tpl->setVariable('TXT_OK', $this->lng->txt('ldap_activated'));
}
else
{
$this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('icon_not_ok.png'));
$this->tpl->setVariable('TXT_OK', $this->lng->txt('ldap_inactivated'));
}

$this->tpl->setVariable('VAL_TITLE', $a_set["name"]);

//user
$user = count(ilObjUser::_getExternalAccountsByAuthMode("ldap_". $a_set["server_id"]));
$this->tpl->setVariable('VAL_USER',$user);

$ilCtrl->setParameter($this->getParentObject(),'ldap_server_id',$a_set['server_id']);
$this->tpl->setVariable('EDIT_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'editServerSettings'));

//actions

include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
$list = new ilAdvancedSelectionListGUI();
$list->setSelectionHeaderClass('small');
$list->setItemLinkClass('small');
$list->setId('actl_'.$a_set['server_id']);
$list->setListTitle($this->lng->txt('actions'));
$list->addItem($this->lng->txt('edit'), '', $ilCtrl->getLinkTarget($this->getParentObject(),'editServerSettings'));

if($a_set['active'])
{
$list->addItem($this->lng->txt('deactivate'), '',
$ilCtrl->getLinkTarget($this->getParentObject(),'deactivateServer'));
}
else
{
$list->addItem($this->lng->txt('activate'), '',
$ilCtrl->getLinkTarget($this->getParentObject(),'activateServer'));
}

$list->addItem($this->lng->txt('delete'), '',
$ilCtrl->getLinkTarget($this->getParentObject(),'confirmDeleteServerSettings'));

$this->tpl->setVariable('ACTIONS',$list->getHTML());
}
}
?>
Loading

0 comments on commit 9a86145

Please sign in to comment.