-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor login to converge in the same function #40520
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
Need to check the following, having oauth2 and openidconnect apps active. It seems openidconnect triggers even though it's an oauth2 token.
|
Both are Bearer tokens - both modules are triggered. Generally speaking this is/was fine as these two modules learned to live together .... |
Are both modules expected to be enabled at the same time? If so, we should fix those errors because they happen periodically with the desktop client. Otherwise, we could treat it as incompatible apps so only one of them should be enabled. |
Things tested so far:
Not tested:
|
55cac82
to
989690d
Compare
Some additional changes in the code:
Other than that, the unit tests showed some code duplication in the token login flow (expected only one call in some methods, but currently calling them twice). No plans to fix it for the moment in order to limit the changes, but we should look it up at some point. |
I think this is ready to review. Taking into account this is mostly a refactor, I don't think we need a changelog entry. |
@@ -530,38 +534,12 @@ public function tryBasicAuthLogin(IRequest $request) { | |||
* compatibility. | |||
*/ | |||
private function loginWithPassword($login, $password) { | |||
$beforeEvent = new GenericEvent(null, ['loginType' => 'password', 'login' => $login, 'uid' => $login, '_uid' => 'deprecated: please use \'login\', the real uid is not yet known', 'password' => $password]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the order of events. Could have some side effects ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... applies to all refactored methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can try to use an "afterPreLogin" callback in the loginInOwnCloud
method in order to move the checks. It will add additional complexity though, and it looks bad to have to use callbacks in the same class.
I don't think we have better options. The code paths are quite different and I had trouble trying to funnel the code into one method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, the loginInOwnCloud
requires a user object. In this loginWithPassword
method, the user object comes from the checkPassword
method, not from the regular userManager->get(...)
. The userManager might not be able to find the user by login and rely on the checkPassword to get the user object (likely the case of LDAP).
This means that we'll have to use another callback (the second one) so the loginInOwnCloud
method gets the right user object.
Even if we don't use callbacks and use some kind of flag, the loginInOwnCloud
method will need to use more than one way to get the user object. We'll also need to inject code before getting the user object (for apache login) and after that (for cookie login).
So we need a flag to decide if we use the userManager's get
method or the checkPassword
, and we also need 2 callbacks to inject code before and after getting the user. It seems to much spaghetti
I think we'll have to take the risk of changing the behavior.... Currently the
In order to keep the previous behavior the method should do
So we need a flag because the Regarding the change in the behavior, I think it sums up to when the events are triggered. Previously, a pre-login event could be triggered followed by a failed-login event. The post-login event wouldn't trigger if a failed-login event happened. A wrong password attempt would trigger that event sequence. With the current code, the login events are triggered quite late. It would be rare that something goes wrong after the pre-login event. In case of disabled users, some previous code triggered a failed-login event while other not. For now, the PR doesn't trigger the event, but we might need to change this. I think this could be a good chance to homogenize the behavior with the events:
|
The only code using the preLogin event is in one code location and it blocks login of one specfic user. Let's move on 👍 |
CI Fails |
windows smb -> known |
Already re-triggered once, will retry again |
b9733ee
to
ad22b85
Compare
I rebased to trigger fresh CI - we can see if anything unexpected fails. |
ValidateSession will explicitly check if the user is disabled. Previously, the check was done in the validateToken method, but general check for the disabled user has been moved to the loginInOwncloud method, which requires login that won't happen in the validateSession method. Token will be invalidated if a LoginException happens. New info log added to notify the disabled user in the logs
ad22b85
to
4e42b45
Compare
I rebased again - CI should be green now. |
Kudos, SonarCloud Quality Gate passed! |
CI is green. I will merge this. Overnight we will get CI results of all nightly oC10 apps. That will help to know if there are any app-related side-effects. |
Description
Refactor login process so it ends going through the new
loginInOwnCloud
method.The new method will be perform the following:
Specific checks based on the auth mechanism (checking if the password is correct, or checking the expiration of the token) will be performed outside.
Additional changes brought in the PR:
loginInOwnCloud
method. This has caused some changes for some authentication methods about when the login events are triggered. This means that for some auth methods, the events will be triggered later and after some operations / checks have been performed. This might cause issues and will require verification.loginWithToken
, the token will be validated before trying to login with it. Previously, we logged in and then validated the token, so this might cause changes in the behaviorcreateSessionToken
will be called after a successful login. There were cases were this was called before login and others after login, so it's unclear when the session token should be created. This might need to be adjusted.preRememberedLogin
andpostRememberedLogin
events have been removed. These were additional events triggered by the "remember me" login which was broken until recently, so it's very unlikely they were used. Currently, the "remember me" login won't trigger any login event, but it might need to trigger the regular ones (prelogin and postlogin). They're currently being skipped.Known issues:
LoginFlowController
will call theloginUser
method without a module class. This will report the login type as empty instead of the expected openidconnect class name. There is nothing we can do without changing the app. This is harmless for this PR, but it will affect further functionality.Related Issue
Preparations for https://github.com/owncloud/enterprise/issues/5295
Motivation and Context
This is a preparation to bring new functionality. We need a centralized point where all login paths can converge.
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: