|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
|
|
4
|
|
|
* |
|
5
|
|
|
* @author Semih Serhat Karakaya |
|
6
|
|
|
* @copyright Copyright (c) 2016, ITU IT HEAD OFFICE. |
|
7
|
|
|
* @license AGPL-3.0 |
|
8
|
|
|
* |
|
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
11
|
|
|
* as published by the Free Software Foundation. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace OCA\Security; |
|
24
|
|
|
|
|
25
|
|
|
use OCP\IUser; |
|
26
|
|
|
use OCP\IUserManager; |
|
27
|
|
|
use OCP\IRequest; |
|
28
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
29
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class Hooks |
|
33
|
|
|
* @package OCA\Secuity\Lib |
|
34
|
|
|
*/ |
|
35
|
|
|
class Hooks { |
|
36
|
|
|
|
|
37
|
|
|
/** @var \OC\User\Manager */ |
|
38
|
|
|
private $userManager; |
|
39
|
|
|
|
|
40
|
|
|
/** @var Throttle*/ |
|
41
|
|
|
private $throttle; |
|
42
|
|
|
|
|
43
|
|
|
/** @var IRequest*/ |
|
44
|
|
|
private $request; |
|
45
|
|
|
|
|
46
|
|
|
/** @var PasswordValidator */ |
|
47
|
|
|
private $passValidator; |
|
48
|
|
|
/** @var EventDispatcherInterface */ |
|
49
|
|
|
private $dispatcher; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param IUserManager $userManager |
|
53
|
|
|
* @param Throttle $throttle |
|
54
|
|
|
* @param IRequest $request |
|
55
|
|
|
* @param PasswordValidator $passValidator |
|
56
|
|
|
* @param EventDispatcherInterface $dispatcher |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct($userManager, $throttle, $request, $passValidator, $dispatcher){ |
|
59
|
|
|
$this->userManager = $userManager; |
|
|
|
|
|
|
60
|
|
|
$this->throttle = $throttle; |
|
61
|
|
|
$this->request = $request; |
|
62
|
|
|
$this->passValidator = $passValidator; |
|
63
|
|
|
$this->dispatcher = $dispatcher; |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function register() { |
|
68
|
|
|
$this->userManager->listen('\OC\User', 'failedLogin', function($uid) { |
|
69
|
|
|
$this->failedLoginCallback($uid); |
|
70
|
|
|
}); |
|
71
|
|
|
|
|
72
|
|
|
$this->userManager->listen('\OC\User', 'postLogin', function($user) { |
|
73
|
|
|
$this->postLoginCallback($user); |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
$this->dispatcher->addListener('OCP\User::validatePassword', function(GenericEvent $event) { |
|
77
|
|
|
$this->passValidator->validate($event->getArgument('password')); |
|
78
|
|
|
}); |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $uid |
|
84
|
|
|
* @param Throttle $throttle |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
public function failedLoginCallback($uid) { |
|
87
|
|
|
$this->throttle->addFailedLoginAttempt($uid, $this->request->getRemoteAddress()); |
|
88
|
|
|
$this->throttle->putDelay($uid, $this->request->getRemoteAddress()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param IUser $user |
|
93
|
|
|
*/ |
|
94
|
|
|
public function postLoginCallback($user) { |
|
|
|
|
|
|
95
|
|
|
$this->throttle->clearSuspiciousAttemptsForIp($this->request->getRemoteAddress()); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..