8000 Remove the non-atomic default implementations of the credential update methods by ahus1 · Pull Request #55078 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
13 changes: 13 additions & 0 deletions docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,16 @@ Communication between nodes is encrypted using TLS by default.
If you were using the `--cache-stack` option in your configuration, remove it.
To use a custom JGroups stack, configure it directly in your cache configuration XML file using the `--cache-config-file` option.
Remove any discovery settings specific to previously deprecated stacks, such as `jgroups.dns.query`.

=== Credential update methods without default implementation
// https://github.com/keycloak/keycloak/issues/55034

The default implementations of the following methods were removed, and the methods are now abstract:

* `SubjectCredentialManager.updateStoredCredential(CredentialModel oldCred, CredentialModel newCred)`
* `UserCredentialStore.updateCredential(RealmModel realm, UserModel user, CredentialModel oldCred, CredentialModel newCred)`
* `UserFederatedUserCredentialStore.updateCredential(RealmModel realm, String userId, CredentialModel oldCred, CredentialModel newCred)`

The removed default implementations were not atomic, and a credential that was changed concurrently could be overwritten.
Custom implementations of these interfaces must implement the methods.
They must replace the credential only if the stored credential still has the content of `oldCred`, return `false` otherwise, and perform the comparison and the update atomically, for example by locking the stored credential.
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,15 @@ public interface UserFederatedUserCredentialStore extends Provider {
/**
* Replaces a stored credential with a new version, but only if it still has the content of the old version.
* <p>
* Implementations should make the check and the replacement atomic, for example by locking the stored credential.
* The default implementation is not atomic, and a change that is committed between the check and the update can be lost.
* <p>
* The default implementation exists for backwards compatibility. It should be removed in the next major release,
* to force implementations to provide an atomic implementation.
* Implementations must make the check and the replacement atomic, for example by locking the stored credential.
*
* @param realm the realm
* @param userId the user id
* @param oldCred the credential as it was read, identified by its id
* @param newCred the credential to store instead
* @return {@code true} if the credential was replaced, {@code false} if it was changed or removed in the meantime
*/
default boolean updateCredential(RealmModel realm, String userId, CredentialModel oldCred, CredentialModel newCred) {
CredentialModel current = getStoredCredentialById(realm, userId, oldCred.getId());
if (current == null || !current.hasSameContent(oldCred)) {
return false;
}
updateCredential(realm, userId, newCred);
return true;
}
boolean updateCredential(RealmModel realm, String userId, CredentialModel oldCred, CredentialModel newCred);

CredentialModel createCredential(RealmModel realm, String userId, CredentialModel cred);
boolean removeStoredCredential(RealmModel realm, String userId, String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,15 @@ public interface UserCredentialStore extends Provider {
/**
* Replaces a stored credential with a new version, but only if it still has the content of the old version.
* <p>
* Implementations should make the check and the replacement atomic, for example by locking the stored credential.
* The default implementation is not atomic, and a change that is committed between the check and the update can be lost.
* <p>
* The default implementation exists for backwards compatibility. It should be removed in the next major release,
* to force implementations to provide an atomic implementation.
* Implementations must make the check and the replacement atomic, for example by locking the stored credential.
*
* @param realm the realm
* @param user the user
* @param oldCred the credential as it was read, identified by its id
* @param newCred the credential to store instead
* @return {@code true} if the credential was replaced, {@code false} if it was changed or removed in the meantime
*/
default boolean updateCredential(RealmModel realm, UserModel user, CredentialModel oldCred, CredentialModel newCred) {
CredentialModel current = getStoredCredentialById(realm, user, oldCred.getId());
if (current == null || !current.hasSameContent(oldCred)) {
return false;
}
updateCredential(realm, user, newCred);
return true;
}
boolean updateCredential(RealmModel realm, UserModel user, CredentialModel oldCred, CredentialModel newCred);

CredentialModel createCredential(RealmModel realm, UserModel user, CredentialModel cred);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,13 @@ default Optional<CredentialModel> updateCredentialAndGet(CredentialInput input)
* of the old version. Use this to update a credential that was read earlier, so that changes made in the meantime
* are not overwritten.
* <p>
* Implementations writing to the Keycloak credential store replace the credential atomically. The default
* implementation is not atomic, and a change that is committed between the check and the update can be lost.
* <p>
* The default implementation exists for backwards compatibility. It should be removed in the next major release,
* to force implementations to provide an atomic implementation.
* Implementations must make the check and the replacement atomic, for example by locking the stored credential.
*
* @param oldCred the credential as it was read, identified by its id
* @param newCred the credential to store instead
* @return {@code true} if the credential was replaced, {@code false} if it was changed or removed in the meantime
*/
default boolean updateStoredCredential(CredentialModel oldCred, CredentialModel newCred) {
CredentialModel current = getStoredCredentialById(oldCred.getId());
if (current == null || !current.hasSameContent(oldCred)) {
return false;
}
updateStoredCredential(newCred);
return true;
}
boolean updateStoredCredential(CredentialModel oldCred, CredentialModel newCred);

/**
* Updates a credential of the entity with an updated {@link CredentialModel}.
Expand Down
Loading
0