Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PasswordPoliciesHookHandler | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onPasswordPoliciesForUser | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\Hooks\Handlers; |
22 | |
23 | use Exception; |
24 | use MediaWiki\Config\Config; |
25 | use MediaWiki\Extension\CentralAuth\Config\CAMainConfigNames; |
26 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
27 | use MediaWiki\Hook\PasswordPoliciesForUserHook; |
28 | use MediaWiki\Password\UserPasswordPolicy; |
29 | use MediaWiki\User\User; |
30 | |
31 | class PasswordPoliciesHookHandler implements PasswordPoliciesForUserHook { |
32 | |
33 | private Config $config; |
34 | |
35 | public function __construct( Config $config ) { |
36 | $this->config = $config; |
37 | } |
38 | |
39 | /** |
40 | * Apply global password policies when calculating the effective policy for |
41 | * a user. |
42 | * @param User $user |
43 | * @param array &$effectivePolicy |
44 | * @return bool |
45 | * @throws Exception |
46 | */ |
47 | public function onPasswordPoliciesForUser( $user, &$effectivePolicy ) { |
48 | $central = CentralAuthUser::getInstance( $user ); |
49 | |
50 | if ( $central->exists() ) { |
51 | $localPolicyGroups = array_intersect( |
52 | array_keys( $this->config->get( CAMainConfigNames::CentralAuthGlobalPasswordPolicies ) ), |
53 | $central->getLocalGroups() |
54 | ); |
55 | |
56 | $effectivePolicy = UserPasswordPolicy::getPoliciesForGroups( |
57 | $this->config->get( CAMainConfigNames::CentralAuthGlobalPasswordPolicies ), |
58 | array_merge( $central->getGlobalGroups(), $localPolicyGroups ), |
59 | $effectivePolicy |
60 | ); |
61 | } |
62 | return true; |
63 | } |
64 | } |