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);
     }
 }
 /**
  * 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}'");
         }
     }
 }
 protected function _transformIdpsForWayf(array $idpEntityIds, $isDebugRequest)
 {
     $identityProviders = $this->_server->getRepository()->findIdentityProvidersByEntityId($idpEntityIds);
     $wayfIdps = array();
     foreach ($identityProviders as $identityProvider) {
         if ($identityProvider->entityId === $this->_server->getUrl('idpMetadataService')) {
             // Skip ourselves as a valid Idp
             continue;
         }
         if ($identityProvider->hidden) {
             continue;
         }
         $additionalInfo = EngineBlock_Log_Message_AdditionalInfo::create()->setIdp($identityProvider->entityId);
         $wayfIdp = array('Name_nl' => $this->getNameNl($identityProvider, $additionalInfo), 'Name_en' => $this->getNameEn($identityProvider, $additionalInfo), 'Logo' => $identityProvider->logo ? $identityProvider->logo->url : '/media/idp-logo-not-found.png', 'Keywords' => $this->getKeywords($identityProvider), 'Access' => $identityProvider->enabledInWayf || $isDebugRequest ? '1' : '0', 'ID' => md5($identityProvider->entityId), 'EntityID' => $identityProvider->entityId);
         $wayfIdps[] = $wayfIdp;
     }
     return $wayfIdps;
 }