Repository navigation
Recover correct user session when auth session expired #55269
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,6 +349,11 @@ | |
| return this; | ||
| } | ||
|
|
||
| public RealmBuilder accessCodeLifespanLogin(int accessCodeLifespanLogin) { | ||
| rep.setAccessCodeLifespanLogin(accessCodeLifespanLogin); | ||
| return this; | ||
| } | ||
|
|
||
| public RealmBuilder actionTokenGeneratedByUserLifespan(int actionTokenGeneratedByUserLifespan) { | ||
| rep.setActionTokenGeneratedByUserLifespan(actionTokenGeneratedByUserLifespan); | ||
| return this; | ||
|
|
@@ -838,7 +843,7 @@ | |
| * @return this | ||
| * @deprecated | ||
| */ | ||
| public RealmBuilder update(RealmUpdate... update) { | ||
|
Check warning on line 846 in test-framework/builders/src/main/java/org/keycloak/testframework/realm/RealmBuilder.java
|
||
| Arrays.stream(update).forEach(u -> u.update(rep)); | ||
| return this; | ||
| } | ||
|
|
||
118 changes: 118 additions & 0 deletions
118
tests/base/src/test/java/org/keycloak/tests/forms/AuthCookieAndPasswordLoginTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package org.keycloak.tests.forms; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| import org.keycloak.authentication.authenticators.browser.CookieAuthenticatorFactory; | ||
| import org.keycloak.authentication.authenticators.browser.PasswordFormFactory; | ||
| import org.keycloak.authentication.authenticators.browser.UsernamePasswordFormFactory; | ||
| import org.keycloak.models.AuthenticationExecutionModel; | ||
| import org.keycloak.testframework.annotations.InjectRealm; | ||
| import org.keycloak.testframework.annotations.InjectUser; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.injection.LifeCycle; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.oauth.annotations.InjectOAuthClient; | ||
| import org.keycloak.testframework.realm.AuthenticationExecutionExportBuilder; | ||
| import org.keycloak.testframework.realm.AuthenticationFlowBuilder; | ||
| import org.keycloak.testframework.realm.ManagedRealm; | ||
| import org.keycloak.testframework.realm.ManagedUser; | ||
| import org.keycloak.testframework.realm.RealmBuilder; | ||
| import org.keycloak.testframework.realm.RealmConfig; | ||
| import org.keycloak.testframework.remote.providers.timeoffset.InfinispanTimeUtil; | ||
| import org.keycloak.testframework.remote.runonserver.InjectRunOnServer; | ||
| import org.keycloak.testframework.remote.runonserver.RunOnServerClient; | ||
| import org.keycloak.testframework.remote.timeoffset.InjectTimeOffSet; | ||
| import org.keycloak.testframework.remote.timeoffset.TimeOffSet; | ||
| import org.keycloak.testframework.ui.annotations.InjectPage; | ||
| import org.keycloak.testframework.ui.page.PasswordPage; | ||
| import org.keycloak.tests.common.BasicUserConfig; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * | ||
| * @author rmartinc | ||
| */ | ||
| @KeycloakIntegrationTest | ||
| public class AuthCookieAndPasswordLoginTest { | ||
|
|
||
| @InjectRealm(config = AuthCookieAndPasswordLoginRealmConfig.class) | ||
| ManagedRealm managedRealm; | ||
|
|
||
| @InjectUser(config = BasicUserConfig.class, lifecycle = LifeCycle.METHOD) | ||
| ManagedUser testUser; | ||
|
|
||
| @InjectOAuthClient | ||
| OAuthClient oauth; | ||
|
|
||
| @InjectPage | ||
| PasswordPage passwordPage; | ||
|
|
||
| @InjectTimeOffSet | ||
| TimeOffSet timeOffSet; | ||
|
|
||
| @InjectRunOnServer | ||
| RunOnServerClient runOnServer; | ||
|
|
||
| @Test | ||
| public void cookieAndPasswordLogin() throws Exception { | ||
| // login normally using the username and password page | ||
| oauth.doLogin(testUser.getUsername(), testUser.getPassword()); | ||
| Assertions.assertTrue(oauth.parseLoginResponse().isSuccess()); | ||
|
|
||
| // using cookie and password | ||
| oauth.openLoginForm(); | ||
| passwordPage.assertCurrent(); | ||
| Assertions.assertEquals(testUser.getUsername(), passwordPage.getAttemptedUsername()); | ||
| passwordPage.fillPassword(testUser.getPassword()); | ||
| passwordPage.submit(); | ||
| Assertions.assertTrue(oauth.parseLoginResponse().isSuccess()); | ||
|
|
||
| runOnServer.run(InfinispanTimeUtil.enableTestingTimeService()); | ||
| try { | ||
| // expire the login using 10 seconds for login | ||
| managedRealm.updateWithCleanup(r -> r.accessCodeLifespanUserAction(10).accessCodeLifespanLogin(10)); | ||
| oauth.openLoginForm(); | ||
| passwordPage.assertCurrent(); | ||
| Assertions.assertEquals(testUser.getUsername(), passwordPage.getAttemptedUsername()); | ||
| timeOffSet.set(Duration.ofSeconds(70)); | ||
| passwordPage.fillPassword(testUser.getPassword()); | ||
| passwordPage.submit(); | ||
| Assertions.assertEquals("Your login attempt timed out. Login will start from the beginning.", | ||
| passwordPage.getErrorMessage().orElse(null)); | ||
|
|
||
| // login again should success | ||
| passwordPage.fillPassword(testUser.getPassword()); | ||
| passwordPage.submit(); | ||
| Assertions.assertTrue(oauth.parseLoginResponse().isSuccess()); | ||
| } finally { | ||
| runOnServer.run(InfinispanTimeUtil.disableTestingTimeService()); | ||
| } | ||
| } | ||
|
|
||
| static class AuthCookieAndPasswordLoginRealmConfig implements RealmConfig { | ||
|
|
||
| @Override | ||
| public RealmBuilder configure(RealmBuilder realm) { | ||
| return realm.name("test").authenticationFlows( | ||
| AuthenticationFlowBuilder.create("step-cookie", "SSO auth-cookie flow", "basic-flow", false, false) | ||
| .authenticationExecutions( | ||
| AuthenticationExecutionExportBuilder.authenticator(CookieAuthenticatorFactory.PROVIDER_ID, | ||
| AuthenticationExecutionModel.Requirement.REQUIRED.name(), 10, false), | ||
| AuthenticationExecutionExportBuilder.authenticator(PasswordFormFactory.PROVIDER_ID, | ||
| AuthenticationExecutionModel.Requirement.REQUIRED.name(), 20, false)), | ||
| AuthenticationFlowBuilder.create("step-forms", "Username Password flow", "basic-flow", false, false) | ||
| .authenticationExecutions( | ||
| AuthenticationExecutionExportBuilder.authenticator(UsernamePasswordFormFactory.PROVIDER_ID, | ||
| AuthenticationExecutionModel.Requirement.REQUIRED.name(), 10, false)), | ||
| AuthenticationFlowBuilder.create("cookie-password-browser", "Cookie and password browser", "basic-flow", true, false) | ||
| .authenticationExecutions( | ||
| AuthenticationExecutionExportBuilder.alias("step-cookie", | ||
| AuthenticationExecutionModel.Requirement.ALTERNATIVE.name(), 10, false), | ||
| AuthenticationExecutionExportBuilder.alias("step-forms", | ||
| AuthenticationExecutionModel.Requirement.ALTERNATIVE.name(), 20, false))) | ||
| .browserFlow("cookie-password-browser"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.