Commit graph

40 commits

Author SHA1 Message Date
Alangi Derick
e907d4328d Use identical check instead of equality check
$user->getId() returns an int and it's strict on this,
so the check here should be an identical check as "=="
does unnecessary coercion. So "===" will be faster and
improves on speed/performance.

Change-Id: I28a4e86ab339f10251df8846b8d951b673fe4f9e
2018-10-31 13:22:58 +01:00
Kunal Mehta
1b521232a6 Include IP address in "Login for $1 succeeded" log entry
Bug: T207540
Change-Id: Iab4f2f2ddc8e64ead2f33356d03fa7beed399415
2018-10-20 13:02:32 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Brad Jorsch
ac0c80a6d6 AuthManager: Don't invalidate BotPasswords if a password reset email is sent
There's a difference between addition of credentials, which doesn't
need to invaliate BotPasswords, and changing or removal of credentials,
which does.

It seems most straightforward for the caller of
AuthManager::changeAuthenticationData() to know which is intended, so
let's add a flag there.

Bug: T199809
Change-Id: Ib8405734e605b94f3f0b66596ad95784cb365e4f
2018-07-17 16:25:28 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Brian Wolff
9d5a5b29d4 Better logging for reauth operations
Include username and IP address in log

Change-Id: I25c6d298e50876601ccd6a906eb7a7c65d2e8d87
2018-06-15 13:04:26 +00:00
Max Semenik
8085c58a4b Replace call_user_func_array(), part 1
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

Change-Id: Idcec077ef3fdf029b632cceafd0150851ad723e3
2018-06-04 23:39:04 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Bartosz Dziewoński
b191e5e860 Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.

It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.

* Replace a common pattern like `return $a < $b ? -1 : 1` with the
  new operator (and similar patterns with the variables, the numbers
  or the comparison inverted). Some of the uses were previously not
  correctly handling the variables being equal; this is now
  automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
  $a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
  when both variables are strings, but if any of the variables is not,
  'strcmp()' converts it to a string before comparison, which could
  give different results than '<=>', so changing this would require
  careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
  of the time (returns `1` if `$b` is lesser, and `0` if they are
  equal or `$a` is lesser) but is erroneous.

Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2018-05-30 18:05:20 -07:00
Aaron Schulz
6a8fcf56ae Avoid use of deprecated SiteStatsUpdate::__construct()
Change-Id: I9bf70fefe3ca146525e9b7cb436c9a577fb8eaee
2018-02-27 19:15:43 -08:00
Kunal Mehta
79de8fd02f Use wikimedia/object-factory 1.0.0
Deprecate the unnamespaced version and move it to includes/compat.

Bug: T147167
Depends-On: I39c805bfb98b32f32f3d0dc1eee9e823afe1c21a
Change-Id: I3780c7adf51683f3f7adb35a88f9a25a0a2e2530
2018-02-04 12:52:44 -08:00
WMDE-Fisch
a7872722b7 Replace deprecated wfGetLB() calls here and there
Change-Id: Ic7cec2dcc6b8e0d500a4c37eb134976b314c33ca
2018-01-20 19:24:24 +00:00
jenkins-bot
be80e2614c Merge "Consistent behavior of read-only reason" 2017-08-28 16:36:24 +00:00
Florian Schmidt
38fce189c4 Consistent behavior of read-only reason
Before this commit, the reason set in the global $wgReadOnly was differently handled
on different special pages. While on most of them, like Special:Upload, the reason
is allowed to have HTML, which can be used in Wikitext, too, Special:CreateAccount
always outputted an escaped version of this reason.

Most special pages uses the ReadOnlyError exception to print a read-only error,
however, AuthManager uses Status objects to communicate between the backend and the
frontend. Therefore the same message and parameters were wrapped in a Status object
and, in the frontend, directly passed to the constructor of ErrorPageError. Unfortunately,
Status::getMessage() escapes the parameters of a message, which is the reason, why the
wiki is read-only. To bypass this restriction, AuthManager now creates a Message object
directly, does not escape the reason, and uses the resulting object to create a Status
object from.

Now the reason is not escaped on Special:CreateAccount anymore, like on most other
special pages.

The read-only message on the protection form is, also before this commit, not escaped and
already displayed correctly, as the read-only is checked in the constructor of the
protection form already and, if the Wiki is read only, handled as a permission error and
already displayed correctly. This commit fixes the behavior of WikiPage in case of it's used
somewhere else, subclassed or if the check in the frontend will be removed and the Status of
WikiPage will be used.

Bug: T157036
Change-Id: Idbfe556fcb90f8bda8fae9d728ca9dee5ea02f67
2017-08-28 17:51:17 +02:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
Kunal Mehta
0944b7d39c AuthManager: Avoid deprecated wfMemcKey()
Change-Id: I254f9c057b8a151c593054dd4f2137586abf262a
2017-05-23 15:01:34 -07:00
addshore
b12086b618 Get ConfigFactory & MainConfig from MediaWikiServices
Change-Id: Iafdd7e00747060572463ffb05aae4543f3a06163
2016-11-23 00:12:38 +00:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Aaron Schulz
9a8c8ab98c Make TransactionProfiler::setSilenced() calls handle nesting
Change-Id: I6511a72a0fb921468a8a19ceb4d0a8ae669aa6e4
2016-10-12 18:14:03 -07:00
Gergő Tisza
cdcc2a0e3f Avoid 'message' in log context in AuthManager
Logstash merges the log context into the main metadata (where
'message' is the log message) and ends up overwriting the message.

