1: <?php
2: /**
3: * A logger for Horde_Kolab_Session_Valid validators.
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 logger for Horde_Kolab_Session_Valid validators.
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_Decorator_Logged
29: implements Horde_Kolab_Session_Valid
30: {
31: /**
32: * The valid handler.
33: *
34: * @var Horde_Kolab_Session_Valid_Interface
35: */
36: private $_valid;
37:
38: /**
39: * The logger.
40: *
41: * @var mixed
42: */
43: private $_logger;
44:
45: /**
46: * Constructor.
47: *
48: * The provided logger class needs to implement the methods info() and
49: * err().
50: *
51: * @param Horde_Kolab_Session_Valid_Interface $valid The validator.
52: * @param mixed $logger The logger instance.
53: */
54: public function __construct(Horde_Kolab_Session_Valid $valid, $logger)
55: {
56: $this->_valid = $valid;
57: $this->_logger = $logger;
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: $this->_logger->info(
73: sprintf(
74: "Validating Kolab session for current user \"%s\", requested user \"%s\", and stored user \"%s\".",
75: $this->_valid->getAuth(),
76: $user,
77: $this->_valid->getSession()->getMail()
78: )
79: );
80: $result = $this->_valid->validate($user);
81: if ($result === false) {
82: $this->_logger->info(
83: sprintf(
84: "Invalid Kolab session for current user \"%s\" and requested user \"%s\".",
85: $this->_valid->getAuth(),
86: $user
87: )
88: );
89: }
90: return $result;
91: }
92:
93: /**
94: * Return the session this validator checks.
95: *
96: * @return Horde_Kolab_Session The session checked by this
97: * validator.
98: */
99: public function getSession()
100: {
101: return $this->_valid->getSession();
102: }
103:
104: /**
105: * Return the auth driver of this validator.
106: *
107: * @return mixed The user ID or false if no user is logged in.
108: */
109: public function getAuth()
110: {
111: return $this->_valid->getAuth();
112: }
113: }
114: