1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the tiqr project. |
4
|
|
|
* |
5
|
|
|
* The tiqr project aims to provide an open implementation for |
6
|
|
|
* authentication using mobile devices. It was initiated by |
7
|
|
|
* SURFnet and developed by Egeniq. |
8
|
|
|
* |
9
|
|
|
* More information: http://www.tiqr.org |
10
|
|
|
* |
11
|
|
|
* @author Ivo Jansch <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @package tiqr |
14
|
|
|
* |
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
16
|
|
|
* |
17
|
|
|
* @copyright (C) 2010-2012 SURFnet BV |
18
|
|
|
*/ |
19
|
|
|
|
20
|
1 |
|
require_once 'Tiqr/UserStorage/Abstract.php'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This user storage implementation implements a simple user storage using json files. |
24
|
|
|
* This is mostly for demonstration and development purposes. In a production environment |
25
|
|
|
* please supply your own implementation that hosts the data in your user database OR |
26
|
|
|
* in a secure (e.g. hardware encrypted) storage. |
27
|
|
|
* @author ivo |
28
|
|
|
*/ |
29
|
|
|
abstract class Tiqr_UserStorage_GenericStore extends Tiqr_UserStorage_Abstract |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
abstract protected function _loadUser($userId, $failOnNotFound = TRUE); |
33
|
|
|
|
34
|
|
|
abstract protected function _saveUser($userId, $data); |
35
|
|
|
|
36
|
|
|
abstract protected function _deleteUser($userId); |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* (non-PHPdoc) |
41
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::createUser() |
42
|
|
|
*/ |
43
|
1 |
|
public function createUser($userId, $displayName) |
44
|
|
|
{ |
45
|
1 |
|
$user = array("userId"=>$userId, |
46
|
1 |
|
"displayName"=>$displayName); |
47
|
1 |
|
return $this->_saveUser($userId, $user); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* (non-PHPdoc) |
52
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::userExists() |
53
|
|
|
*/ |
54
|
1 |
|
public function userExists($userId) |
55
|
|
|
{ |
56
|
1 |
|
$user = $this->_loadUser($userId, FALSE); |
57
|
1 |
|
return (is_array($user)||is_object($user)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* (non-PHPdoc) |
62
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::getDisplayName() |
63
|
|
|
*/ |
64
|
1 |
|
public function getDisplayName($userId) |
65
|
|
|
{ |
66
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
67
|
1 |
|
return $data["displayName"]; |
68
|
|
|
} |
69
|
|
|
return NULL; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* (non-PHPdoc) |
74
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::getNotificationType() |
75
|
|
|
*/ |
76
|
1 |
|
public function getNotificationType($userId) |
77
|
|
|
{ |
78
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
79
|
1 |
|
if (isset($data["notificationType"])) { |
80
|
1 |
|
return $data["notificationType"]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
1 |
|
return NULL; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* (non-PHPdoc) |
88
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::setNotificationType() |
89
|
|
|
*/ |
90
|
1 |
|
public function setNotificationType($userId, $type) |
91
|
|
|
{ |
92
|
1 |
|
$data = $this->_loadUser($userId); |
93
|
1 |
|
$data["notificationType"] = $type; |
94
|
1 |
|
$this->_saveUser($userId, $data); |
95
|
1 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* (non-PHPdoc) |
99
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::getNotificationAddress() |
100
|
|
|
*/ |
101
|
1 |
|
public function getNotificationAddress($userId) |
102
|
|
|
{ |
103
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
104
|
1 |
|
if (isset($data["notificationAddress"])) { |
105
|
|
|
return $data["notificationAddress"]; |
106
|
|
|
} |
107
|
|
|
} |
108
|
1 |
|
$this->logger->info('Unable to find notification address for user'); |
109
|
1 |
|
return NULL; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* (non-PHPdoc) |
114
|
|
|
* @see simplesamlphp/modules/authTiqr/lib/User/sspmod_authTiqr_User_Interface::setNotificationAddress() |
115
|
|
|
*/ |
116
|
|
|
public function setNotificationAddress($userId, $address) |
117
|
|
|
{ |
118
|
|
|
$data = $this->_loadUser($userId); |
119
|
|
|
$data["notificationAddress"] = $address; |
120
|
|
|
$this->_saveUser($userId, $data); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* (non-PHPdoc) |
125
|
|
|
* @see simplesamlphp-module/authTiqr/lib/User/sspmod_authTiqr_User_Interface::getFailedLoginAttempts() |
126
|
|
|
*/ |
127
|
1 |
|
public function getLoginAttempts($userId) |
128
|
|
|
{ |
129
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
130
|
1 |
|
if (isset($data["loginattempts"])) { |
131
|
1 |
|
return $data["loginattempts"]; |
132
|
|
|
} |
133
|
|
|
} |
134
|
1 |
|
return 0; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* (non-PHPdoc) |
139
|
|
|
* @see simplesamlphp-module/authTiqr/lib/User/sspmod_authTiqr_User_Interface::setFailedLoginAttempts() |
140
|
|
|
*/ |
141
|
1 |
|
public function setLoginAttempts($userId, $amount) |
142
|
|
|
{ |
143
|
1 |
|
$data = $this->_loadUser($userId); |
144
|
1 |
|
$data["loginattempts"] = $amount; |
145
|
1 |
|
$this->_saveUser($userId, $data); |
146
|
1 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* (non-PHPdoc) |
150
|
|
|
* @see simplesamlphp-module/authTiqr/lib/User/sspmod_authTiqr_User_Interface::isBlocked() |
151
|
|
|
*/ |
152
|
1 |
|
public function isBlocked($userId, $duration) |
153
|
|
|
{ |
154
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
155
|
1 |
|
$timestamp = $this->getTemporaryBlockTimestamp($userId); |
156
|
|
|
// if not blocked or block is expired, return false |
157
|
1 |
|
if (!isset($data["blocked"]) || $data["blocked"]==false || (false !== $timestamp && false != $duration && (strtotime($timestamp) + $duration * 60) < time())) { |
158
|
1 |
|
return false; |
159
|
|
|
} |
160
|
|
|
} |
161
|
1 |
|
return true; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* (non-PHPdoc) |
166
|
|
|
* @see libTiqr/library/tiqr/Tiqr/UserStorage/Tiqr_UserStorage_Interface::setTemporaryBlockAttempts() |
167
|
|
|
*/ |
168
|
1 |
|
public function setTemporaryBlockAttempts($userId, $amount) { |
169
|
1 |
|
$data = $this->_loadUser($userId); |
170
|
1 |
|
$data["temporaryBlockAttempts"] = $amount; |
171
|
1 |
|
$this->_saveUser($userId, $data); |
172
|
1 |
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* (non-PHPdoc) |
176
|
|
|
* @see libTiqr/library/tiqr/Tiqr/UserStorage/Tiqr_UserStorage_Interface::getTemporaryBlockAttempts() |
177
|
|
|
*/ |
178
|
1 |
|
public function getTemporaryBlockAttempts($userId) { |
179
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
180
|
1 |
|
if (isset($data["temporaryBlockAttempts"])) { |
181
|
1 |
|
return $data["temporaryBlockAttempts"]; |
182
|
|
|
} |
183
|
|
|
} |
184
|
1 |
|
return 0; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* (non-PHPdoc) |
189
|
|
|
* @see libTiqr/library/tiqr/Tiqr/UserStorage/Tiqr_UserStorage_Interface::setTemporaryBlockTimestamp() |
190
|
|
|
*/ |
191
|
1 |
|
public function setTemporaryBlockTimestamp($userId, $timestamp) { |
192
|
1 |
|
$data = $this->_loadUser($userId); |
193
|
1 |
|
$data["temporaryBlockTimestamp"] = $timestamp; |
194
|
1 |
|
$this->_saveUser($userId, $data); |
195
|
1 |
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* (non-PHPdoc) |
199
|
|
|
* @see libTiqr/library/tiqr/Tiqr/UserStorage/Tiqr_UserStorage_Interface::getTemporaryBlockTimestamp() |
200
|
|
|
*/ |
201
|
1 |
|
public function getTemporaryBlockTimestamp($userId) { |
202
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
203
|
1 |
|
if (isset($data["temporaryBlockTimestamp"])) { |
204
|
1 |
|
return $data["temporaryBlockTimestamp"]; |
205
|
|
|
} |
206
|
|
|
} |
207
|
1 |
|
return false; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* (non-PHPdoc) |
212
|
|
|
* @see simplesamlphp-module/authTiqr/lib/User/sspmod_authTiqr_User_Interface::block() |
213
|
|
|
*/ |
214
|
1 |
|
public function setBlocked($userId, $blocked) |
215
|
|
|
{ |
216
|
1 |
|
$data = $this->_loadUser($userId); |
217
|
1 |
|
$data["blocked"] = $blocked; |
218
|
1 |
|
$this->_saveUser($userId, $data); |
219
|
1 |
|
} |
220
|
|
|
|
221
|
|
|
} |
222
|
|
|
|