/** * test imap authentication */ public function testImapAuth() { // use imap config for the auth config $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray(); if (empty($imapConfig)) { $this->markTestSkipped('No IMAP config found.'); } $authConfig = array('host' => $imapConfig['host'], 'port' => $imapConfig['port'], 'ssl' => $imapConfig['ssl'], 'domain' => $imapConfig['domain']); Tinebase_Auth::setBackendType(Tinebase_Auth::IMAP); Tinebase_Auth::setBackendConfiguration($authConfig); Tinebase_Auth::saveBackendConfiguration(); Tinebase_Auth::getInstance()->setBackend(); $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend()); $testCredentials = TestServer::getInstance()->getTestCredentials(); // valid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], $testCredentials['password']); $this->assertTrue($authResult->isValid()); // invalid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], 'some pw'); $this->assertFalse($authResult->isValid()); $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode()); $this->assertEquals(array('Invalid credentials for user ' . $this->_getEmailAddress(), ''), $authResult->getMessages()); }
/** * update to 2.6 * - move authentication storage configuration from config.inc.php to config db table * */ public function update_5() { $config = Setup_Controller::getInstance()->getConfigData(); if (!empty($config['authentication'])) { if (empty($config['authentication']['backend'])) { $config['authentication']['backend'] = 'Sql'; } $backendType = ucfirst($config['authentication']['backend']); Tinebase_Auth::setBackendType($backendType); //add default config settings $defaultConfig = Tinebase_Auth::getBackendConfigurationDefaults($backendType); Tinebase_Auth::setBackendConfiguration($defaultConfig); //override default settings with config.inc.php settings if (!empty($config['authentication'][$config['authentication']['backend']])) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting config: ' . print_r($config['authentication'][$config['authentication']['backend']], TRUE)); } Tinebase_Auth::setBackendConfiguration($config['authentication'][$config['authentication']['backend']]); } Tinebase_Auth::saveBackendConfiguration(); } $this->setApplicationVersion('Tinebase', '2.6'); }
/** * Update authentication provider * * @param array $_data * @return void */ protected function _updateAuthenticationProvider($_data) { Tinebase_Auth::setBackendType($_data['backend']); $config = isset($_data[$_data['backend']]) ? $_data[$_data['backend']] : $_data; $excludeKeys = array('adminLoginName', 'adminPassword', 'adminPasswordConfirmation'); foreach ($excludeKeys as $key) { if (isset($config[$key]) || array_key_exists($key, $config)) { unset($config[$key]); } } Tinebase_Auth::setBackendConfiguration($config, null, true); Tinebase_Auth::saveBackendConfiguration(); }
/** * test imap authentication */ public function testImapAuth() { // use imap config for the auth config $imapConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::IMAP); if (empty($imapConfig)) { $this->markTestSkipped('No IMAP config found.'); } $authConfig = array('host' => $imapConfig['host'], 'port' => $imapConfig['port'], 'ssl' => $imapConfig['ssl'], 'domain' => $imapConfig['domain']); Tinebase_Auth::setBackendType(Tinebase_Auth::IMAP); Tinebase_Auth::setBackendConfiguration($authConfig); Tinebase_Auth::saveBackendConfiguration(); Tinebase_Auth::getInstance()->setBackend(); $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend()); $testConfig = Zend_Registry::get('testConfig'); // valid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testConfig->username, $testConfig->password); $this->assertTrue($authResult->isValid()); // invalid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testConfig->username, 'some pw'); $this->assertFalse($authResult->isValid()); $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode()); if ($testConfig->email) { $this->assertEquals(array('Invalid credentials for user ' . $testConfig->email, ''), $authResult->getMessages()); } }