/** * read ldap / get users and groups from tine an create mapping * * @return array */ protected function _getGroupMapping() { $this->_logger->info(__METHOD__ . '::' . __LINE__ . ' Fetching user mapping ...'); $filter = Zend_Ldap_Filter::andFilter(Zend_Ldap_Filter::string($this->_groupBaseFilter)); $mapping = array(); $groupNameMapping = $this->_config->groupNameMapping ? $this->_config->groupNameMapping->toArray() : array(); $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' Group name mapping: ' . print_r($groupNameMapping, TRUE)); $ldapGroups = $this->_ldap->search($filter, $this->_config->ldap->baseDn, $this->_groupSearchScope, array('*', '+')); foreach ($ldapGroups as $group) { $groupname = isset($groupNameMapping[$group['cn'][0]]) ? $groupNameMapping[$group['cn'][0]] : $group['cn'][0]; $ldapUuid = $group['entryuuid'][0]; try { $tineGroup = $this->_tineGroupBackend->getGroupByName($groupname); $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' Group ' . $groupname . ' (' . $group['cn'][0] . '): ' . $tineGroup->getId() . ' -> ' . $ldapUuid); $mapping[$tineGroup->getId()] = $ldapUuid; } catch (Tinebase_Exception_Record_NotDefined $tenf) { // @todo should be: Tinebase_Exception_NotFound $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' Group ' . $groupname . ' (' . $group['cn'][0] . '): ' . $tenf->getMessage()); } } $this->_logger->info(__METHOD__ . '::' . __LINE__ . ' Found ' . count($mapping) . ' groups for the mapping.'); $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($mapping, TRUE)); return $mapping; }
/** * try to get the group with the name tine20phpunit * */ public function testGetGroupByName() { $this->testAddGroup(); $group = $this->_backend->getGroupByName('tine20phpunit'); $this->assertEquals($this->objects['initialGroup']->name, $group->name); }
protected function _testImportGroupsHelper($expected) { $be = new Tinebase_Group_Sql(); foreach ($expected as $name => $count) { $group = $be->getGroupByName($name); $members = $be->getGroupMembers($group); $this->assertEquals($count, count($members), 'Group ' . $name . ' should have ' . $count . ' members!'); $this->assertEquals('displayed', $group->visibility, 'Group ' . $name . ' should be visible!'); } }
/** * * @param Tinebase_Record_Abstract $record * @param array $members */ protected function _handleGroupMemberShip($record, $members) { $be = new Tinebase_Group_Sql(); $group = $be->getGroupByName($record->name); $oldMembers = $be->getGroupMembers($group->getId()); $newMembers = $this->_resolveUsers($members); foreach ($oldMembers as $oldMember) { if (!in_array($oldMember, $newMembers)) { $be->removeGroupMember($record->getId(), $oldMember); } } foreach ($newMembers as $newMember) { if (!in_array($newMember, $oldMembers)) { $be->addGroupMember($record->getId(), $newMember); } } }