Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ protected AuthenticationSessionModel createAuthenticationSession(ClientModel cli
if (user != null && !user.isEnabled()) {
authSession = createNewAuthenticationSession(manager, client);

logger.error("DEBUG: Executing line 193 - backchannelLogout for disabled user");
AuthenticationManager.backchannelLogout(session, userSession, true);
throw new RuntimeException("HIT_LINE_193");
} else {
String userSessionId = userSession.getId();
rootAuthSession = session.authenticationSessions().getRootAuthenticationSession(realm, userSessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,46 @@ public void testLogoutDifferentBrowserWithAuthenticationSessionStillPresent() th
}
}

@Test
public void testLogoutInAnotherTabIfUserIsDisabled() {
try (BrowserTabUtil util = BrowserTabUtil.getInstanceAndSetEnv(driver)) {
// Given
String username = "disabled-test";
UserRepresentation disabledUser = UserBuilder.create()
.username(username)
.email(String.format("%[email protected]", username))
.enabled(true)
.build();
var disabledUserId = ApiUtil.createUserAndResetPasswordWithAdminClient(testRealm(), disabledUser, generatePassword(username), false);
getCleanup().addUserId(disabledUserId);
// User is enabled, User can Login
oauth.openLoginForm();
String tab1WindowHandle = util.getActualWindowHandle();
loginPage.login(username, getPassword(username));
appPage.assertCurrent();
String code = oauth.parseLoginResponse().getCode();
AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code);
AccessToken accessToken = oauth.verifyToken(tokenResponse.getAccessToken());
// User is successfully authenticated

// Admin API disables User (could be any other method)
UserRepresentation user = ApiUtil.findUserByUsername(testRealm(), username);
user.setEnabled(false);
testRealm().users().get(user.getId()).update(user);
events.clear();

// seamless login in the second tab, user already authenticated
util.newTab(oauth.loginForm().build());
oauth.openLoginForm();

assertThat(testRealm().users().get(user.getId()).getUserSessions(), Matchers.hasSize(0));
events.expect(EventType.LOGOUT)
.user(userId)
.session(accessToken.getSessionId())
.assertEvent();
}
}

private void waitForAppPage(Runnable htmlUnitAction) {
if (driver instanceof HtmlUnitDriver) {
// authChecker.js javascript does not work with HtmlUnitDriver. So need to "refresh" the current browser tab by running the last action in order to simulate "already_logged_in"
Expand Down
Loading