protected function _getAccessToken($conf, $subjectId, $requireNew) { $cache = EngineBlock_ApplicationSingleton::getInstance()->getDiContainer()->getApplicationCache(); if (!$requireNew && $cache instanceof Zend_Cache_Backend_Apc) { $accessToken = $cache->load(self::ACCESS_TOKEN_KEY); if ($accessToken) { return $accessToken; } } // for example https://api.dev.surfconext.nl/v1/oauth2/token $baseUrl = $this->_ensureTrailingSlash($conf->baseUrl) . 'v1/oauth2/token'; $client = new Zend_Http_Client($baseUrl); try { $response = $client->setConfig(array('timeout' => 15))->setHeaders(Zend_Http_Client::CONTENT_TYPE, Zend_Http_Client::ENC_URLENCODED)->setAuth($conf->key, $conf->secret)->setParameterPost('grant_type', 'client_credentials')->request(Zend_Http_Client::POST); $result = json_decode($response->getBody(), true); if (isset($result['access_token'])) { $accessToken = $result['access_token']; if ($cache instanceof Zend_Cache_Backend_Apc) { $cache->save($accessToken, self::ACCESS_TOKEN_KEY); } return $accessToken; } throw new EngineBlock_VirtualOrganization_AccessTokenNotGrantedException('AccessToken not granted for EB as SP. Check SR and the Group Provider endpoint log.'); } catch (Exception $exception) { $additionalInfo = EngineBlock_Log_Message_AdditionalInfo::create()->setUserId($subjectId)->setDetails($exception->getTraceAsString()); EngineBlock_ApplicationSingleton::getLog()->error("Error in connecting to API(s) for access token grant" . $exception->getMessage(), array('additional_info' => $additionalInfo->toArray())); throw new EngineBlock_VirtualOrganization_AccessTokenNotGrantedException('AccessToken not granted for EB as SP. Check SR and the Group Provider endpoint log', EngineBlock_Exception::CODE_ALERT, $exception); } }
/** * @param array $record * @return array */ private function addAdditionalInfo(array $record) { $hasEngineBlockException = isset($record['context']['exception']) && $record['context']['exception'] instanceof EngineBlock_Exception; if ($hasEngineBlockException) { $record['context']['exception'] = EngineBlock_Log_Message_AdditionalInfo::createFromException($record['context']['exception'])->toArray(); } return $record; }
/** * Create a new Database connection, for a given mode self::MODE_READ and self::MODE_WRITE, * defaults to write mode. * * @static * @throws EngineBlock_Exception * @param $mode * @return PDO */ public function create($mode = null) { if ($mode === null) { $mode = self::MODE_WRITE; } $databaseSettings = $this->_getDatabaseSettings(); if ($mode === self::MODE_READ) { try { return $this->_createReadConnection($databaseSettings); } catch (Exception $e) { $additionalInfo = EngineBlock_Log_Message_AdditionalInfo::create()->setDetails($e->getTraceAsString()); EngineBlock_ApplicationSingleton::getLog()->error("Unable to create a Read connection, trying to create a write connection, exception: " . print_r($e, true), array('additional_info' => $additionalInfo->toArray())); return $this->_createWriteConnection($databaseSettings); } } else { if ($mode === self::MODE_WRITE) { return $this->_createWriteConnection($databaseSettings); } else { throw new EngineBlock_Database_Exception("Requested database connection with unknown mode '{$mode}'"); } } }
public function testItCorrectlyDeterminesTheExceptionsSeverity() { $exception = new EngineBlock_Exception('message', EngineBlock_Exception::CODE_ALERT); $additionalInfo = EngineBlock_Log_Message_AdditionalInfo::createFromException($exception); $this->assertSame('ALERT', $additionalInfo->getSeverity()); }
private function getNameEn(IdentityProvider $identityProvider, EngineBlock_Log_Message_AdditionalInfo $additionalInfo) { if ($identityProvider->displayNameEn) { return $identityProvider->displayNameEn; } if ($identityProvider->nameEn) { return $identityProvider->nameEn; } EngineBlock_ApplicationSingleton::getLog()->warning('No EN displayName and name found for idp: ' . $identityProvider->entityId, array('additional_info' => $additionalInfo->toArray())); return $identityProvider->entityId; }
protected function _setAdditionalEventItems(EngineBlock_Log_Message_AdditionalInfo $additionalInfo = null) { if ($additionalInfo) { $additionalEvents = $additionalInfo->toArray(); foreach ($additionalEvents as $key => $value) { $this->setEventItem($key, $value); } } }