public function testGetAccessToken()
 {
     $session = $this->createSessionStub();
     $client = $this->createClientStub();
     $this->manager->setTokenGenerator($this->createTokenGeneratorStub());
     $accessToken = $this->manager->createAccessToken($session, $client);
     $loadedAccessToken = $this->manager->getAccessToken($accessToken->getToken());
     $this->assertEquals($loadedAccessToken->toArray(), $accessToken->toArray());
 }
 public function getFactories()
 {
     $smc = $this;
     return array('InoOicServer\\ContextStorage' => 'InoOicServer\\Context\\Storage\\StorageFactory', 'InoOicServer\\SessionStorage' => 'InoOicServer\\Session\\Storage\\StorageFactory', 'InoOicServer\\ClientRegistryStorage' => 'InoOicServer\\Client\\Registry\\StorageFactory', 'InoOicServer\\ClientRegistry' => 'InoOicServer\\Client\\RegistryFactory', 'InoOicServer\\ServerInfo' => function (ServiceManager $sm) use($smc) {
         $config = $sm->get('Config');
         if (!isset($config[$smc::CONFIG_SERVER_INFO]) || !is_array($config[$smc::CONFIG_SERVER_INFO])) {
             throw new Exception\ConfigNotFoundException($smc::CONFIG_SERVER_INFO);
         }
         $serverInfo = new ServerInfo($config[$smc::CONFIG_SERVER_INFO]);
         return $serverInfo;
     }, 'InoOicServer\\Logger' => function (ServiceManager $sm) use($smc) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['logger'])) {
             throw new Exception\ConfigNotFoundException('logger');
         }
         $loggerConfig = $config['oic_server']['logger'];
         if (!isset($loggerConfig['writers'])) {
             throw new Exception\ConfigNotFoundException('logger/writers');
         }
         $logger = new Log\Logger();
         if (count($loggerConfig['writers'])) {
             $priority = 1;
             foreach ($loggerConfig['writers'] as $writerConfig) {
                 $writer = $logger->writerPlugin($writerConfig['name'], $writerConfig['options']);
                 if (isset($writerConfig['filters']) && is_array($writerConfig['filters'])) {
                     foreach ($writerConfig['filters'] as $filterName => $filterValue) {
                         $filterClass = '\\Zend\\Log\\Filter\\' . String::underscoreToCamelCase($filterName);
                         $filter = new $filterClass($filterValue);
                         $writer->addFilter($filter);
                     }
                 }
                 if (isset($writerConfig['formatter']) && is_array($writerConfig['formatter']) && isset($writerConfig['formatter'])) {
                     $formatterConfig = $writerConfig['formatter'];
                     if (isset($formatterConfig['format'])) {
                         $formatter = new Log\Formatter\Simple($formatterConfig['format']);
                         if (isset($formatterConfig['dateTimeFormat'])) {
                             $formatter->setDateTimeFormat($formatterConfig['dateTimeFormat']);
                         }
                         $writer->setFormatter($formatter);
                     }
                 }
                 $logger->addWriter($writer, $priority++);
             }
         }
         return $logger;
     }, 'InoOicServer\\ErrorHandler' => function (ServiceManager $sm) {
         return new ErrorHandler($sm->get('InoOicServer\\Logger'));
     }, 'InoOicServer\\SessionManager' => function (ServiceManager $sm) {
         $sessionManager = new \Zend\Session\SessionManager();
         return $sessionManager;
     }, 'InoOicServer\\SessionContainer' => function (ServiceManager $sm) {
         // $config = $sm->get('Config');
         $sessionManager = $sm->get('InoOicServer\\SessionManager');
         $container = new \Zend\Session\Container('InoOicServer', $sessionManager);
         return $container;
     }, 'InoOicServer\\UserSerializer' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['user_serializer'])) {
             throw new Exception\ConfigNotFoundException('user_serializer');
         }
         return new User\Serializer\Serializer($config['oic_server']['user_serializer']);
     }, 'InoOicServer\\UserFactory' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['user_factory'])) {
             throw new Exception\ConfigNotFoundException('user_factory');
         }
         return new User\UserFactory($config['oic_server']['user_factory']);
     }, 'InoOicServer\\UserDataConnector' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['data_connectors'])) {
             throw new Exception\ConfigNotFoundException('data_connectors');
         }
         $dataConnectorConfigs = $config['oic_server']['data_connectors'];
         $factory = $sm->get('InoOicServer\\UserDataConnectorFactory');
         $chain = $factory->createDataConnector(array('class' => '\\InoOicServer\\User\\DataConnector\\Chain'));
         foreach ($dataConnectorConfigs as $dataConnectorConfig) {
             $chain->addDataConnector($factory->createDataConnector($dataConnectorConfig));
         }
         return $chain;
     }, 'InoOicServer\\UserValidator' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         $validatorsConfig = array();
         if (isset($config['oic_server']['user_validators']) && is_array($config['oic_server']['user_validators'])) {
             $validatorsConfig = $config['oic_server']['user_validators'];
         }
         /* @var $factory \InoOicServer\User\Validator\ValidatorFactory */
         $factory = $sm->get('InoOicServer\\UserValidatorFactory');
         $validator = $factory->createValidator(array('class' => '\\InoOicServer\\User\\Validator\\ChainValidator'));
         foreach ($validatorsConfig as $validatorConfig) {
             $subValidator = $factory->createValidator($validatorConfig);
             $subValidator->setSessionContainer($sm->get('InoOicServer\\SessionContainer'));
             $validator->addValidator($subValidator);
         }
         return $validator;
     }, 'InoOicServer\\UserInfoMapper' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['user_info_mapper'])) {
             throw new Exception\ConfigNotFoundException('user_info_mapper');
         }
         $mapperConfig = $config['oic_server']['user_info_mapper'];
         if (!isset($mapperConfig['class'])) {
             throw new Exception\ConfigNotFoundException('user_info_mapper / class');
         }
         $className = $mapperConfig['class'];
         if (!class_exists($className)) {
             throw new GeneralException\InvalidClassException(sprintf("Non-existent class '%s'", $className));
         }
         return new $className();
     }, 'InoOicServer\\OicSessionManager' => function (ServiceManager $sm) use($smc) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server'][$smc::CONFIG_SESSION_MANAGER]) || !is_array($config['oic_server'][$smc::CONFIG_SESSION_MANAGER])) {
             throw new Exception\ConfigNotFoundException($smc::CONFIG_SESSION_MANAGER);
         }
         $sessionManager = new SessionManager($config['oic_server'][$smc::CONFIG_SESSION_MANAGER]);
         $sessionManager->setStorage($sm->get('InoOicServer\\SessionStorage'));
         $sessionManager->setSessionIdGenerator($sm->get('InoOicServer\\SessionIdGenerator'));
         $sessionManager->setTokenGenerator($sm->get('InoOicServer\\TokenGenerator'));
         $sessionManager->setUserSerializer($sm->get('InoOicServer\\UserSerializer'));
         return $sessionManager;
     }, 'InoOicServer\\SessionIdGenerator' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['session_id_generator'])) {
             throw new Exception\ConfigNotFoundException('session_id_generator');
         }
         $generatorConfig = $config['oic_server']['session_id_generator'];
         if (!isset($generatorConfig['class'])) {
             throw new Exception\ConfigNotFoundException('session_id_generator/class');
         }
         $className = $generatorConfig['class'];
         $options = array();
         if (isset($generatorConfig['options']) && is_array($generatorConfig['options'])) {
             $options = $generatorConfig['options'];
         }
         return new $className($options);
     }, 'InoOicServer\\AuthenticationManager' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['authentication'])) {
             throw new Exception\ConfigNotFoundException('authentication');
         }
         $manager = new Authentication\Manager($config['oic_server']['authentication']);
         return $manager;
     }, 'InoOicServer\\ClientAuthenticationManager' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         if (!isset($config['oic_server']['client_authentication_manager']) || !is_array($config['oic_server']['client_authentication_manager'])) {
             throw new Exception\ConfigNotFoundException('client_authentication_manager');
         }
         $manager = new Client\Authentication\Manager($config['oic_server']['client_authentication_manager']);
         return $manager;
     }, 'InoOicServer\\AuthorizeContextManager' => function (ServiceManager $sm) {
         $config = $sm->get('Config');
         $timeout = null;
         if (isset($config['oic_server']['context_authorize']['timeout'])) {
             $timeout = intval($config['oic_server']['context_authorize']['timeout']);
         }
         $contextStorage = $sm->get('InoOicServer\\ContextStorage');
         $sessionContainer = $sm->get('InoOicServer\\SessionContainer');
         $contextStorage->setSessionContainer($sessionContainer);
         $contextFactory = $sm->get('InoOicServer\\AuthorizeContextFactory');
         $requestFactory = $sm->get('InoOicServer\\AuthorizeRequestFactory');
         $manager = new AuthorizeContextManager($contextStorage, $requestFactory, $contextFactory);
         if ($timeout) {
             $manager->setTimeout($timeout);
         }
         return $manager;
     }, 'InoOicServer\\AuthorizeDispatcher' => function (ServiceManager $sm) {
         $dispatcher = new Dispatcher\Authorize();
         $dispatcher->setAuthorizeResponse($sm->get('InoOicServer\\AuthorizeResponse'));
         $dispatcher->setClientRegistry($sm->get('InoOicServer\\ClientRegistry'));
         $dispatcher->setSessionManager($sm->get('InoOicServer\\OicSessionManager'));
         $dispatcher->setDataConnector($sm->get('InoOicServer\\UserDataConnector'));
         $dispatcher->setUserValidator($sm->get('InoOicServer\\UserValidator'));
         return $dispatcher;
     }, 'InoOicServer\\AuthorizeRequest' => function (ServiceManager $sm) {
         $httpRequest = $sm->get('Zend\\HttpRequest');
         $request = new Simple($httpRequest);
         return $request;
     }, 'InoOicServer\\AuthorizeResponse' => function (ServiceManager $sm) {
         return new Response\Authorize\Simple($sm->get('Response'));
     }, 'InoOicServer\\TokenDispatcher' => function (ServiceManager $sm) {
         $dispatcher = new Dispatcher\Token();
         $dispatcher->setClientRegistry($sm->get('InoOicServer\\ClientRegistry'));
         $dispatcher->setSessionManager($sm->get('InoOicServer\\OicSessionManager'));
         $dispatcher->setTokenRequest($sm->get('InoOicServer\\TokenRequest'));
         $dispatcher->setTokenResponse($sm->get('InoOicServer\\TokenResponse'));
         $dispatcher->setClientAuthenticationManager($sm->get('InoOicServer\\ClientAuthenticationManager'));
         return $dispatcher;
     }, 'InoOicServer\\TokenRequest' => function (ServiceManager $sm) {
         return new Request\Token($sm->get('Request'));
     }, 'InoOicServer\\TokenResponse' => function (ServiceManager $sm) {
         return new Response\Token($sm->get('Response'));
     }, 'InoOicServer\\UserInfoDispatcher' => function (ServiceManager $sm) {
         $dispatcher = new Dispatcher\UserInfo();
         $dispatcher->setSessionManager($sm->get('InoOicServer\\OicSessionManager'));
         $dispatcher->setUserInfoRequest($sm->get('InoOicServer\\UserInfoRequest'));
         $dispatcher->setUserInfoResponse($sm->get('InoOicServer\\UserInfoResponse'));
         $dispatcher->setUserInfoMapper($sm->get('InoOicServer\\UserInfoMapper'));
         return $dispatcher;
     }, 'InoOicServer\\UserInfoRequest' => function (ServiceManager $sm) {
         return new Request\UserInfo($sm->get('Request'));
     }, 'InoOicServer\\UserInfoResponse' => function (ServiceManager $sm) {
         return new Response\UserInfo($sm->get('Response'));
     }, 'InoOicServer\\InputFilterFactory' => function (ServiceManager $sm) {
         $factory = new Factory();
         $config = $sm->get('Config');
         if (isset($config['oic_server']['filter_invokables'])) {
             $filterInvokables = $config['oic_server']['filter_invokables'];
             $factory->setDefaultFilterChain(new FilterChain());
             $pluginManager = $factory->getDefaultFilterChain()->getPluginManager();
             foreach ($filterInvokables as $filterName => $filterClass) {
                 $pluginManager->setInvokableClass($filterName, $filterClass);
             }
         }
         return $factory;
     }, 'Zend\\HttpRequest' => function (ServiceManager $sm) {
         $request = new \Zend\Http\PhpEnvironment\Request();
         return $request;
     });
 }