/** * Apply the given configuration on this backend * * @param ConfigObject $config * * @return $this * * @throws ConfigurationError In case a linked user backend does not exist or is invalid */ public function setConfig(ConfigObject $config) { if ($config->backend === 'ldap') { $defaults = $this->getOpenLdapDefaults(); } elseif ($config->backend === 'msldap') { $defaults = $this->getActiveDirectoryDefaults(); } else { $defaults = new ConfigObject(); } if ($config->user_backend && $config->user_backend !== 'none') { $userBackend = UserBackend::create($config->user_backend); if (!$userBackend instanceof LdapUserBackend) { throw new ConfigurationError('User backend "%s" is not of type LDAP', $config->user_backend); } if ($this->ds->getHostname() !== $userBackend->getDataSource()->getHostname() || $this->ds->getPort() !== $userBackend->getDataSource()->getPort()) { // TODO(jom): Elaborate whether it makes sense to link directories on different hosts throw new ConfigurationError('It is required that a linked user backend refers to the ' . 'same directory as it\'s user group backend counterpart'); } $this->setUserBackend($userBackend); $defaults->merge(array('user_base_dn' => $userBackend->getBaseDn(), 'user_class' => $userBackend->getUserClass(), 'user_name_attribute' => $userBackend->getUserNameAttribute(), 'user_filter' => $userBackend->getFilter())); } return $this->setGroupBaseDn($config->base_dn)->setUserBaseDn($config->get('user_base_dn', $this->getGroupBaseDn()))->setGroupClass($config->get('group_class', $defaults->group_class))->setUserClass($config->get('user_class', $defaults->user_class))->setGroupNameAttribute($config->get('group_name_attribute', $defaults->group_name_attribute))->setUserNameAttribute($config->get('user_name_attribute', $defaults->user_name_attribute))->setGroupMemberAttribute($config->get('group_member_attribute', $defaults->group_member_attribute))->setGroupFilter($config->filter)->setUserFilter($config->user_filter); }
/** * @depends testWhetherConfigObjectsCanBeConvertedToArrays */ public function testWhetherItIsPossibleToMergeConfigObjects() { $config = new ConfigObject(array('a' => 'b')); $config->merge(array('a' => 'bb', 'c' => 'd', 'e' => array('f' => 'g'))); $this->assertEquals(array('a' => 'bb', 'c' => 'd', 'e' => array('f' => 'g')), $config->toArray(), 'ConfigObjects cannot be extended with arrays'); $config->merge(new ConfigObject(array('c' => array('d' => 'ee'), 'e' => array('h' => 'i')))); $this->assertEquals(array('a' => 'bb', 'c' => array('d' => 'ee'), 'e' => array('f' => 'g', 'h' => 'i')), $config->toArray(), 'ConfigObjects cannot be extended with other ConfigObjects'); }