Example #1
0
 public static function getInstance()
 {
     // We need to copy this, for PHP uses superclass with self :(
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Attempts an authentication to the underlying Erfurt framework via
  * HTTP GET/POST parameters.
  */
 public function authAction()
 {
     if (!$this->_config->service->allowGetAuth) {
         // disallow get
         if (!$this->_request->isPost()) {
             //$this->_response->setRawHeader('HTTP/1.0 405 Method Not Allowed');
             $this->_response->setHttpResponseCode(405);
             $this->_response->setHeader('Allow', 'POST');
             return;
         }
     }
     // fetch params
     $l = $this->_request->logout;
     if (isset($l) && ('true' == $l || 'false' == $l)) {
         $logout = $this->_request->logout == 'true' ? true : false;
     } elseif (isset($this->_request->u)) {
         $username = $this->_request->u;
         $password = $this->_request->getParam('p', '');
     } else {
         //$this->_response->setRawHeader('HTTP/1.0 400 Bad Request');
         $this->_response->setHttpResponseCode(400);
         return;
     }
     if (isset($logout) && true == $logout) {
         // logout
         Erfurt_Auth::getInstance()->clearIdentity();
         session_destroy();
         //$this->_response->setRawHeader('HTTP/1.0 200 OK');
         $this->_response->setHttpResponseCode(200);
         return;
     } else {
         // authenticate
         $result = $this->_owApp->erfurt->authenticate($username, $password);
     }
     // return HTTP result
     if ($result->isValid()) {
         // return success (200)
         //$this->_response->setRawHeader('HTTP/1.0 200 OK');
         $this->_response->setHttpResponseCode(200);
         return;
     } else {
         // return fail (401)
         //$this->_response->setRawHeader('HTTP/1.0 401 Unauthorized');
         $this->_response->setHttpResponseCode(401);
         return;
     }
 }
Example #3
0
 /**
  * Returns the auth instance.
  *
  * @return Zend_Auth
  */
 public function getAuth()
 {
     if (null === $this->_auth) {
         require_once 'Erfurt/Auth.php';
         $auth = Erfurt_Auth::getInstance();
         $config = $this->getConfig();
         if (isset($config->session->identifier)) {
             $sessionNamespace = 'Erfurt_Auth' . $config->session->identifier;
             require_once 'Zend/Auth/Storage/Session.php';
             $auth->setStorage(new Zend_Auth_Storage_Session($sessionNamespace));
         }
         $this->_auth = $auth;
     }
     return $this->_auth;
 }
 /**
  * Destroys auth credentials and logs the current agent out.
  */
 public function logoutAction()
 {
     // destroy auth
     Erfurt_Auth::getInstance()->clearIdentity();
     // destroy any selections user has made
     Zend_Session::destroy(true);
     $this->_redirect($this->_config->urlBase);
 }
Example #5
0
 private function _loadTestConfig()
 {
     if (null === $this->_customTestConfig) {
         if (is_readable(_TESTROOT . 'config.ini')) {
             $this->_customTestConfig = new Zend_Config_Ini(_TESTROOT . 'config.ini', 'private', array('allowModifications' => true));
         } else {
             if (is_readable(_TESTROOT . 'config.ini.dist')) {
                 $this->_customTestConfig = new Zend_Config_Ini(_TESTROOT . 'config.ini.dist', 'private', array('allowModifications' => true));
             } else {
                 $this->_customTestConfig = false;
             }
         }
         // overwrite store adapter to use with environment variable if set
         // this is useful, when we want to test with different stores without manually
         // editing the config
         if ($this->_customTestConfig !== false) {
             $storeAdapter = getenv('EF_STORE_ADAPTER');
             if ($storeAdapter === 'virtuoso' || $storeAdapter === 'zenddb') {
                 $this->_customTestConfig->store->backend = $storeAdapter;
             } else {
                 if ($storeAdapter !== false) {
                     throw new Exception('Invalid value of $EF_STORE_ADAPTER: ' . $storeAdapter);
                 }
             }
         }
     }
     $app = Erfurt_App::getInstance(false);
     // We always reload the config in Erfurt, for a test may have changed values
     // and we need a clean environment.
     if ($this->_customTestConfig !== false && $this->_customTestConfig !== null) {
         $app->loadConfig($this->_customTestConfig);
     } else {
         $app->loadConfig();
     }
     $this->_testConfig = $app->getConfig();
     // Disable versioning
     $app->getVersioning()->enableVersioning(false);
     // For tests we have no session!
     $auth = Erfurt_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_NonPersistent());
     $app->setAuth($auth);
 }