1: <?php
2: /**
3: * A class to check if the given session is valid.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Session
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Session
12: */
13:
14: /**
15: * A class to check if the given session is valid.
16: *
17: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Session
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Session
27: */
28: class Horde_Kolab_Session_Valid_Base
29: implements Horde_Kolab_Session_Valid
30: {
31: /**
32: * The session handler this instance provides with anonymous access.
33: *
34: * @var Horde_Kolab_Session
35: */
36: private $_session;
37:
38: /**
39: * Provides authentication information for this object.
40: *
41: * @var mixed The user ID or false if no user is logged in.
42: */
43: private $_auth;
44:
45: /**
46: * Constructor.
47: *
48: * @param Horde_Kolab_Session $session The session that should be validated.
49: * @param mixed $auth The user ID or false if no user is
50: * logged in.
51: */
52: public function __construct(
53: Horde_Kolab_Session $session,
54: $auth
55: ) {
56: $this->_session = $session;
57: $this->_auth = $auth;
58: }
59:
60: /**
61: * Reset the current session information in case it does not match the
62: * authentication information anymore.
63: *
64: * @param string $user The user the session information is being requested
65: * for. This is usually empty, indicating the current
66: * user.
67: *
68: * @return boolean True if the session is still valid.
69: */
70: public function validate($user = null)
71: {
72: $mail = $this->_session->getMail();
73: if ($this->_auth != $mail) {
74: $this->_session->purge();
75: return false;
76: }
77: if (empty($user)) {
78: return true;
79: }
80: if ($user != $mail && $user != $this->_session->getUid()) {
81: $this->_session->purge();
82: return false;
83: }
84: return true;
85: }
86:
87: /**
88: * Return the session this validator checks.
89: *
90: * @return Horde_Kolab_Session The session checked by this
91: * validator.
92: */
93: public function getSession()
94: {
95: return $this->_session;
96: }
97:
98: /**
99: * Return the auth driver of this validator.
100: *
101: * @return mixed The user ID or false if no user is logged in.
102: */
103: public function getAuth()
104: {
105: return $this->_auth;
106: }
107: }