LDAP Patch and setup for non groupofuniquenames

Author Message

Some Guy

Tuesday 07 August 2007 8:34:51 pm

hey
i am very new to ez publish and so far the first modification ive made is to allow for my ldap setup

basicly my ldap setup has all my users in
ou=Users,dc=domain,dc=com
and then i have
ou=Groups,dc=domain,dc=com
where i have some groups that are just setup like
group cn=website_admins
memberUid=me
memberUid=other_me
etc.

so i wanted to use SimpleMapping configuration so i can just say here are my users, and i want these groups to be put into this ez publish group
i also wanted to ONLY allow those whom have an ldap group map to a ez publish group to be able to login ie
LDAPUserGroupMap[only_this_ldap_group]=login_to_this_ez_publish_group
where if a user in ldap didnt have a map they would fail login rather than goto guest group

first problem i had was simplemapping required groupofuniquenames, then i couldn't restrict logins to certain groups
these two are ez to fix, default login to no privilege group and setting up groupofuniquenames in ldap is ez

but my 3rd bigger problem was when a user is a member of multiple groups how does it decide which group to put them in, well ez publish put them in the first matching group going by alphabetical order of ldap groups
ie
map[bb_ldap]=admin
map[aa_ldap=normal
where a user in both ldap groups would always be mapped to normal

so i have written a patch to accommodate my setup

--- ezorig/kernel/classes/datatypes/ezuser/ezldapuser.php	2007-08-07 16:10:09.204831648 +1000
+++ ezdev/kernel/classes/datatypes/ezuser/ezldapuser.php	2007-08-07 17:34:04.639329248 +1000
@@ -184,6 +184,7 @@
 
             $LDAPUserGroupAttributeType = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroupAttributeType' );
             $LDAPUserGroupAttribute     = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroupAttribute' );
+            $LDAPGroupMemberAttributeMatch = $LDAPIni->variable( 'LDAPSettings', 'LDAPGroupMemberAttributeMatch' );
 
             if ( $LDAPIni->hasVariable( 'LDAPSettings', 'Utf8Encoding' ) )
             {
@@ -255,6 +256,8 @@
                                              $LDAPEmailAttribute );
                 if ( $LDAPUserGroupAttributeType )
                     $retrieveAttributes[] = $LDAPUserGroupAttribute;
+		if ( $LDAPGroupMemberAttributeMatch )
+		    $retrieveAttributes[] = $LDAPGroupMemberAttributeMatch;
 
                 if ( $LDAPSearchScope == "one" )
                     $sr = ldap_list( $ds, $LDAPBaseDN, $LDAPFilter, $retrieveAttributes );
@@ -380,6 +383,10 @@
                             }
                         }
                     }
+		    else if ( $LDAPUserGroupType == 'map' )
+		    {
+			$defaultUserPlacement = false;
+		    }
                 }
 
                 $adminUser = eZUser::fetchByName( 'admin' );
@@ -418,6 +425,8 @@
                     $LDAPGroupMemberAttribute = $LDAPIni->variable( 'LDAPSettings', 'LDAPGroupMemberAttribute' );
                     $LDAPGroupDescriptionAttribute = $LDAPIni->variable( 'LDAPSettings', 'LDAPGroupDescriptionAttribute' );
 
+		    $KeepGroupMapOrder = $LDAPIni->variable( 'LDAPSettings', 'KeepGroupMapOrder' );
+
                     $groupSearchingDepth = ( $LDAPGroupMappingType == '1' ) ? 1 : 1000;
 
                     // now, get all parents for currently ldap authenticated user
@@ -433,7 +442,22 @@
 
                     $groupsTree = array();
                     $stack = array();
-                    $newfilter = '(&(objectClass=' . $LDAPGroupClass . ')(' . $LDAPGroupMemberAttribute . '=' . $userData['dn'] . '))';
+
+		    if ( $LDAPGroupMemberAttributeMatch )
+		    {
+		    	//ldap_search returns all lowercase attribute names :\
+		    	$LDAPGroupMemberAttributeMatch = strtolower($LDAPGroupMemberAttributeMatch);
+
+			if ( isset($userData[$LDAPGroupMemberAttributeMatch][0]) )
+				$memberAttribute = $userData[$LDAPGroupMemberAttributeMatch][0];
+			else
+				return false;
+		    }
+		    else
+		    {
+			$memberAttribute = $userData['dn'];
+		    }
+                    $newfilter = '(&(objectClass=' . $LDAPGroupClass . ')(' . $LDAPGroupMemberAttribute . '=' . $memberAttribute . '))';
 
                     $groupsTree[ $userData['dn'] ] = array( 'data' => & $userData,
                                                                 'parents' => array(),
@@ -472,6 +496,8 @@
                                         if ( count( $groupRow ) > 0 )
                                         {
                                             $userRecord['new_parents'][] = $groupRow[ 0 ][ 'node_id' ];
+					    if ( $KeepGroupMapOrder == 'enabled' )
+					    	$KeepGroupMapOrderArray[$ldapGroupName] = $groupRow[0]['node_id'];
                                         }
                                     }
                                 }
@@ -566,6 +592,24 @@
                     }
                 }
 
