Under LDAP Integration, I had the ability to set what groups I wanted to allow access to... In Other Words... I would be able to allow only Users that belonged to a specific group "Drupal" under a specific OU "Technology".

Has this/Will This be ported over to this module?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnbarclay’s picture

Component: User interface » Documentation

yes. This funcationality is in the d7 version. ldap_authorization is the equivelent of ldap groups and ldap_authentication has white listing and black listing functionality.

I'm changing this to a documentation issue so it gets in the common use cases in the documentation.

pumpkinkid’s picture

Ah! are you talking about the "Excluded Text Test" field? I didn't realize "restrictions" was meant to be the opposite of white lists...

pumpkinkid’s picture

Wait... I'm not entirely sure how this works...

I have a Schema that is similar to this

Domain
|
---Technology
| |
| ---Users
---Marketing
| |
| ---Users
---Drupal
| |
| ---Groups
| |
| ---Allowed Users

On the server setup, I used this as my base DN

OU=Users,OU=Technology,dc=domain,dc=local

All my Technology users log in... but I want to be able to add users under Marketing, only if they are a member of the "Allowed Users" under the Drupal, Groups OU...

Would I have to make the server base DN

dc=domain,dc=local

Then blacklist everyone I DON'T want?

johnbarclay’s picture

I can think of 3 ways of doing this:

1. Have 2 ldap server instances. An ldap server instance in the ldap project is just a different configuration; they can both point to the same server. Each would have one of the base dns, but only one would have the restriction list.

2. Have 1 ldap server. Use both OU=Users,OU=Technology,dc=domain,dc=local and OU=Users,OU=Marketing,dc=domain,dc=local in the basdns. You can have as many as you like in that field separated by line returns. Then use white list or restrictions to further filter. Not sure if this will work for your case.

3. Let everyone logon, but use ldap authorization to put technology and marketing into roles. ldap authorization is much better developed for this sort of stuff. those who don't belong in any roles will be authenticated users and you can give that group no rights. this is an easier to maintain model as the site evolves and more roles come about.

pumpkinkid’s picture

I appreciate the help, I think 1 is going to be the best way to do this...

I do want to point out that 3 is similar to how ldap integration handled this, except for the fact that the use of a white list prevented anyone not listed from logging in... in other words, I could have

dc=domain,dc=local

but only have users who belong to groups white listed log on...

Are there any plans, or would you consider adding that as a feature under those settings? Not sure how difficult it would be to have a check box that would exclude all else when checked.

johnbarclay’s picture

Version: 7.x-1.0-unstable6 » 6.x-1.x-dev
Category: support » feature

Such as patch would be fine as it:
- avoids multiple server configurations
- provides a good upgrade path for ldap_integration d6.

If you can't provide the patch, can you write text of the UI?

What about simply requiring ldap_authorization module and having a checkbox in ldap authentication such as: " [x] only allow users who have role mappings in ldap authorization to authenticate via ldap " This would accomplish your needs and keep the authorization and authentication interfaces from blurring.

pumpkinkid’s picture

Keeping some of the ldap integration's wording, how bout:

[x] Deny access to users without role mappings.
Then as a subtitle "If the user is not in any of these groups, login will be denied."

johnbarclay’s picture

great. thanks. should be easy to write and get into 7.1

pumpkinkid’s picture

Awesome! Thanks!

Let me know what else I can do to help.

johnbarclay’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

There are 4 ways you can help, depending on your skillset and interests:

- write the patch
- write the unit test
- add the use case to the documentation
- manually test when done.

Also I noticed this was tagged 6.x. There is no 6.x version of this project.

pumpkinkid’s picture

I wondered about the tag for 6.x...

I can help write the patch, if I can go in to the code and fight my way around hooks... I'll try to take a look at it as soon as possible.

Documentation I can do as well, but shouldn't that be done after the module can perform the function?

Of course Manually I can do as well since I'm trying to get that functionality on one of my sites now.

johnbarclay’s picture

Thanks.

here is some psuedo code that will be useful

if ldap authorization module enabled and your checkbox checked {

list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations(username, 'query');  

loop through $new authorizations and see if user was granted any

if not, return false.

} 

it should go in the function allowUser() in LdapAuthenticationConf.Class.php.

To add the property to the UI etc., just search on ldapUserHelpLinkText in ldap_authentication. You will need to have the property in all the same locations. I would suggest naming it "excludeIfNoAuthorizations"

johnbarclay’s picture

Component: Documentation » Code
FileSize
5.02 KB

I started to write a patch for this. I got the UI and the variable in the classes, and ran across some chicken and egg issues. The ldap authorization wants a user object passed into _ldap_authorizations_user_authorizations() for it to work. Since ldap_authentication doesn't have a real user object yet it can't pass one in.

It looks like we can pass a fake $user std class object into _ldap_authorizations_user_authorizations() and add a new $op such as 'authentication_query' so the onlyApplyToLdapAuthenticated flag is ignored within the _ldap_authorizations_user_authorizations() function.

Attached is the patch. Hope this gets you started. If this doesn't make sense to you, let me know and I can continue on with this. I didn't commit the attached patch yet.

pumpkinkid’s picture

Re-reading our conversation, I am not sure we are on the same page...

It was brought to my attention that since my last attempt at making the LDAP module work as I need it to, I inadvertently made it so that non of my users could log on. Finding the problem, it was due to the way I had attempted to make the "whitelists" work...

On the "allow only text test" field, I placed the entire CN of the LDAP groups I wanted to white list... I had made the mistake of assuming this would work for LDAP groups, when in fact it states that "at least one of be found in users cn string" At that point I realized that if I had a Base DN of dc=domain,dc=local I also needed to have an OU=Technology and OU=Marketing on the white list section. This made it so that only those users that matched the the OU on the CN would be allowed in... Exactly as explained on the settings page...

Once I understood what it was doing. I was able to start allowing a smaller group of users in, but I still want to be able to filter access based on the LDAP groups a user belongs to, not just by the OU's in the CN string.

johnbarclay’s picture

Yeah. We are not on the same page. I was thinking you wanted to filter who can authenticate based on drupal groups, not ldap groups. The white lists/black list thing can easily get out of hand. That is why there is room for code there and a hook.

I think denying based on drupal groups pushes alot of the complexity of whitelists and black lists into ldap authorization, where the group mapping functionality is already fairly feature rich.

pumpkinkid’s picture

That's why I wanted to make sure...

So is there a way currently that would allow for me to identify members of an LDAP group using the php field?

johnbarclay’s picture

Not without a fair amount of code. Looks like only username and ldap entry are available in that function. I suspose it depends on how your ldap stores group membership.

If add the code below, around line 118 of ldapauthenticationconf.class.php
print('

name'); print($name);print('ldap_user'); print_r($ldap_user); die;

you will see what is available in the code.  If you are using active directory, the code might look something like the following.  The syntax is likely off, but the idea is:

$groups = explode(',', $ldap_user['attr']['memberOf'][0]);
$ingroup =  in_array('mygroup', groups, );
return $ingroup;




I would suggest the easiest way is to have me finish the patch I suggested above and then add mappings to certain groups in ldap authorization.
pumpkinkid’s picture

I appreciate the help, and I apologize we weren't on the same page before.

That being said though, I'm still not seeing how with the above patch we would be able to do what I'm looking for... Does Authorization recognize LDAP groups a user belongs to?

If so, then I would imagine that the way you propose to set this up would be to allow the base DN to include everyone, then limit it by using the patch above, where if there is no LDAP to Drupal Group assignment it won't let you in... Am I right?

Just trying to make sure I'm helping you test for the right functionality.

johnbarclay’s picture

Yes. Ldap authorization is used to map a users ldap properties to drupal roles, organic groups, etc. I'm not sure how ldap groups are stored in your ldap, but ldap authorization should be able to derive them. Here's where the mapping take place:

ldap_servers: mapping between drupal username and user's ldap entry
ldap_authorization: mapping between user's ldap entry and drupal roles.

In the ldap_authorization/test directory are the simpletests for ldap authorization and the fake ldap data for it. This may help illustrate things.

pumpkinkid’s picture

Ok, so I spent some time yesterday trying to better understand the LDAP module as far as the Authentication and Authorization pieces goes...

At the moment I have the Base DN set to allow all users, I have Authentication only allowing Technology and Marketing and I even have it so that the Authorization piece assigns a Drupal Group to the user based on the LDAP Groups they belong in... I believe that puts me in the position I need to be before the above patch is implemented.

So going back to your chicken and egg issue... I remember the LDAP Authentication had an issue where the user is able to "log in" (the user gets created) but then gets kicked off (shows as bad username and password) if not in a group mapping...

Ideally we would walk away from that, but I wonder if that's why they had to do it that way...

johnbarclay’s picture

I think the only chicken and egg issue is in #13 above:

It looks like we can pass a fake $user std class object into _ldap_authorizations_user_authorizations() and add a new $op such as 'authentication_query' so the onlyApplyToLdapAuthenticated flag is ignored within the _ldap_authorizations_user_authorizations() function.

The complexity this adds to that function will be outweighed by the load it takes off of ldap_authentication white and black list functionality. So I think its a good thing to do.

johnbarclay’s picture

Assigned: Unassigned » johnbarclay
Status: Active » Needs review

This is in head now. I haven't got the simpletest to work, but I tested by hand. Please test it out and confirm that it works.

johnbarclay’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

carlovdb’s picture

Status: Closed (fixed) » Active

Where can you exclude on groups with the memberOf variable.

I should only have to allow a certain group and that is not in the user's dn string so I can't use the whitelist

johnbarclay’s picture

Status: Active » Closed (fixed)

use the mapping filter to allow specific groups.

carlovdb’s picture

Thank you for your reply

Am I correct that all the other users that try to log in should be set to a drupal user profile that can not see the site and the users that belong to that group are set to a drupal group with the correct setting so that they can see everything?

johnbarclay’s picture

please start a support issue for this; don't add on to a "feature request"