web development and photography
symfony and LDAP
I’ve recently been looking at the essential (ie why isn’t it included in the core?) symfony plugin sfGuard. It offers are really nice, simple way of building a simple user, role, and permissions system into your symfony app.
The great thing is that with a little tweaking (documentation not great) you can add a custom LDAP lookup class, which overrides the standard built in user password lookup. Ok, you need to write your own class, or use a 3rd party one. But the basics of LDAP are built into php5, and it’s really not hard to do.
One problem I had was that sfGuard is designed to make it impossible to do an LDAP lookup and an internal check for a superadmin user. The reasons are a little esoteric, and have to do with mixing static and non-static contexts. Basically, the only option is to change one of the sfGuard library classes. Specifically sfGuardPlugin/lib/model/plugin/PluginsfGuardUser.php
Adding in this fixed things:
if ($callable = sfConfig::get('app_sf_guard_plugin_check_password_callable_both'))
{
$result = false;
$result = $this->checkPasswordByGuard($password);
if (!$result)
{
$result = call_user_func_array($callable, array($this->getUsername(), $password));
}
return $result;
}
which meant I had to use a special ‘check_password_callable_both’ option in the app.yml file. But at least this way it did checkPasswordByGuard() first, and then tried my added in LDAP class second.
Is there another way of doing this? I don’t know. Probably. But this seemed to work for me, and perhaps could be included in the sfGuard plugin by default. I guess I should get in touch with the developers to check…
| Print article | This entry was posted by admin on May 1, 2008 at 22:34 GMT, and is filed under symfony. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |



about 1 year ago
I too am having a similar problem. Basically if you create your own custom LDAP class – you can’t use any private class attributes – because all your methods must be static.
So in my custom ldap class I have my own methods – getEmail, getPhone etc… but have to pass the ldap objects every time… bit silly, when I should make them private members/attributes.
Did you end up submitting a feature request/bug for this? Maybe we should do it…