I'l like to be able to invoke a hook from a site custom moduel, that excludes certains users from logging in (ba DN pattern matching).
Looking at LdapAuthenticationConf.class.php, allowuser() I inserted the following at the end, before the return TRUE:
// allow other modules to hook in and refuse if they like
drupal_alter('ldap_authentication_allowuser_results', $ldap_user_entry, $name, $hook_result);
if (isset($hook_result) && !$hook_result) {
watchdog('ldap_authentication_allowuser', 'result=refused');
return FALSE;
}Implementation of that works. Is that the right approach? (I dont want to enable the PHP module and use php filters in the GUI):
Aside: the messages to the user who is refised are not very nice:
Notice: Trying to get property of non-object in drupal_lookup_path() (line 77 of /var/www/includes/path.inc).
Sorry, your LDAP credentials were not found, or the LDAP server is not available. You may log in with other credentials on the user login form.
Comments
Comment #1
johnbarclay commentedThis is committed to the 1.x and 2.x branch. Thanks. The watchdog call was a little off as were a couple others in the same class (see http://drupalcode.org/project/ldap.git/commitdiff/e460e694e4cae689e03b0d...).
If you want to put that error message in as a bug issue, that would be helpful. Not sure I understand when the message comes up.
Comment #2
johnbarclay commentedThis is committed to the 1.x and 2.x branch. Thanks. The watchdog call was a little off as were a couple others in the same class (see http://drupalcode.org/project/ldap.git/commitdiff/e460e694e4cae689e03b0d...).
If you want to put that error message in as a bug issue, that would be helpful. Not sure I understand when the message comes up.
Comment #3
boran commentedThanks. Yes, that watchdog is better.
I upgraded to latest dev, added that code: the code works fine.
However the sites now goes into a loop, which it tries to authenticate 5-6 times. I've moved that issues and the related discussion of the path.in error above to #1638414: Site looping when ldap sso refused: Trying to get property of non-object in drupal_lookup_path() (line 77 of /var/www/includes/p.
Comment #4
boran commentedOne could also add a bit of documentation for the api:
ldap_authentication/ldap_authentication.api.php
Comment #5
johnbarclay commentedI changed the documentation for this in the 2.0 branch, emphasizing that another module could have already set it to FALSE. @boran, does this make sense to document this way?
Comment #6
boran commentedSorry for he slow answer.
Yes your point about checking for False first is very important.
Still would like to see the comments about the function name though, will also show in Api documentation tools .
Comment #7
johnbarclay commentedI think I got it all together now. This is committed to 7.x-2.x-dev. Appreciate you following up on documentation; documentation really helps others and keeps the issue queue thinner.
Does this look like what you are after?
Comment #8
johnbarclay commentedFunctioning correctly. Needs simpletest coverage.
Comment #9
boran commentedVery good, thanks!
I'm still on the 1.x (since production is v.soon for me), the upgrade from 7.x-1.0-beta11+2-dev to 7.x-1.0-beta11+15-dev went well on my test site.
I see ldap_authentication.api.php has not made it into 1.x, but you noted that above.
Comment #10
johnbarclay commentedTrying to freeze new features in favor of stability. Marking this as postponed, which means simpletests won't be in until 8.x-3.x I believe
Comment #11
larowlanTagging
Comment #13
grahlSeems to work, tests need to be worked on separately.