Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estended LDAP integration to allow multiple users search filter. #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion actions/create_repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@
$engine->addException($e2);
}

//
// MAUMAR: Avaliable repository templates (dumps)
//
$_templateList = array();
$config = $engine->getConfig();
$index = (int) 1;
while (true) {
$tmplName = $config->getValue('Repositories:template:' . $index, 'Name');
if ($tmplName != null) {
$_templateList[$index]['Name'] = $tmplName;
}
else {
break;
}

$tmplSource = $config->getValue('Repositories:template:' . $index, 'Source');
if ($tmplSource != null) {
$_templateList[$index]['Source'] = $tmplSource;
}

++$index;
}

// Create a initial repository structure.
try {
$repoPredefinedStructure = get_request_var("repostructuretype");
Expand All @@ -82,6 +105,19 @@
throw new ValidationException(tr("Missing project name"));
}
break;
default:
foreach ($_templateList as $rt) {
if ("$repoPredefinedStructure" == $rt['Name']) {
error_log("load ".$rt['Name']." into ".$reponame);

$engine->getRepositoryEditProvider()
->load($r, $rt['Source']);
$engine->addMessage(tr("Loaded structure '%0' into repository '%1'", array($rt['Name'], $reponame)));

break;
}
}
break;
}
}
}
Expand All @@ -93,4 +129,4 @@
$engine->addException($e);
}
}
?>
?>
14 changes: 13 additions & 1 deletion classes/core/entities/User.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class User
public $id;
public $name;
public $password;
public $attributes; // MAUMAR: LDAP Attributes

// Object(Permission)
public $perm;
Expand All @@ -34,6 +35,7 @@ public function __construct($id=null, $name=null, $password=null, $perm=null)
$this->name = $name;
$this->password = $password;
$this->perm = $perm;
$this->attributes = array();
}

public function ctr( $id, $name, $password )
Expand Down Expand Up @@ -63,6 +65,16 @@ public function getEncodedName()
return rawurlencode( $this->name );
}

public function getEncodedAttributes()
{
$result = "";
foreach ($this->attributes as $a) {
$result .= rawurlencode($a) . " , ";
}

return $result;
}

public static function compare( $o1, $o2 )
{
if( $o1->name == $o2->name )
Expand All @@ -73,4 +85,4 @@ public static function compare( $o1, $o2 )
}
}
}
?>
?>
12 changes: 11 additions & 1 deletion classes/core/interfaces/IRepositoryEditProvider.iface.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,15 @@ public function mkdir(\svnadmin\core\entities\Repository $oRepository, array $pa
* @return bool
*/
public function dump(\svnadmin\core\entities\Repository $oRepository);

/**
* Loads a repository file system content from dumped file.
*
* @param \svnadmin\core\entities\Repository $oRepository
*
* @return bool
*/
public function load(\svnadmin\core\entities\Repository $oRepository, $file);

}
?>
?>
22 changes: 21 additions & 1 deletion classes/providers/RepositoryEditProvider.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@ public function dump(\svnadmin\core\entities\Repository $oRepository)
return $this->_svnAdmin->dump($absoluteRepositoryPath);
}

/**
* (non-PHPdoc)
* @see svnadmin\core\interfaces.IRepositoryEditProvider::load()
*/
public function load(\svnadmin\core\entities\Repository $oRepository, $file)
{
$svnParentPath = $this->getRepositoryConfigValue($oRepository, 'SVNParentPath');

if ($svnParentPath == NULL) {
throw new \Exception('Invalid parent-identifier: ' .
$oRepository->getParentIdentifier());
}

$absoluteRepositoryPath = $svnParentPath . '/' . $oRepository->name;

$this->_svnAdmin->load($absoluteRepositoryPath, $file);

return true;
}

/**
* Gets the configuration value associated to the given Repository object
* (identified by 'parentIdentifier')
Expand All @@ -246,4 +266,4 @@ protected function getRepositoryConfigValue(\svnadmin\core\entities\Repository $
return $v;
}
}
?>
?>
132 changes: 117 additions & 15 deletions classes/providers/ldap/LdapUserViewProvider.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class LdapUserViewProvider extends \IF_AbstractLdapConnector
*/
protected $users_attributes;

/**
* MAUMAR: Holds multiple search queries
*/
protected $users_extra_queries = array();

/*
* Settings to find groups.
*/
Expand Down Expand Up @@ -151,6 +156,28 @@ public function __construct()
$this->users_search_filter = $cfg->getValue("Users:ldap", "SearchFilter");
$this->users_attributes = $cfg->getValue("Users:ldap", "Attributes");
$this->users_attributes = explode(",", $this->users_attributes);

// MAUMAR: Support multiple ldap search query. Try to load it
$index = (int) 1;
while (true) {
$extra_alias = $cfg->getValue("Users:ldap:" . $index, "Alias");
if ($extra_alias != null) {
$this->users_extra_queries[$index]['Alias'] = $extra_alias;
}
else {
break;
}

//error_log("Loading users extra query ".$extra_alias);

$extra_base_dn = $cfg->getValue("Users:ldap:" . $index, "BaseDN");
$extra_search_filter = $cfg->getValue("Users:ldap:" . $index, "SearchFilter");

$this->users_extra_queries[$index]['BaseDN'] = $extra_base_dn;
$this->users_extra_queries[$index]['SearchFilter'] = $extra_search_filter;

++$index;
}

$this->groups_base_dn = $cfg->getValue("Groups:ldap", "BaseDN");
$this->groups_search_filter = $cfg->getValue("Groups:ldap", "SearchFilter");
Expand Down Expand Up @@ -257,6 +284,7 @@ public function getUsers($withStarUser=true)
{
$ret = array();
$up_name = strtolower($this->users_attributes[0]);
$attrCount = count($this->users_attributes);

// Search users in LDAP.
$ldapUsers = $this->p_getUserEntries();
Expand All @@ -267,6 +295,16 @@ public function getUsers($withStarUser=true)
$u = new \svnadmin\core\entities\User;
$u->id = $ldapUsers[$i]->dn;
$u->name = $ldapUsers[$i]->$up_name;

if ($attrCount > 1)
{
for ($x = 1; $x < $attrCount; $x++)
{
$attr_name = strtolower($this->users_attributes[$x]);
$u->attributes[$attr_name] = $ldapUsers[$i]->$attr_name;
}
}

$ret[] = $u;
}

Expand Down Expand Up @@ -294,10 +332,22 @@ public function userExists($objUser)
// Search for a user, where the 'users_attributes' equals the $objUser->name.
$found = parent::objectSearch($this->connection, $this->users_base_dn, $final_filter, $this->users_attributes, 1);

if (!is_array($found) || count($found) <= 0)
return false;
if (is_array($found) && count($found) > 0) {
return true;
}

foreach ($this->users_extra_queries as $q) {
$base_dn = $q['BaseDN'];
$search_filter = $q['SearchFilter'];
$final_filter = '(&('.$user_name_filter.')'.$search_filter.')';

return true;
$found = parent::objectSearch($this->connection, $base_dn, $final_filter, $this->users_attributes, 1);

if (is_array($found) && count($found) > 0)
return true;
}

return false;
}

/**
Expand All @@ -313,9 +363,22 @@ public function authenticate($objUser, $password)
// Search for a user, where the 'users_attributes' equals the $objUser->name.
$found = parent::objectSearch( $this->connection, $this->users_base_dn, $final_filter, $this->users_attributes, 1 );

if (!is_array($found) || count($found) <= 0)
return false; // User not found.
if (!is_array($found) || count($found) <= 0) {
foreach ($this->users_extra_queries as $q) {
$base_dn = $q['BaseDN'];
$search_filter = $q['SearchFilter'];
$final_filter = '(&('.$user_name_filter.')'.$search_filter.')';

$found = parent::objectSearch($this->connection, $base_dn, $final_filter, $this->users_attributes, 1);

if (is_array($found) && count($found) > 0)
break;
}

if (!is_array($found) || count($found) <= 0)
return false; // User not found.
}

// The user has been found.
// Get the dn of the user and authenticate him/her now.
return \IF_AbstractLdapConnector::authenticateUser($this->host_address, $this->host_port, $found[0]->dn, $password, $this->host_protocol_version);
Expand Down Expand Up @@ -506,7 +569,24 @@ protected function p_getUserEntries()
// Include the attribute which is used in the "member" attribute of a group-entry.
$attributes[] = $this->groups_to_users_attribute_value;

return parent::objectSearch($this->connection, $this->users_base_dn, $this->users_search_filter, $attributes, 0);
$result = parent::objectSearch($this->connection, $this->users_base_dn, $this->users_search_filter, $attributes, 0);

foreach ($this->users_extra_queries as $q) {
$base_dn = $q['BaseDN'];
$search_filter = $q['SearchFilter'];

$found = parent::objectSearch($this->connection, $base_dn, $search_filter, $attributes, 0);

if (is_array($found) && count($found) > 0) {
$result = array_merge($result, $found);
}
}

if (is_array($result) && count($result) > 0) {
return $result;
}

return NULL;
}

/**
Expand Down Expand Up @@ -542,10 +622,23 @@ protected function p_findUserEntry(\svnadmin\core\entities\User $objUser)

$found = parent::objectSearch($this->connection, $this->users_base_dn, $final_filter, $attributes, 1);

if (!is_array($found) || count($found) <= 0)
return NULL;
if (is_array($found) && count($found) > 0) {
return $found[0];
}

foreach ($this->users_extra_queries as $q) {
$base_dn = $q['BaseDN'];
$search_filter = $q['SearchFilter'];
$final_filter = '(&('.$user_name_filter.')'.$search_filter.')';

$found = parent::objectSearch($this->connection, $base_dn, $final_filter, $attributes, 1);

if (is_array($found) && count($found) > 0) {
return $found[0];
}
}

return $found[0];
return NULL;
}

/**
Expand Down Expand Up @@ -585,13 +678,22 @@ protected function p_resolveGroupMemberId($memberId)
// Execute search.
$found = parent::objectSearch($this->connection, $memberId, $this->users_search_filter, $this->users_attributes, 1);

if (!is_array($found) || count($found) <= 0)
{
error_log("Can not resolve member ID. member-id=$memberId; filter=$filter;");
return null;
if (is_array($found) && count($found) > 0) {
return $found[0];
}

foreach ($this->users_extra_queries as $q) {
$search_filter = $q['SearchFilter'];

$found = parent::objectSearch($this->connection, $memberId, $search_filter, $this->users_attributes, 1);

return $found[0];
if (is_array($found) && count($found) > 0) {
return $found[0];
}
}

error_log("Can not resolve member ID. member-id=$memberId; filter=$filter;");
return null;
}

/**
Expand Down Expand Up @@ -820,4 +922,4 @@ public function updateSvnAuthFile($autoRemoveUsers=true, $autoRemoveGroups=true)
}
}
}
?>
?>
Loading