forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add null checks after retrieving user from LDAP for validation to pre…
…vent NPE when user is removed in LDAP. Closes keycloak#28523 Signed-off-by: Stefan Guilhen <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -324,4 324,31 @@ public void loginLDAPUserCredentialVaultAuthenticationNoneEncryptionStartTLS() { | |
verifyConnectionUrlProtocolPrefix("ldap://"); | ||
runLDAPLoginTest(); | ||
} | ||
|
||
// Check that login fails as expected when an LDAP user that has already authenticated is removed from LDAP and attempts to authenticate again. | ||
// See https://github.com/keycloak/keycloak/issues/28523 | ||
@Test | ||
@LDAPConnectionParameters(bindType=LDAPConnectionParameters.BindType.SIMPLE, encryption=LDAPConnectionParameters.Encryption.NONE) | ||
public void loginLDAPUserAuthenticationSimpleDeleteLDAPUser() { | ||
// create another user for this test. | ||
getTestingClient().server().run(session -> { | ||
LDAPTestContext ctx = LDAPTestContext.init(session); | ||
RealmModel appRealm = ctx.getRealm(); | ||
LDAPObject jane = LDAPTestUtils.addLDAPUser(ctx.getLdapProvider(), appRealm, "janedoe", "Jane", | ||
"Doe", "[email protected]", "2nd Avenue", "09283"); | ||
LDAPTestUtils.updateLDAPPassword(ctx.getLdapProvider(), jane, DEFAULT_TEST_USERS.get("VALID_USER_PASSWORD")); | ||
}); | ||
// login with the new user, then logout - user is now cached in Keycloak. | ||
this.verifyLoginSucceededAndLogout("janedoe", DEFAULT_TEST_USERS.get("VALID_USER_PASSWORD")); | ||
|
||
// now remove the user directly in LDAP. | ||
getTestingClient().server().run(session -> { | ||
LDAPTestContext ctx = LDAPTestContext.init(session); | ||
RealmModel appRealm = ctx.getRealm(); | ||
LDAPTestUtils.removeLDAPUserByUsername(ctx.getLdapProvider(), appRealm, ctx.getLdapProvider().getLdapIdentityStore().getConfig(), "janedoe"); | ||
}); | ||
|
||
// attempt to login again with the deleted user should fail with the proper message. | ||
this.verifyLoginFailed("janedoe", DEFAULT_TEST_USERS.get("VALID_USER_PASSWORD")); | ||
} | ||
} |