Bug: T145133
Change-Id: I27f221b0f1f7203e93d1b92119dc584ba8526f5b
2016-10-04 00:24:42 +00:00
Gergő Tisza
4a92749554 Fix some PhpStorm warnings in AuthManager
Change-Id: Ib5fab7a54a6572897d9b679d6470d830cbb3cea9
2016-09-12 22:55:51 +00:00
Gergő Tisza
55572b08a6 Avoid user autocreation race condition caused by repeatable read
AuthManager tries to check whether the user already exists if
User::addToDatabase fails in autocreation, but since the same DB row
was already checked a few lines earlier and this method is typically
wrapped in an implicit transaction, it will just re-read the same
snapshot and not do anything useful. addToDatabase already has
a check for that so let's rely on that instead.

Bug: T145131
Change-Id: I94a5e8b851dcf994f5f9e773edf4e9153a4a3535
2016-09-08 17:14:15 -07:00
Aaron Schulz
16266edff3 Change "slave" => "replica DB" in /includes
Change-Id: Icb716219c9335ff8fa447b1733d04b71d9712bf9
2016-09-05 21:01:01 +00:00
Gergő Tisza
94e2aa7b55 Expand SessionManager / AuthManager documentation
Bug: T110628
Bug: T142154
Change-Id: Ib0a41f01b3d12267b2a94ea1375e6d13cacd2b69
2016-08-30 18:54:30 +00:00
jenkins-bot
c039c6c6b9 Merge "Revert "AuthManager: Commit transaction after auto-creating a user"" 2016-08-18 20:16:47 +00:00
Aaron Schulz
5d20db748c Revert "AuthManager: Commit transaction after auto-creating a user"
* 81be9512a022 should obviate the main desire for this.
  The normal commit step is now relied upon again.
* 820f5d6ce5 and a26fbb6705 enforce DBO_TRX transactions.
* Committing the implicit transaction(s) prematurely is bad
  for web request and cross-DB transactionality. Only code
  that has clear outermost DB context (e.g. jobs/maintenance)
  should be doing things like this as it becomes hard to reason
  about (e.g. how much the request/caller needs atomicity
  or whether there is an outer (start|end)Atomic section).

This reverts commit 83c66caa08.

