private function findUnit(Identity $identity) { if (null === $this->unit) { $filter = Filter::equals('mail', $identity->mail); $baseDn = Dn::factory($this->ldap->getBaseDn())->prepend(['ou' => 'people']); $result = $this->ldap->search($filter, $baseDn, Ldap::SEARCH_SCOPE_ONE, ['l']); if (1 !== $result->count()) { return; } $result = $result->current(); $unitDn = $result['l'][0]; $this->unit = $this->ldap->getNode($unitDn); } return $this->unit; }
/** * Sets the LDAP specific options on the Zend_Ldap instance * * @param Zend_Ldap $ldap * @param array $options * @return array of auth-adapter specific options */ protected function _prepareOptions(\Zend\Ldap\Ldap $ldap, array $options) { $adapterOptions = array('group' => null, 'groupDn' => $ldap->getBaseDn(), 'groupScope' => \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, 'groupAttr' => 'cn', 'groupFilter' => 'objectClass=groupOfUniqueNames', 'memberAttr' => 'uniqueMember', 'memberIsDn' => true); foreach ($adapterOptions as $key => $value) { if (array_key_exists($key, $options)) { $value = $options[$key]; unset($options[$key]); switch ($key) { case 'groupScope': $value = (int) $value; if (in_array($value, array(\Zend\Ldap\Ldap::SEARCH_SCOPE_BASE, \Zend\Ldap\Ldap::SEARCH_SCOPE_ONE, \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB), true)) { $adapterOptions[$key] = $value; } break; case 'memberIsDn': $adapterOptions[$key] = $value === true || $value === '1' || strcasecmp($value, 'true') == 0; break; default: $adapterOptions[$key] = trim($value); break; } } } $ldap->setOptions($options); return $adapterOptions; }
/** * Attach node to an LDAP connection * * This is an offline method. * * @param Ldap $ldap * @return Node Provides a fluid interface * @throws Exception\LdapException */ public function attachLdap(Ldap $ldap) { if (!Dn::isChildOf($this->_getDn(), $ldap->getBaseDn())) { throw new Exception\LdapException(null, 'LDAP connection is not responsible for given node.', Exception\LdapException::LDAP_OTHER); } if ($ldap !== $this->ldap) { $this->ldap = $ldap; if (is_array($this->children)) { foreach ($this->children as $child) { $child->attachLdap($ldap); } } } return $this; }