Set CreatedTimestamp
by zitrone@gmx-topmail.de
Hi,
i'm currently trying to migrate users from an old system to keycloak (3.1.0). Im using the java implementation of the keycloak admin api to create the accounts, building a UserRepresentation and sending it to realm.users().create(). Now i have the problem, that i want to migrate the creation date of the accounts from the old system. Although i can set the createdTimestamp for the userRepresentation, it will not be stored in keycloak. Instead the current time is set for the createdTimestamp. Is there a way to modify the createdTimestamp? I understand that this is something you usually dont want to happen, but during migration of already existing accounts, it would be kind of handy.
If there is no other way i have to use a custom attribute, storing the old creation date, but that means additional code to retrieve it.
Second question: What is the best way to iterate over all accounts in keycloak? Currently i'm using something like this:
Integer userCount = keyCloakClient.realm(realmname).users().count();
int processed = 0;
List<String> userIds = new ArrayList<>();
int fetchsize = 100;
while (processed < userCount) {
keyCloakClient
.realm(realmname)
.users()
.search("", processed, fetchsize)
.stream()
//some filters
.forEach(user -> userIds.add(user.getId()));
processed += fetchsize;
}
If i put the fetchsize to big, i get problems processing the json response. But i'm worried that the result from the empty search will not be stable and i'll miss accounts.
regards
zitrone