Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PasswordPoliciesHookHandler
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onPasswordPoliciesForUser
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
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
21namespace MediaWiki\Extension\CentralAuth\Hooks\Handlers;
22
23use Exception;
24use MediaWiki\Config\Config;
25use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
26use MediaWiki\Hook\PasswordPoliciesForUserHook;
27use MediaWiki\User\User;
28use UserPasswordPolicy;
29
30class PasswordPoliciesHookHandler implements
31    PasswordPoliciesForUserHook
32{
33    /** @var Config */
34    private $config;
35
36    /**
37     * @param Config $config
38     */
39    public function __construct( Config $config ) {
40        $this->config = $config;
41    }
42
43    /**
44     * Apply global password policies when calculating the effective policy for
45     * a user.
46     * @param User $user
47     * @param array &$effectivePolicy
48     * @return bool
49     * @throws Exception
50     */
51    public function onPasswordPoliciesForUser( $user, &$effectivePolicy ) {
52        $central = CentralAuthUser::getInstance( $user );
53
54        if ( $central->exists() ) {
55            $localPolicyGroups = array_intersect(
56                array_keys( $this->config->get( 'CentralAuthGlobalPasswordPolicies' ) ),
57                $central->getLocalGroups()
58            );
59
60            $effectivePolicy = UserPasswordPolicy::getPoliciesForGroups(
61                $this->config->get( 'CentralAuthGlobalPasswordPolicies' ),
62                array_merge( $central->getGlobalGroups(), $localPolicyGroups ),
63                $effectivePolicy
64            );
65        }
66        return true;
67    }
68}