This now follows Jan suggestion to simply provide the user name as a string. Much simpler :)
/**
* Return the session validation driver.
*
- * @param Horde_Kolab_Session $session The session to validate.
- * @param Horde_Kolab_Session_Auth_Interface $auth The auth handler.
+ * @param Horde_Kolab_Session $session The session to validate.
+ * @param mixed $auth The user ID or false if no user is
+ * logged in.
*
* @return Horde_Kolab_Session_Valid_Interface The driver for validating
* sessions.
*/
public function getSessionValidator(
Horde_Kolab_Session $session,
- Horde_Kolab_Session_Auth_Interface $auth
+ $auth
) {
$configuration = $this->_injector->getInstance('Horde_Kolab_Session_Configuration');
) {
return $this->getSessionValidator(
$session,
- $this->_injector->getInstance('Horde_Kolab_Session_Auth_Interface')
+ $this->_injector->getInstance('Horde_Registry')->getAuth()
)->isValid();
}
* @package Core
*/
class Horde_Registry
-implements Horde_Interfaces_Registry_Auth
{
/* Session flags. */
const SESSION_NONE = 1;
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Interfaces</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>Injector</name>
<channel>pear.horde.org</channel>
</package>
+++ /dev/null
-<?php
-/**
- * Defines a provider of authentication information.
- *
- * PHP version 5
- *
- * @category Horde
- * @package Interfaces
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Interfaces
- */
-
-/**
- * Defines a provider of authentication information.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Horde
- * @package Interfaces
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Interfaces
- */
-interface Horde_Interfaces_Registry_Auth
-{
- /**
- * Returns the currently logged in user, if there is one.
- *
- * @param string $format The return format, defaults to the unique Horde
- * ID. Alternative formats:
- * - bare: Horde ID without any domain information
- * (e.g., foo@example.com would be returned as
- * 'foo').
- * - domain: Domain of the Horde ID (e.g.,
- * foo@example.com would be returned as
- * 'example.com').
- * - original: The username used to originally login
- * to Horde.
- *
- * @return mixed The user ID or false if no user is logged in.
- */
- public function getAuth($format = null);
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>Interfaces</name>
- <channel>pear.horde.org</channel>
- <summary>A collection of Horde specific interfaces.</summary>
- <description>This package provides the interfaces that are required for the communication between framework packages and the core application infrastructure of Horde. The main provider of implementations found in this package will be the Horde Core framework package.
- </description>
- <lead>
- <name>Gunnar Wrobel</name>
- <user>wrobel</user>
- <email>p@rdus.de</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Chuck Hagenbuch</name>
- <user>chuck</user>
- <email>chuck@horde.org</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Jan Schneider</name>
- <user>jan</user>
- <email>jan@horde.org</email>
- <active>yes</active>
- </lead>
- <date>2009-03-02</date>
- <version>
- <release>0.0.1</release>
- <api>0.0.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
- * Initial package.
- </notes>
- <contents>
- <dir name="/">
- <dir name="lib">
- <dir name="Horde">
- <dir name="Interfaces">
- <dir name="Registry">
- <file name="Auth.php" role="php" />
- </dir> <!-- /lib/Horde/Session -->
- </dir> <!-- /lib/Horde/Kolab -->
- </dir> <!-- /lib/Horde -->
- </dir> <!-- /lib -->
- </dir> <!-- / -->
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.3.0</min>
- </php>
- <pearinstaller>
- <min>1.4.0b1</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease>
- <filelist>
- <install name="lib/Horde/Interfaces/Registry/Auth.php" as="Horde/Interfaces/Registry/Auth.php" />
- </filelist>
- </phprelease>
- <changelog>
- </changelog>
-</package>
* information in the Kolab session handler as reading this data is expensive
* and it is sufficient to read it once per session.
*
- * The users account id needs to be provided from the outside via an instance of
- * Horde_Interfaces_Registry_Auth::. Any additional Kolab user data relevant for
- * the user session should be accessed via the Horde_Kolab_Session class.
+ * The users account id needs to be provided from the outside. Any
+ * additional Kolab user data relevant for the user session should be
+ * accessed via the Horde_Kolab_Session class.
*
* Copyright 2008-2010 The Horde Project (http://www.horde.org/)
*
+++ /dev/null
-<?php
-/**
- * Mock authentication for the Kolab session information.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-
-/**
- * Mock authentication for the Kolab session information.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-class Horde_Kolab_Session_Auth_Mock
-implements Horde_Interfaces_Registry_Auth
-{
- /**
- * The user this instance will report.
- *
- * @var string
- */
- private $_user;
-
- /**
- * Constructor
- *
- * @param string $user The user this instance should report.
- */
- public function __construct($user)
- {
- $this->_user = $user;
- }
-
- /**
- * Returns the currently logged in user, if there is one.
- *
- * @param string $format The return format, defaults to the unique Horde
- * ID. Alternative formats:
- * - bare: Horde ID without any domain information
- * (e.g., foo@example.com would be returned as
- * 'foo').
- * - domain: Domain of the Horde ID (e.g.,
- * foo@example.com would be returned as
- * 'example.com').
- * - original: The username used to originally login
- * to Horde.
- *
- * @return mixed The user ID or false if no user is logged in.
- */
- public function getAuth($format = null)
- {
- if (empty($this->_user)) {
- return false;
- }
-
- $user = $this->_user;
-
- switch ($format) {
- case 'bare':
- return (($pos = strpos($user, '@')) === false)
- ? $user
- : substr($user, 0, $pos);
-
- case 'domain':
- return (($pos = strpos($user, '@')) === false)
- ? false
- : substr($user, $pos + 1);
-
- default:
- return $user;
- }
- }
-}
/**
* Provides authentication information for this object.
*
- * @var Horde_Interfaces_Registry_Auth
+ * @var mixed The user ID or false if no user is logged in.
*/
private $_auth;
/**
* Constructor.
*
- * @param Horde_Kolab_Session $session The session that should be
- * validated.
- * @param Horde_Interfaces_Registry_Auth $auth The authentication handler.
+ * @param Horde_Kolab_Session $session The session that should be validated.
+ * @param mixed $auth The user ID or false if no user is
+ * logged in.
*/
public function __construct(
Horde_Kolab_Session $session,
- Horde_Interfaces_Registry_Auth $auth
+ $auth
) {
$this->_session = $session;
$this->_auth = $auth;
public function isValid($user = null)
{
$mail = $this->_session->getMail();
- if ($this->_auth->getAuth() != $mail) {
+ if ($this->_auth != $mail) {
return false;
}
if (empty($user)) {
/**
* Return the auth driver of this validator.
*
- * @return Horde_Interfaces_Registry_Auth The auth driver set for this
- * validator.
+ * @return mixed The user ID or false if no user is logged in.
*/
public function getAuth()
{
sprintf(
"Invalid Kolab session for current user \"%s\", requested"
. " user \"%s\" and stored user \"%s\".",
- $this->_valid->getAuth()->getAuth(),
+ $this->_valid->getAuth(),
$user,
$this->_valid->getSession()->getMail()
)
/**
* Return the auth driver of this validator.
*
- * @return Horde_Interfaces_Registry_Auth The auth driver set for this
- * validator.
+ * @return mixed The user ID or false if no user is logged in.
*/
public function getAuth()
{
/**
* Return the auth driver of this validator.
*
- * @return Horde_Interfaces_Registry_Auth The auth driver set for this
- * validator.
+ * @return mixed The user ID or false if no user is logged in.
*/
public function getAuth();
}
\ No newline at end of file
<dir name="Kolab">
<file name="Session.php" role="php" />
<dir name="Session">
- <dir name="Auth">
- <file name="Mock.php" role="php" />
- </dir> <!-- /lib/Horde/Session/Auth -->
<file name="Base.php" role="php" />
<dir name="Decorator">
<file name="Anonymous.php" role="php" />
<file name="AllTests.php" role="test" />
<file name="Autoload.php" role="test" />
<dir name="Class">
- <dir name="Auth">
- <file name="MockTest.php" role="test" />
- </dir> <!-- /test/Horde/Kolab/Session/Class/Auth -->
<file name="BaseTest.php" role="test" />
<dir name="Decorator">
<file name="AnonymousTest.php" role="test" />
<min>1.4.0b1</min>
</pearinstaller>
<package>
- <name>Interfaces</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>Kolab_Server</name>
<channel>pear.horde.org</channel>
</package>
<phprelease>
<filelist>
<install name="lib/Horde/Kolab/Session.php" as="Horde/Kolab/Session.php" />
- <install name="lib/Horde/Kolab/Session/Auth/Mock.php" as="Horde/Kolab/Session/Auth/Mock.php" />
<install name="lib/Horde/Kolab/Session/Base.php" as="Horde/Kolab/Session/Base.php" />
<install name="lib/Horde/Kolab/Session/Exception.php" as="Horde/Kolab/Session/Exception.php" />
<install name="lib/Horde/Kolab/Session/Exception/Badlogin.php" as="Horde/Kolab/Session/Exception/Badlogin.php" />
<install name="lib/Horde/Kolab/Session/Valid/Interface.php" as="Horde/Kolab/Session/Valid/Interface.php" />
<install name="test/Horde/Kolab/Session/AllTests.php" as="Horde/Kolab/Session/AllTests.php" />
<install name="test/Horde/Kolab/Session/Autoload.php" as="Horde/Kolab/Session/Autoload.php" />
- <install name="test/Horde/Kolab/Session/Class/Auth/MockTest.php" as="Horde/Kolab/Session/Class/Auth/MockTest.php" />
<install name="test/Horde/Kolab/Session/Class/BaseTest.php" as="Horde/Kolab/Session/Class/BaseTest.php" />
<install name="test/Horde/Kolab/Session/Class/Decorator/AnonymousTest.php" as="Horde/Kolab/Session/Class/Decorator/AnonymousTest.php" />
<install name="test/Horde/Kolab/Session/Class/Decorator/LoggedTest.php" as="Horde/Kolab/Session/Class/Decorator/LoggedTest.php" />
+++ /dev/null
-<?php
-/**
- * Test the mock auth driver.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-
-/**
- * Prepare the test setup.
- */
-require_once dirname(__FILE__) . '/../../Autoload.php';
-
-/**
- * Test the mock auth driver.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package Kolab_Session
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Session
- */
-class Horde_Kolab_Session_Class_Auth_MockTest extends Horde_Kolab_Session_SessionTestCase
-{
- public function testMethodGetcurrentuserHasResultStringTheCurrentUser()
- {
- $auth = new Horde_Kolab_Session_Auth_Mock('test');
- $this->assertEquals('test', $auth->getAuth());
- }
-}
\ No newline at end of file
{
public function testMethodIsvalidHasResultBooleanTrueIfTheSessionIsNotConnectedAndTheCurrentUserIsAnonymous()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue(''));
+ $auth = false;
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->once())
->method('getMail')
public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->once())
->method('getMail')
public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('somebody@example.org'));
+ $auth = 'somebody@example.org';
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->once())
->method('getMail')
public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->once())
->method('getMail')
public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->once())
->method('getMail')
public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesEitherTheCurrentUserMailAndUid()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->once())
->method('getMail')
public function testMethodIsvalidHasPostconditionThatAnInvalidSessionGetsLogged()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->exactly(2))
- ->method('getAuth')
- ->will($this->returnValue('auth@example.org'));
+ $auth = 'auth@example.org';
$session = $this->getMock('Horde_Kolab_Session');
$session->expects($this->exactly(2))
->method('getMail')
public function testMethodIsvalidHasResultBooleanTrueIfTheSessionIsNotConnectedAndTheCurrentUserIsAnonymous()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue(''));
+ $auth = false;
$composite = $this->_getMockedComposite();
$session = new Horde_Kolab_Session_Base(
$composite, array()
public function testMethodIsvalidHasResultBooleanFalseIfTheSessionIsNotConnected()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$composite = $this->_getMockedComposite();
$session = new Horde_Kolab_Session_Base(
$composite, array()
public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserDoesNotMatchTheCurrentUserOfTheSession()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('somebody@example.org'));
+ $auth = 'somebody@example.org';
$this->user->expects($this->exactly(5))
->method('getSingle')
->will($this->returnValue('mail@example.org'));
public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndNoNewUserWasSet()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$this->user->expects($this->exactly(5))
->method('getSingle')
->will($this->returnValue('mail@example.org'));
public function testMethodIsvalidHasResultBooleanFalseIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesNeitherTheCurrentUserMailAndUid()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$this->user->expects($this->exactly(5))
->method('getSingle')
->will($this->returnValue('mail@example.org'));
public function testMethodIsvalidHasResultBooleanTrueIfTheMailOfTheCurrentUserMatchesTheCurrentUserOfTheSessionAndTheNewUserMatchesEitherTheCurrentUserMailAndUid()
{
- $auth = $this->getMock('Horde_Interfaces_Registry_Auth');
- $auth->expects($this->once())
- ->method('getAuth')
- ->will($this->returnValue('mail@example.org'));
+ $auth = 'mail@example.org';
$this->user->expects($this->exactly(5))
->method('getSingle')
->will($this->returnValue('mail@example.org'));
protected function setupFactoryMocks()
{
$this->server = $this->_getMockedComposite();
- $this->session_auth = $this->getMock('Horde_Interfaces_Registry_Auth');
+ $this->session_auth = $this->getMock('Horde_Kolab_Session_Auth_Interface');
$this->session_storage = $this->getMock('Horde_Kolab_Session_Storage_Interface');
}
}
\ No newline at end of file