Skip to content

Commit

Permalink
Removed the type caster as it wasn't necessary and removed the passwo…
Browse files Browse the repository at this point in the history
…rd check due to RFC 4510-4511 for LDAP v3.
  • Loading branch information
Juti Noppornpitak committed Jul 9, 2012
1 parent 8a7dacd commit 498d156
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
15 changes: 7 additions & 8 deletions Manager/LdapConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Monolog\Logger;

use IMAG\LdapBundle\Exception\ConnectionException;

class LdapConnection implements LdapConnectionInterface
{
private
Expand Down Expand Up @@ -60,18 +62,15 @@ public function search(array $params)
}
}

public function bind($user_dn, $password)
public function bind($user_dn, $password='')
{
if (!$user_dn) {
throw new \Exception('You must bind with an ldap user_dn');
if (empty($user_dn) && is_string($user_dn)) {
throw new ConnectionException('LDAP user\'s DN (user_dn) must be provided (as a string).');
}

if (!$password) {
throw new \Exception('Password can not be null to bind');
}
// Accoding to the LDAP RFC 4510-4511, the password can be blank.

return (bool)
@ldap_bind($this->_ress, $user_dn, $password);
return ldap_bind($this->_ress, $user_dn, $password);
}

public function getParameters()
Expand Down
30 changes: 14 additions & 16 deletions Manager/LdapManagerUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace IMAG\LdapBundle\Manager;

use Symfony\Component\Security\Core\Exception\AuthenticationException;

class LdapManagerUser implements LdapManagerUserInterface
{
private
private
$ldapConnection,
$username,
$password,
Expand Down Expand Up @@ -33,7 +35,7 @@ public function auth()
->bind()
;
}

public function doPass()
{
$this
Expand Down Expand Up @@ -99,14 +101,14 @@ private function addLdapUser()
throw new \Exception('User is not defined, pls use setUsername');
}

$filter = isset($this->params['user']['filter'])
? $this->params['user']['filter']
$filter = isset($this->params['user']['filter'])
? $this->params['user']['filter']
: '';

$entries = $this->ldapConnection
->search(array(
'base_dn' => $this->params['user']['base_dn'],
'filter' => sprintf('(&%s(%s=%s))',
'filter' => sprintf('(&%s(%s=%s))',
$filter,
$this->params['user']['name_attribute'],
$this->ldapConnection->escape($this->username)
Expand Down Expand Up @@ -134,14 +136,14 @@ private function addLdapRoles()

$tab = array();

$filter = isset($this->params['role']['filter'])
$filter = isset($this->params['role']['filter'])
? $this->params['role']['filter']
: '';

$entries = $this->ldapConnection
->search(array(
'base_dn' => $this->params['role']['base_dn'],
'filter' => sprintf('(&%s(%s=%s))',
'filter' => sprintf('(&%s(%s=%s))',
$filter,
$this->params['role']['user_attribute'],
$this->ldapConnection->escape($this->getUserId())
Expand All @@ -156,20 +158,16 @@ private function addLdapRoles()
self::slugify($entries[$i][$this->params['role']['name_attribute']][0])
));
}

$this->_ldapUser['roles'] = $tab;

return $this;
}

private function bind()
{
if (!$this->password) {
throw new \Exception('Password is not defined, pls use setPassword');
}

return (bool) $this->ldapConnection
->bind($this->_ldapUser['dn'], $this->password);
return $this->ldapConnection
->bind($this->_ldapUser['dn'], $this->password);
}

private static function slugify($role)
Expand All @@ -187,11 +185,11 @@ private function getUserId()
case 'dn':
return $this->_ldapUser['dn'];
break;

case 'username':
return $this->username;
break;

default:
throw new \Exception(sprintf('The value can\'t be retrieve for this user_id : %s',$this->params['role']['user_id']));
}
Expand Down

0 comments on commit 498d156

Please sign in to comment.