Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
|
100.00% |
15 / 15 |
CRAP | |
100.00% |
1 / 1 |
| AbstractPrimaryAuthenticationProvider | |
100.00% |
26 / 26 |
|
100.00% |
15 / 15 |
18 | |
100.00% |
1 / 1 |
| continuePrimaryAuthentication | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| postAuthentication | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| testUserCanAuthenticate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| providerNormalizeUsername | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| providerRevokeAccessForUser | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| providerAllowsPropertyChange | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| testForAccountCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| continuePrimaryAccountCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| finishAccountCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| postAccountCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| testUserForCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| autoCreatedAccount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| beginPrimaryAccountLink | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| continuePrimaryAccountLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| postAccountLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | /** |
| 10 | * A base class that implements some of the boilerplate for a PrimaryAuthenticationProvider |
| 11 | * |
| 12 | * @stable to extend |
| 13 | * @ingroup Auth |
| 14 | * @since 1.27 |
| 15 | */ |
| 16 | abstract class AbstractPrimaryAuthenticationProvider extends AbstractAuthenticationProvider |
| 17 | implements PrimaryAuthenticationProvider |
| 18 | { |
| 19 | |
| 20 | /** |
| 21 | * @stable to override |
| 22 | * |
| 23 | * @param array $reqs |
| 24 | * |
| 25 | * @return AuthenticationResponse|void |
| 26 | */ |
| 27 | public function continuePrimaryAuthentication( array $reqs ) { |
| 28 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 29 | throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @inheritDoc |
| 34 | * @stable to override |
| 35 | */ |
| 36 | public function postAuthentication( $user, AuthenticationResponse $response ) { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @inheritDoc |
| 41 | * @stable to override |
| 42 | */ |
| 43 | public function testUserCanAuthenticate( $username ) { |
| 44 | // Assume it can authenticate if it exists |
| 45 | return $this->testUserExists( $username ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @inheritDoc |
| 50 | * @stable to override |
| 51 | * @note Reimplement this if you do anything other than |
| 52 | * UserNameUtils->getCanonical( $req->username ) to determine the user being |
| 53 | * authenticated. |
| 54 | */ |
| 55 | public function providerNormalizeUsername( $username ) { |
| 56 | $name = $this->userNameUtils->getCanonical( $username ); |
| 57 | return $name === false ? null : $name; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @inheritDoc |
| 62 | * @stable to override |
| 63 | * @note Reimplement this if self::getAuthenticationRequests( AuthManager::ACTION_REMOVE ) |
| 64 | * doesn't return requests that will revoke all access for the user. |
| 65 | */ |
| 66 | public function providerRevokeAccessForUser( $username ) { |
| 67 | $reqs = $this->getAuthenticationRequests( |
| 68 | AuthManager::ACTION_REMOVE, [ 'username' => $username ] |
| 69 | ); |
| 70 | foreach ( $reqs as $req ) { |
| 71 | $req->username = $username; |
| 72 | $req->action = AuthManager::ACTION_REMOVE; |
| 73 | $this->providerChangeAuthenticationData( $req ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @inheritDoc |
| 79 | * @stable to override |
| 80 | */ |
| 81 | public function providerAllowsPropertyChange( $property ) { |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @inheritDoc |
| 87 | * @stable to override |
| 88 | */ |
| 89 | public function testForAccountCreation( $user, $creator, array $reqs ) { |
| 90 | return \StatusValue::newGood(); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @inheritDoc |
| 95 | * @stable to override |
| 96 | */ |
| 97 | public function continuePrimaryAccountCreation( $user, $creator, array $reqs ) { |
| 98 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 99 | throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @inheritDoc |
| 104 | * @stable to override |
| 105 | */ |
| 106 | public function finishAccountCreation( $user, $creator, AuthenticationResponse $response ) { |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @inheritDoc |
| 112 | * @stable to override |
| 113 | */ |
| 114 | public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) { |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @inheritDoc |
| 119 | * @stable to override |
| 120 | */ |
| 121 | public function testUserForCreation( $user, $autocreate, array $options = [] ) { |
| 122 | return \StatusValue::newGood(); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @inheritDoc |
| 127 | * @stable to override |
| 128 | */ |
| 129 | public function autoCreatedAccount( $user, $source ) { |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @inheritDoc |
| 134 | * @stable to override |
| 135 | */ |
| 136 | public function beginPrimaryAccountLink( $user, array $reqs ) { |
| 137 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 138 | if ( $this->accountCreationType() === self::TYPE_LINK ) { |
| 139 | throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' ); |
| 140 | } else { |
| 141 | throw new \BadMethodCallException( |
| 142 | __METHOD__ . ' should not be called on a non-link provider.' |
| 143 | ); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @inheritDoc |
| 149 | * @stable to override |
| 150 | */ |
| 151 | public function continuePrimaryAccountLink( $user, array $reqs ) { |
| 152 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 153 | throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' ); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @inheritDoc |
| 158 | * @stable to override |
| 159 | */ |
| 160 | public function postAccountLink( $user, AuthenticationResponse $response ) { |
| 161 | } |
| 162 | |
| 163 | } |