Remove the isConnected() call again and ensure we get a connected session once we...
authorGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 20:44:58 +0000 (21:44 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 20:44:58 +0000 (21:44 +0100)
14 files changed:
framework/Kolab_Session/lib/Horde/Kolab/Session.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php
framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php
framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php

index 45a7c02..f36a04a 100644 (file)
@@ -106,11 +106,4 @@ interface Horde_Kolab_Session
      * @return Horde_Kolab_Storage The storage connection.
      */
     public function getStorage();
-
-    /**
-     * Return the connection status of this session.
-     *
-     * @return boolean True if the session has been successfully connected.
-     */
-    public function isConnected();
 }
index ef31e55..9c046a6 100644 (file)
@@ -179,14 +179,4 @@ class Horde_Kolab_Session_Anonymous implements Horde_Kolab_Session
     {
         return $this->_session->getStorage();
     }
-
-    /**
-     * Return the connection status of this session.
-     *
-     * @return boolean True if the session has been successfully connected.
-     */
-    public function isConnected()
-    {
-        return $this->_session->isConnected();
-    }
 }
index a2ec455..f9b8230 100644 (file)
@@ -104,13 +104,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
     private $_storage;
 
     /**
-     * Indicate if this session was successfully connected.
-     *
-     * @var array
-     */
-    private $_connected = false;
-
-    /**
      * Constructor.
      *
      * @param string             $user_id The session will be setup for the user
@@ -144,12 +137,12 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         if (isset($credentials['password'])) {
             $password = $credentials['password'];
         } else {
-            throw new Horde_Kolab_Session_Exception('Missing password!');
+            $password = '';
         }
 
         try {
             $this->_server->connect($this->_user_id, $password);
-            $user_object     = $this->_server->objects->fetch();
+            $user_object = $this->_server->objects->fetch();
         } catch (Horde_Kolab_Server_Exception_Bindfailed $e) {
             throw new Horde_Kolab_Session_Exception_Badlogin($e);
         } catch (Horde_Kolab_Server_Exception $e) {
@@ -375,14 +368,4 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         }
         return $this->_storage;
     }
-
-    /**
-     * Return the connection status of this session.
-     *
-     * @return boolean True if the session has been successfully connected.
-     */
-    public function isConnected()
-    {
-        return $this->_connected;
-    }
 }
index 3dca47c..9fdba64 100644 (file)
@@ -94,9 +94,11 @@ interface Horde_Kolab_Session_Factory
      * Returns either a reference to a session handler with data retrieved from
      * the session or a new session handler.
      *
-     * @param string $user The session will be setup for the user with this ID.
+     * @param string $user        The session will be setup for the user with
+     *                            this ID.
+     * @param array  $credentials An array of login credentials.
      *
      * @return Horde_Kolab_Session The concrete Kolab session reference.
      */
-    public function getSession($user = null);
+    public function getSession($user = null, array $credentials = null);
 }
index 9f8be47..85f5081 100644 (file)
@@ -158,12 +158,14 @@ implements Horde_Kolab_Session_Factory
      * Returns either a reference to a session handler with data retrieved from
      * the session or a new session handler.
      *
-     * @param string $user The session will be setup for the user with this ID.
+     * @param string $user        The session will be setup for the user with
+     *                            this ID.
+     * @param array  $credentials An array of login credentials.
      *
      * @return Horde_Kolab_Session The concrete Kolab session reference.
      */
-    public function getSession($user = null)
+    public function getSession($user = null, array $credentials = null)
     {
-        return $this->_factory->getSession($user);
+        return $this->_factory->getSession($user, $credentials);
     }
 }
index 309357e..e995107 100644 (file)
@@ -91,11 +91,13 @@ implements Horde_Kolab_Session_Factory
      * Returns either a reference to a session handler with data retrieved from
      * the session or a new session handler.
      *
-     * @param string $user The session will be setup for the user with this ID.
+     * @param string $user        The session will be setup for the user with
+     *                            this ID.
+     * @param array  $credentials An array of login credentials.
      *
      * @return Horde_Kolab_Session The concrete Kolab session reference.
      */
-    public function getSession($user = null)
+    public function getSession($user = null, array $credentials = null)
     {
         $storage = $this->getSessionStorage();
         $session = $storage->load();
@@ -103,6 +105,8 @@ implements Horde_Kolab_Session_Factory
         if (!empty($session) && $this->validate($session, $user)) {
             return $session;
         }
-        return $this->createSession($user);
+        $session = $this->createSession($user);
+        $session->connect($credentials);
+        return $session;
     }
 }
index 0458c66..8fa9930 100644 (file)
@@ -173,12 +173,14 @@ implements Horde_Kolab_Session_Factory
      * Returns either a reference to a session handler with data retrieved from
      * the session or a new session handler.
      *
-     * @param string $user The session will be setup for the user with this ID.
+     * @param string $user        The session will be setup for the user with
+     *                            this ID.
+     * @param array  $credentials An array of login credentials.
      *
      * @return Horde_Kolab_Session The concrete Kolab session reference.
      */
-    public function getSession($user = null)
+    public function getSession($user = null, array $credentials = null)
     {
-        return $this->_factory->getSession($user);
+        return $this->_factory->getSession($user, $credentials);
     }
 }