Change-Id: I1a5533b239e53f2089f239651c6fdf97e51c9062
2016-08-18 19:36:25 +00:00
Gergő Tisza
d4de10750f AuthManager: do not rewrite PRIMARY_REQUIRED to REQUIRED
AuthManager::getAuthenticationRequests() changes
AuthenticationRequest::$required from REQUIRED to PRIMARY_REQUIRED
if the request is from a primary; it made an exception when
all primary providers returned a given request. That exception is
not particularly useful (AuthenticationRequest::mergeFieldInfo()
used to rely on it to determine which fields are required, but
since I9d33bd2 that's not really needed), and knowing which request
is from a primary is useful for other means.

This changes required field semantics in a corner case: when a
primary provider returns two required requests, the previous
behavior was to assume that they are both required; the new one
is to treat them as alternatives (as if they were returned by
two different providers). So when all primary providers return
request X, and one of them returns Y in addition, the fields of X
will not be marked required, while previously that would have been
the case.

Instead of overcomplicating the interface for something that is
unlikely to come up in any real use case, add a new requirement
to PrimaryAuthenticationProvider that it should not return
multiple required requests.

Bug: T141471
Change-Id: I1c1f44d4d6b66f77c876e3459fb97f03483db744
2016-08-17 05:51:53 +00:00
Aaron Schulz
0d8c851d79 Make autoCreateUser() transaction profiler suppression limited in scope
Change-Id: If7b2330aa8cdf49ae25e5c0af5cb3ffc3f40b257
2016-08-15 14:10:33 -07:00
Gergő Tisza
854a462dc0 Remove $wgDisableAuthManager
Change-Id: I2b2c9693a275fcc026916bd97f303e7a5c8df341
2016-08-09 23:00:27 +00:00
Brad Jorsch
83c66caa08 AuthManager: Commit transaction after auto-creating a user
As things stand now, DBO_TRX or DBO_DEFAULT will cause a transaction to
be started, and then anything in the entire request failing will
probably cause the newly-added user row to be lost. But updates to
external databases (e.g. CentralAuth) likely won't be since those DB
connections were probably shut down after the update was completed.

So let's explicitly commit changes af the end of auto-creation so that
problems with the request itself don't undo it.

Bug: T119736
Change-Id: I6c13c8feb86d8b9a01df894733c38445d048fea0
2016-07-12 13:35:10 -04:00
Brad Jorsch
cd763560c8 Add $options parameter for testUserForCreation()
This will allow providers to know whether the call is just for testing
(from ApiQueryUsers) or for actual creation, and skip duplicate work
when testForAccountCreation() is going to be called.

Change-Id: Id3ef713fd377135d78f66e5100dedd4689293b59
Depends-On: I4af8b3b692f60c42f8685b90be5936da7ba4e2e2
Depends-On: Ie9639a15d04b387be0e72754301eb6d91cd8adc2
Depends-On: I063cbdfbd9a223bf2391fce2b714ab82ddd3272f
Depends-On: I7c67512634f6e72251911238f083857da9fd3f84
2016-06-20 11:27:07 -04:00
Brad Jorsch
50fa154511 Don't try to use the context language when auto-creating
Most of the time the context language won't be ready yet, because it
needs the user we're auto-creating.

Bug: T124367
Change-Id: I0376647be33e81593101378217b37363125cfddf
2016-06-13 12:52:41 -04:00
Brad Jorsch
e2522e7e7e Don't override action in UI and REDIRECT responses
In Ic8caf57eb, we changed things so the requests returned in a UI or
REDIRECT response would have the action forced to that appropriate for
the action being peformed. But ResetPasswordSecondaryAuthenticationProvider
has a use case where a mismatch is necessary: it's run during the login
action, but it needs a PasswordAuthenticationResponse for a change
action.

Bug: T136894
Change-Id: I9d109a22c5b2d2064f664f584100ecaab43199c5
2016-06-03 11:37:29 -04:00
Brad Jorsch
50b6fb32fb AuthManager::setDefaultUserOptions and LoginForm::initUser shouldn't invalidate CA tokens
We only want to set the local user_token when we create the local
account. We don't want to invalidate all existing CentralAuth sessions
for the user just because they happened to visit a new wiki and get
an account auto-created.

This might also fix T136853. It looks like what's going on there is that
two jobs are both in this code path calling CentralAuth::resetAuthToken()
at the same time, leading to a race and one fails the CAS check.

Bug: T136834
Change-Id: I61b8253584a11a5b02f7ccb9efa0679cd2a822c6
2016-06-02 19:35:27 +00:00
jenkins-bot
218e89d5b4 Merge "AuthManager: Ensure neededRequests have action and username set properly" 2016-06-01 21:26:13 +00:00
Brad Jorsch
3e970169f6 Make AuthManager::getAuthenticationProvider() public
I found a need in CentralAuth to check that
CentralAuthPrimaryAuthenticationProvider is actually in use, so I'm
exposing this.

Change-Id: I40bd3dc4d05db0c3a34b01f550a9a9a1ded8fc61
2016-06-01 14:16:49 -04:00
Brad Jorsch
db521e5574 AuthManager: Ensure neededRequests have action and username set properly
They were coming out as null instead, which screws up when requests are
changing their fields based on the action.

Change-Id: Ic8caf57ebad35c3eb17d45f9d96c6de5b559a83a
2016-06-01 12:13:15 -04:00
Chad Horohoe
ca831d5f45 Reset all tokens on login
Bug: T122056
Change-Id: I03739e942b6c182ed9cbcd0d9615dcd799e8baed
2016-05-31 12:20:05 -07:00
Brad Jorsch
9bb2875e2e AuthManager fixups around the login→RESTART→create flow
* ApiQueryAuthManagerInfo will differentiate between preserved linking
  data and a preserved createRequest.
* ApiQueryAuthManagerInfo will indicate the preserved username, if any,
  because the client will have to pass that back to action=createaccount.
* ApiClientLogin won't tell about the confusing
  CreateFromLoginAuthenticationRequest returned on RESTART responses.
* Explain how 'preservestate' works in ApiAMCreateAccount's auto-doc.
* ConfirmLinkSecondaryAuthenticationProvider will filter out requests
  that can no longer be used (i.e. if it was for linking the account
  that got used for creation).
* All the complicated code in AuthManager::beginAccountCreation() was
  trying to deal with allowing the client to pass only the
  CreateFromLoginAuthenticationRequest. That was dumb, removed it.
* Added methods to CreateFromLoginAuthenticationRequest to indicate its
  status with respect to different kinds of preserved state.
* Increase accuracy of the AuthenticationResponse::$createRequest doc.

Change-Id: I726d79de18e739d6e60c1eea51453433c21ba207
2016-05-31 11:44:02 -04:00
Brad Jorsch
d245bd25ae Add AuthManager
This implements the AuthManager class and its needed interfaces and
subclasses, and integrates them into the backend portion of MediaWiki.
Integration with frontend portions of MediaWiki (e.g. ApiLogin,
Special:Login) is left for a followup.

Bug: T91699
Bug: T71589
Bug: T111299
Co-Authored-By: Gergő Tisza <gtisza@wikimedia.org>
Change-Id: If89d24838e326fe25fe867d02181eebcfbb0e196
2016-05-16 15:11:02 +00:00