1: <?php
2: /**
3: * The Horde_Kolab_Session_Anonymous class allows anonymous access to the Kolab
4: * system.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_Session
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_Session
13: */
14:
15: /**
16: * The Horde_Kolab_Session_Anonymous class allows anonymous access to the Kolab
17: * system.
18: *
19: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Kolab
25: * @package Kolab_Session
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Kolab_Session
29: */
30: class Horde_Kolab_Session_Decorator_Anonymous
31: extends Horde_Kolab_Session_Decorator_Base
32: {
33: /**
34: * Anonymous user ID.
35: *
36: * @var string
37: */
38: private $_anonymous_id;
39:
40: /**
41: * Anonymous password.
42: *
43: * @var string
44: */
45: private $_anonymous_pass;
46:
47: /**
48: * Constructor.
49: *
50: * @param Horde_Kolab_Session $session The this instance should provide
51: * anonymous access for.
52: * @param string $user ID of the anonymous user.
53: * @param string $pass Password of the anonymous user.
54: */
55: public function __construct(Horde_Kolab_Session $session, $user, $pass)
56: {
57: parent::__construct($session);
58: $this->_anonymous_id = $user;
59: $this->_anonymous_pass = $pass;
60: }
61:
62: /**
63: * Try to connect the session handler.
64: *
65: * @param string $user_id The user ID to connect with.
66: * @param array $credentials An array of login credentials. For Kolab,
67: * this must contain a "password" entry.
68: *
69: * @return NULL
70: *
71: * @throws Horde_Kolab_Session_Exception If the connection failed.
72: */
73: public function connect($user_id = null, array $credentials = null)
74: {
75: if ($user_id === null && $credentials === null) {
76: $this->_session->connect($this->_anonymous_id, array('password' => $this->_anonymous_pass));
77: } else {
78: $this->_session->connect($user_id, $credentials);
79: }
80: }
81:
82: /**
83: * Return the user id used for connecting the session.
84: *
85: * @return string The user id.
86: */
87: public function getId()
88: {
89: $id = $this->_session->getId();
90: if ($id == $this->_anonymous_id) {
91: return null;
92: }
93: return $id;
94: }
95: }
96: