Skip to content
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

Initial Credentials Causes Update #819

Closed
dwyerk opened this issue Nov 28, 2022 · 1 comment · Fixed by #1213
Closed

Initial Credentials Causes Update #819

dwyerk opened this issue Nov 28, 2022 · 1 comment · Fixed by #1213
Assignees

Comments

@dwyerk
Copy link

dwyerk commented Nov 28, 2022

With #623 support for a new userLabel "initial" was added which prevents the credentials from being set if the user already exists. However, it can trigger a false update when only the password has changed.

This behavior can currently be seen in the ImportUsersIT.shouldUpdateRealmWithChangedClientUserPassword test. During the doImport call on line 189, the UserImportService will attempt to update the myinitialclientuser and this code will correctly add an empty list to the JSON:

            if (patchedUser.getCredentials() != null) {
                // do not override password, if userLabel is set "initial"
                List<CredentialRepresentation> userCredentials = patchedUser.getCredentials().stream()
                        .filter(credentialRepresentation -> !Objects.equals(
                                credentialRepresentation.getUserLabel(), USER_LABEL_FOR_INITIAL_CREDENTIAL
                        ))
                        .collect(Collectors.toList());
                patchedUser.setCredentials(userCredentials);
            }

However, the next condition will be true, and the service will try to update the user with keycloak:

            if (!CloneUtil.deepEquals(existingUser, patchedUser, "access")) {
                logger.debug("Update user '{}' in realm '{}'", userToImport.getUsername(), realmName);
                userRepository.updateUser(realmName, patchedUser);

But nothing has changed! The call to CloneUtil.deepEquals is returning true in this case but it should not.

This is a problem for those of us who want to use this feature to workaround the invalidpasswordhistorymessage issue where Keycloak won't accept keycloak-config-cli's update when there is a "Not Recently Used" password policy in place because it triggers an unnecessary update to the user which will fail.

@dwyerk
Copy link
Author

dwyerk commented Nov 28, 2022

Debugging into CloneUtils.deepEquals, we can see:

originJsonNode = {"id":"24c8403d-fe8b-4a10-b12d-85ea7279a495","createdTimestamp":1669679459001,"username":"myinitialclientuser","enabled":true,"totp":false,"emailVerified":false,"firstName":"My clientuser's firstname","lastName":"My clientuser's lastname","email":"[email protected]","disableableCredentialTypes":[],"requiredActions":[],"notBefore":0}

otherJsonNode = {"id":"24c8403d-fe8b-4a10-b12d-85ea7279a495","createdTimestamp":1669679459001,"username":"myinitialclientuser","enabled":true,"totp":false,"emailVerified":false,"firstName":"My clientuser's firstname","lastName":"My clientuser's lastname","email":"[email protected]","credentials":[],"disableableCredentialTypes":[],"requiredActions":[],"notBefore":0}

So the only difference is that patchedUser has "credentials":[] while existingUser does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

4 participants