@Override
    public OneTimeTokenAccount update(final OneTimeTokenAccount account) {
        if (account.getId() < 0) {
            account.setId(RandomUtils.nextLong());
        }
        LOGGER.debug("Storing account [{}]", account);
        val entry = locateLdapEntryFor(account.getUsername());
        val ldapAttribute = Objects.requireNonNull(entry,
                () -> String.format("Unable to locate LDAP entry for %s", account.getUsername()))
            .getAttribute(ldapProperties.getAccountAttributeName());

        if (ldapAttribute == null || ldapAttribute.getStringValues().isEmpty()) {
            LOGGER.debug("Adding new account for LDAP entry [{}]", entry);
            updateAccount(account, entry);
        } else {
            val existingAccounts = ldapAttribute.getStringValues()
                .stream()
                .map(LdapGoogleAuthenticatorTokenCredentialRepository::mapFromJson)
                .filter(Objects::nonNull)
                .flatMap(List::stream)
                .map(this::decode)
                .collect(Collectors.toSet());
            val matchingAccount = existingAccounts.stream()
                .filter(acct -> acct.getId() == account.getId())
                .findFirst();
            matchingAccount.ifPresentOrElse(ac -> {
                ac.setValidationCode(account.getValidationCode());
                ac.setScratchCodes(account.getScratchCodes());
                ac.setSecretKey(account.getSecretKey());
                ac.setProperties(account.getProperties());
            }, () -> existingAccounts.add(account));

            val accountsToSave = existingAccounts.stream()
                .map(acct -> encode(account))
                .filter(Objects::nonNull)
                .map(acct -> mapToJson(CollectionUtils.wrapArrayList(acct)))
                .collect(Collectors.toSet());
            executeModifyOperation(accountsToSave, entry);
        }
        return account;
    }
This is {@link LdapGoogleAuthenticatorTokenCredentialRepository}.

@author Misagh Moayyed
@since 6.2.0
support/cas-server-support-gauth-ldap/src/main/java/org/apereo/cas/gauth/credential/LdapGoogleAuthenticatorTokenCredentialRepository.java