index 513d92e..c398ebf 100644 (file)
@@ -143,12 +143,14 @@ implements Horde_Kolab_Session_Factory
      * Returns either a reference to a session handler with data retrieved from
      * the session or a new session handler.
      *
-     * @param string $user The session will be setup for the user with this ID.
+     * @param string $user        The session will be setup for the user with
+     *                            this ID.
+     * @param array  $credentials An array of login credentials.
      *
      * @return Horde_Kolab_Session The concrete Kolab session reference.
      */
-    public function getSession($user = null)
+    public function getSession($user = null, array $credentials = null)
     {
-        return $this->_factory->getSession($user);
+        return $this->_factory->getSession($user, $credentials);
     }
 }
index d99dd32..bba8424 100644 (file)
@@ -168,14 +168,4 @@ class Horde_Kolab_Session_Logged implements Horde_Kolab_Session
     {
         return $this->_session->getStorage();
     }
-
-    /**
-     * Return the connection status of this session.
-     *
-     * @return boolean True if the session has been successfully connected.
-     */
-    public function isConnected()
-    {
-        return $this->_session->isConnected();
-    }
 }
index 033f70b..06cbc01 100644 (file)
@@ -59,10 +59,7 @@ class Horde_Kolab_Session_Singleton
             $config            = $conf['kolab'];
             $config['logger']  = Horde::getLogger();
             $factory = new Horde_Kolab_Session_Factory_Configuration($config);
-            self::$_instance = $factory->getSession($user);
-            if (!self::$_instance->isConnected()) {
-                self::$_instance->connect($credentials);
-            }
+            self::$_instance = $factory->getSession($user, $credentials);
         }
         return self::$_instance;
     }
index f73215e..c145590 100644 (file)
@@ -167,14 +167,4 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
     {
         return $this->_session->getStorage();
     }
-
-    /**
-     * Return the connection status of this session.
-     *
-     * @return boolean True if the session has been successfully connected.
-     */
-    public function isConnected()
-    {
-        return $this->_session->isConnected();
-    }
 }
index 4247388..483cd2a 100644 (file)
@@ -162,18 +162,6 @@ class Horde_Kolab_Session_Class_BaseTest extends Horde_Kolab_Session_SessionTest
         $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer());
     }
 
-    public function testMethodConnectThrowsExceptionIfTheCredentialsHaveNoPasswordEntry()
-    {
-        $session = new Horde_Kolab_Session_Base(
-            'user', $this->_getComposite(), array()
-        );
-        try {
-            $session->connect(array());
-        } catch (Horde_Kolab_Session_Exception $e) {
-            $this->assertEquals('Missing password!', $e->getMessage());
-        }
-    }
-
     public function testMethodConnectThrowsExceptionIfTheConnectionFailed()
     {
         $composite = $this->_getMockedComposite();
index 5379d5c..0ff43c5 100644 (file)
@@ -36,6 +36,9 @@ class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_Ses
     {
         parent::setUp();
         $this->setupFactoryMocks();
+        $this->user = $this->getMock(
+            'Horde_Kolab_Server_Object_Hash', array(), array(), '', false, false
+        );
     }
 
     public function testMethodGetvalidatorHasResultHordekolabsesessionvalid()
@@ -103,6 +106,15 @@ class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_Ses
         $this->session_auth->expects($this->once())
             ->method('getCurrentUser')
             ->will($this->returnValue('new@example.org'));
+        $this->server->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $this->user->expects($this->exactly(1))
+            ->method('getSingle')
+            ->will($this->returnValue('mail@example.org'));
+        $this->user->expects($this->exactly(4))
+            ->method('getExternal')
+            ->will($this->returnValue(array('mail@example.org')));
         $factory = new Horde_Kolab_Session_Factory_Constructor(
             $this->server, $this->session_auth, array(), $this->session_storage
         );
@@ -114,6 +126,15 @@ class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_Ses
         $this->session_storage->expects($this->once())
             ->method('load')
             ->will($this->returnValue(false));
+        $this->server->objects->expects($this->once())
+            ->method('fetch')
+            ->will($this->returnValue($this->user));
+        $this->user->expects($this->exactly(1))
+            ->method('getSingle')
+            ->will($this->returnValue('mail@example.org'));
+        $this->user->expects($this->exactly(4))
+            ->method('getExternal')
+            ->will($this->returnValue(array('mail@example.org')));
         $factory = new Horde_Kolab_Session_Factory_Constructor(
             $this->server, $this->session_auth, array(), $this->session_storage
         );
index c4f54d8..5946485 100644 (file)
@@ -210,7 +210,19 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se
         $factory = new Horde_Kolab_Session_Factory_Configuration(
             array(
                 'server' => array(
-                    'basedn' => ''
+                    'mock' => true,
+                    'basedn' => '',
+                    'data' => array(
+                        'dn=user' => array(
+                            'dn' => 'dn=user',
+                            'data' => array(
+                                'uid' => array(''),
+                                'mail' => array('user@example.org'),
+                                'userPassword' => array(''),
+                                'objectClass' => array('top', 'kolabInetOrgPerson'),
+                            )
+                        )
+                    )
                 )
             )
         );