+		if ( $defaultUserPlacement === false )
+		{
+			//no default group, no login 4 u
+			return false;
+		}
+
+		if ( $KeepGroupMapOrder == 'enabled' && count($extraNodeAssignments) > 1 )
+		{
+			foreach($LDAPUserGroupMap as $group => $map)
+			{
+				if ( isset($KeepGroupMapOrderArray[$group]) )
+				{
+					$defaultUserPlacement = $KeepGroupMapOrderArray[$group];
+					break;
+				}
+			}
+		}
+
                 $userAttributes = array( 'login'      => $login,
                                          'first_name' => $userData[ $LDAPFirstNameAttribute ][0],
                                          'last_name'  => $userData[ $LDAPLastNameAttribute ][0],
--- ezorig/settings/ldap.ini	2007-08-07 16:17:12.386498256 +1000
+++ ezdev/settings/ldap.ini	2007-08-08 13:12:57.549292472 +1000
@@ -26,7 +26,9 @@
 LDAPSearchFilters[]
 # LDAP attribute for login. Normally, uid
 LDAPLoginAttribute=uid
-# Could be id or name
+# Options: id, name, map
+# When using map no defualt group will be selected
+# if a user doesnt have any ldap groups mapped for them, they cant login
 LDAPUserGroupType=id
 # Default place to store LDAP users. Could be content object id or group name for LDAP user group,
 # depends on LDAPUserGroupType.
@@ -46,6 +48,10 @@
 # Attribute of LDAP user which should be used to obtain groups which user(group) belongs to.
 # Required then 'LDAPGroupMappingType' is set to 'GetGroupsTree' or 'SimpleMapping'
 LDAPGroupMemberAttribute=member
+# Attribute that LDAPGroupMemberAttribute matches against
+# comment out this line to use defualt which is the fully qualifed user dn
+# examples: uid
+#LDAPGroupMemberAttributeMatch=
 # Attribute which contain description of LDAP group, optional
 LDAPGroupDescriptionAttribute=
 # Group names map (from LDAP to ezpublish user-groups),
@@ -69,3 +75,12 @@
 # be automatically moved back (to the group they are configured to be placed in)
 # when the user logs in again.
 KeepGroupAssignment=disabled
+# This setting only applies to LDAPGroupMappingType=SimpleMapping
+# by default you are mapped out to the first group you are found in
+# the order in which it checks is the order of the groups in ldap
+# this will override that order to the order defined in here
+# ie:
+#	LDAPUserGroupMap[b]=primary
+#	LDAPUserGroupMap[a]=seccondy
+# When enabled a user in both ldap groups will be mapped to primary instead of seccondary
+KeepGroupMapOrder=enabled

now with my ldap setup of groups that arnt groupofuniquenames
say ldap groups
a_everyorne
b_justme
c_todd

where the first group a_eveyorne might hvae
memberUid=me
memberUid=bob
and group b_justme has
memberUid=me
and c_todd
memberUid=todd

then i have ez publish groups
Admins
LesserPeople

now what i want to archive is, map the b_justme group to admins, and a_everyone to lesserpeople
but the user 'todd' is also in my ldap, and i hate him so i don't want him to be able to login at all

so i have the following configuration

#do not let todd login
#or more specificaly if he is in a group not mapped to an ez publish group do not let him login
LDAPUserGroupType=map

LDAPGroupMappingType=SimpleMapping
LDAPGroupBaseDN=ou=Groups,dc=domain,dc=com
LDAPGroupNameAttribute=cn

#custom group schema
LDAPGroupClass=posixGroup
LDAPGroupMemberAttribute=memberUid
LDAPGroupMemberAttributeMatch=uid

#map in order of precedence
LDAPUserGroup[b_justme]=Admins
LDAPUserGroup[a_everyone]=LesserPeople

#use my map order
KeepGroupMapOrder=enabled

without the last option i would have been mapped to LesserPeople
because it would check a_everyone (alphabetical order) first and see i am in that group

even if the specific code solution my patch offers is not very good i believe the functionality it offers should be included in future versions of ez publish

any feedback would be greatly appreciated

Heath

Thursday 09 August 2007 6:14:30 pm

Hello,

Thank you for the contribution of this patch and detailed description of the solution.

Perhaps this would be more useful to others in the future if the patch was added to a new project on http://projects.ez.no

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:27:03
Script start
Timing: Jan 18 2025 16:27:03
Module start 'layout'
Timing: Jan 18 2025 16:27:03
Module start 'content'
Timing: Jan 18 2025 16:27:04
Module end 'content'
Timing: Jan 18 2025 16:27:04
Script end

Main resources:

Total runtime0.6536 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 588.0547152.6406
Module start 'layout' 0.00700.0032 740.695339.4922
Module start 'content' 0.01020.6424 780.1875572.9688
Module end 'content' 0.65260.0010 1,353.156316.1250
Script end 0.6536  1,369.2813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4988160.0002
Check MTime0.00130.2021160.0001
Mysql Total
Database connection0.00130.203510.0013
Mysqli_queries0.595591.1054540.0110
Looping result0.00050.0696520.0000
Template Total0.621995.220.3109
Template load0.00230.356820.0012
Template processing0.619694.792020.3098
Template load and register function0.00020.030110.0002
states
state_id_array0.00180.268210.0018
state_identifier_array0.00070.110620.0004
Override
Cache load0.00200.3099710.0000
Sytem overhead
Fetch class attribute can translate value0.00080.116620.0004
Fetch class attribute name0.00100.157530.0003
XML
Image XML parsing0.00080.123320.0004
class_abstraction
Instantiating content class attribute0.00000.000830.0000
General
dbfile0.00070.1074170.0000
String conversion0.00000.001440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
16content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 39
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs