1: <?php
2: /**
3: * Logs access to the export system.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_FreeBusy
9: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
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_FreeBusy
13: */
14:
15: /**
16: * Logs access to the export system.
17: *
18: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
19: *
20: * See the enclosed file COPYING for license information (LGPL). If you did not
21: * receive this file, see
22: * http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Kolab
25: * @package Kolab_FreeBusy
26: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
27: * @author Gunnar Wrobel <wrobel@pardus.de>
28: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
29: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
30: * @since Horde 3.2
31: */
32: class Horde_Kolab_FreeBusy_User_Decorator_Log
33: implements Horde_Kolab_FreeBusy_User
34: {
35: /**
36: * The decorated user.
37: *
38: * @var Horde_Kolab_FreeBusy_User
39: */
40: private $_user;
41:
42: /**
43: * The logger.
44: *
45: * @var mixed
46: */
47: private $_logger;
48:
49: /**
50: * The remote .
51: *
52: * @var mixed
53: */
54: private $_remote;
55:
56: /**
57: * Constructor.
58: *
59: * @param Horde_Kolab_FreeBusy_User $user The decorated user.
60: * @param Horde_Controller_Request $request The request.
61: * @param mixed $logger The log handler. The class must
62: * at least provide the notice()
63: * and err() methods.
64: */
65: public function __construct(
66: Horde_Kolab_FreeBusy_User $user,
67: Horde_Controller_Request $request,
68: $logger
69: )
70: {
71: $this->_user = $user;
72: $this->_logger = $logger;
73: $vars = $request->getServerVars();
74: $this->_remote = isset($vars['REMOTE_ADDR']) ? $vars['REMOTE_ADDR'] : 'unknown';
75: }
76:
77: /**
78: * Return the primary id of the user accessing the system.
79: *
80: * @return string The primary id.
81: */
82: public function getPrimaryId()
83: {
84: return $this->_user->getPrimaryId();
85: }
86:
87: /**
88: * Return the password of the user accessing the system.
89: *
90: * @return string The password.
91: */
92: public function getPassword()
93: {
94: return $this->_user->getPassword();
95: }
96:
97: /**
98: * Return the primary domain of the user accessing the system.
99: *
100: * @return string The primary domain.
101: */
102: public function getDomain()
103: {
104: return $this->_user->getDomain();
105: }
106:
107: /**
108: * Return the groups this user is member of.
109: *
110: * @return array The groups for this user.
111: */
112: public function getGroups()
113: {
114: return $this->_user->getGroups();
115: }
116:
117:
118: /**
119: * Finds out if a set of login credentials are valid.
120: *
121: * @return boolean Whether or not the password was correct.
122: */
123: public function isAuthenticated()
124: {
125: $result = $this->_user->isAuthenticated();
126: $id = $this->_user->getPrimaryId();
127: if ($result) {
128: $this->_logger->notice(
129: sprintf(
130: 'Login success for "%s" from "%s" to free/busy.',
131: $id,
132: $this->_remote
133: )
134: );
135: } else {
136: if (!empty($id)) {
137: $this->_logger->err(
138: sprintf(
139: 'Failed login for "%s" from "%s" to free/busy',
140: $id,
141: $this->_remote
142: )
143: );
144: } else {
145: $this->_logger->notice(
146: sprintf(
147: 'Anonymous access from "%s" to free/busy.',
148: $this->_remote
149: )
150: );
151: }
152: }
153: return $result;
154: }
155: }