I have configured
admin/config/people/ldap/authorization/edit/og_group
and have it mapped to my groups in ldap.

I have
IV.B. When should OG groups be granted/revoked from user?
When a user logs on

Checked.

When I test the config at /admin/config/people/ldap/authorization/test/og_group

It finds the mapping correctly.

However, when a user logs in, it does not add them to the group. In fact, with debug enabled, I can't even see it trying.

Comments

drupalnuts’s picture

I did this
function test_init() {
global $user;
ldap_authorizations_user_authorizations($user);
}

That added a lot more debugging to watchlog, but still did not assign groups.

ldap_search() call: base_dn: OU=people,OU=test,DC=test,DC=inside, filter = (sAMAccountName=test), attributes: , attrsonly = 0, sizelimit = 0, timelimit = 0, deref = , scope = 3

Then

ldap_search() call: base_dn: CN=umhs,OU=sites,OU=test,DC=activestep,DC=inside, filter = (member=CN=test,OU=people,OU=test,DC=test,DC=inside), attributes: cn, attrsonly = 0, sizelimit = 0, timelimit = 0, deref = , scope = 3

Then

test :_ldap_authorization_ldap_authorization_maps_alter: deriveFromDn authorization ids: deriveFromAttr authorization ids: deriveFromEntry authorization ids: authorizations: group1 merged authz_ids authorization ids: group1

Then

test : initial proposed authorization for og_group: group1.

Then

test : filtered authorization for og_group: 1-2.

However, it never ads the user to that group.

johnbarclay’s picture

Title: ldap authorization og not working » ldap authorization: og not working
Version: 7.x-1.0-beta9 » 7.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

I can't replicate this. Can you do the following:
0) Try the 7.x-1.0-dev version. I don't think any recent changes would affect this, but it has additional debugging logging messages.
1). Pick the user your are going to test with and figure out their user id (uid)
2) make a note of the records in og_memberships and og_user_roles and delete any with that uid.
3) enable ldap_help module and check the detailed logging checkbox at admin/config/people/ldap/settings
4) goto admin/reports/dblog and clear the old log messages (unless you need them for something)
5) log the user in to test the authorization creations

6) check the 'og_memberships' and 'og_user_roles' tables and see if any records were created for that uid.
7) goto admin/reports/dblog. There should be a log record that looks like:

TYPE	ldap_authorization
DATE	Saturday, March 24, 2012 - 22:39
USER	jbarclay
LOCATION	
REFERRER	
MESSAGE	jbarclay : user_authorizations_set results for og_group:
1. Initial existing authorizations:
1. Filtered Authorizations: 1-3
2. After filtering off previously granted authorizations: 1-3
3. All available existing authorization ids: 1-1, 1-2, 1-3, 1-4, 3-1, 3-2, 3-3, 3-4
4. authorization ids that need to be created: none
5. consumer containers existing after create call (or non-call if og): 1-1, 1-2, 1-3, 1-4, 3-1, 3-2, 3-3, 3-4
6. Grants passed to authorizationGrant(): 1-3
7. revokes passed to authorizationRevoke(): none

Post that here. It will help figure out why its not attempting to create the membership.

drupalnuts’s picture

Status: Postponed (maintainer needs more info) » Active

I updated to the -dev, I do not get a line in watchdog like the above, it shows the server binding, and then the user being able to login after a bind. (I use a service account)

It never runs ldap_authorization.

drupalnuts’s picture

Well I got this to run.

authorization ids to add: %creates
revokes: none
grants: 13-2
consumer containers initially existing: 8-1, 8-2, 8-3, 9-1, 9-2, 9-3, 10-1, 10-2, 10-3, 11-1, 11-2, 11-3, 12-1, 12-2, 12-3, 13-1, 13-2, 13-3, 14-1, 14-2, 14-3, 15-1, 15-2, 15-3, 16-1, 16-2, 16-3, 17-1, 17-2, 17-3, 18-1, 18-2, 18-3, 19-1, 19-2, 19-3, 20-1, 20-2, 20-3, 21-1, 21-2, 21-3
consumer containers needed to create: none
consumer containers existing after create call: 8-1, 8-2, 8-3, 9-1, 9-2, 9-3, 10-1, 10-2, 10-3, 11-1, 11-2, 11-3, 12-1, 12-2, 12-3, 13-1, 13-2, 13-3, 14-1, 14-2, 14-3, 15-1, 15-2, 15-3, 16-1, 16-2, 16-3, 17-1, 17-2, 17-3, 18-1, 18-2, 18-3, 19-1, 19-2, 19-3, 20-1, 20-2, 20-3, 21-1, 21-2, 21-3

It should give me access to group 13 as a member, but it does not change og_membership

drupalnuts’s picture

and in the -dev version

1. Initial existing authorizations:
1. Filtered Authorizations: 13-2
2. After filtering off previously granted authorizations: 13-2
3. All available existing authorization ids: 8-1, 8-2, 8-3, 9-1, 9-2, 9-3, 10-1, 10-2, 10-3, 11-1, 11-2, 11-3, 12-1, 12-2, 12-3, 13-1, 13-2, 13-3, 14-1, 14-2, 14-3, 15-1, 15-2, 15-3, 16-1, 16-2, 16-3, 17-1, 17-2, 17-3, 18-1, 18-2, 18-3, 19-1, 19-2, 19-3, 20-1, 20-2, 20-3, 21-1, 21-2, 21-3
4. authorization ids that need to be created: none
5. consumer containers existing after create call (or non-call if og): 8-1, 8-2, 8-3, 9-1, 9-2, 9-3, 10-1, 10-2, 10-3, 11-1, 11-2, 11-3, 12-1, 12-2, 12-3, 13-1, 13-2, 13-3, 14-1, 14-2, 14-3, 15-1, 15-2, 15-3, 16-1, 16-2, 16-3, 17-1, 17-2, 17-3, 18-1, 18-2, 18-3, 19-1, 19-2, 19-3, 20-1, 20-2, 20-3, 21-1, 21-2, 21-3
6. Grants passed to authorizationGrant(): 13-2
7. revokes passed to authorizationRevoke(): none
johnbarclay’s picture

do you see any watchdog entries after that? the ones that are generated in LdapAuthorizationConsumerOG.class.php in the function grantSingleAuthorization()?

Do those 2 database tables look correct for that user id?

drupalnuts’s picture

Message consumer_id=13-2, op=grant
Severity debug
Hostname XXX

That pops up as well. There is a entry put in for og_user_roles for my user and group
but
not in og_membership.

drupalnuts’s picture

I deleted the user and all the items in og_user_roles and og_membership, and logged into ldap again, it stuck an entry in og_user_roles, but not og_membership.

johnbarclay’s picture

I fixed a bug in the test form and the ldap_authorization_get_consumers() function. I don't think this has anything to do with the og bug, but it may have created some interference between the 2 authorization approaches (roles and og groups) if both were enabled. I'm still working through some other implications from this, but hope to have a commit Monday or sooner.

jzornig’s picture

What version of OG are you running?

johnbarclay’s picture

I'm developing and testing against the 7.x-1.3 branch. If anyone is using the 7.x-2.0-dev branch or 7.x-1.2, 7.x-1.1, I would love to know if they are succeeding or failing so I can give a warning that the the 7.x-1.3 branch is required.

drupalnuts’s picture

After the update to the dev branch on the 27, I am no longer getting anything in either table. It seems like one step back.

mike64’s picture

I was having the exact same problem. The og_membership entry seems to be the table that matters for basic membership. An entry in that table indicates "member". If you grant another OG role like "administrator member" to a user then an entry appears in og_users_roles.

After visually tracing the code I could not see how an og_membership row would be created. After reviewing the og.module code and the relationships between the OG functions I decided to change the following line of the grantSingleAuthorization function in LdapAuthorizationConsumerOG.class.php.

                // CASE 5:  grant role

                // og_role_grant($gid, $user->uid, $rid);
                og_group($gid);

IANAOGE: I am not an OG expert.

It works for my cases where all I'm trying to grant is group membership. The og_group function also accepts and array parameter for more options.

johnbarclay’s picture

Thanks for tracing through the code. og_group($gid) won't work for most use cases, since it assumes the current logged in user. But isolating the problem to the og_role_grant() function is very helpful.

@mike64. With this change, does the mapping work well for you? Are you using it with LDAP Authorization Drupal Roles also? I'm not getting a lot of feedback on who is succeeding and failing with ldap og. When you are tracing, what are the values of $gid, $user->uid, and $rid when og_role_grant() is called?

I added another debug line in LdapAuthorizationConsumerOG.class.php that watchdogs the $gid, $uid, and $rid being passed to og_role_grant(). To help further debug this, use 7.x-1.0-dev, enable ldap help module, enable detailed logging at admin/config/people/ldap/settings, login with user to be granted groups, and check watchdog logs.

Some other thoughts:
- make sure you have the server and configuration enabled at the top of admin/config/people/ldap/authorization/edit/og_group
- the simpletests work fine and test the call to og_role_grant() as an api call (in testBasicFunctionsAndApi()) as well as test roles granted on logon (in testAuthorizationsOnLogon()), so any help getting to the bottom of this pesky bug is greatly appreciated.

johnbarclay’s picture

Title: ldap authorization: og not working » ldap authorization: og not working (organic groups)
Issue tags: +Organic Groups, +OG, +ldap authorization og

added some keyowrds since "og" isn't searchable

asadsultan’s picture

I seem to be having the same problem. The watchdog entries seem to be fine when I log in but membership to the group is not granted. Trying to access a private group says access denied in the log. Has this problem been solved? im using ldap 7.x-1.x-dev with OG 7.x-1.3....Any advice would be appreciated.

johnbarclay’s picture

Title: ldap authorization: og not working (organic groups) » ldap authorization: og 1.x not working (organic groups)

This has not been solved. Comment #13 may be a viable workaround if you are only using the default membership of organic groups. Looking for feedback on #14, but will follow up on recreating and fixing regardless when I get a chance.

johnbarclay’s picture

Status: Active » Needs review

I committed some changes to 7.x-1.x-dev (see #1559388: LDAP Authorization Organic Groups: OG 7.x-2.x Support). Most of them are related to og 7.x-2.x. But the code:

			$values = array(
				'entity type' => 'user',
				'entity' => $user,
				'state' => OG_STATE_ACTIVE,
				'membership type' => OG_MEMBERSHIP_TYPE_DEFAULT,
			);
			$user_entity = og_group($gid, $values);
			og_role_grant($gid, $user->uid, $rid);

basically does what comment #13 does, but supports user's beside the currently logged in user and supports roles. Please test.

johnbarclay’s picture

Status: Needs review » Closed (cannot reproduce)

I committed a number of other ldap og fixes to 7.x-1.x-dev. So this issue and some of the patches in it are no longer relevant and I'm closing this. One issue was not reloading the user object after the og fields were populated, thus writing back over them.

Any testing of 7.x-1.x-dev against og 7. x-1.4 would be greatly apreciated.