Skip to content

Commit

Permalink
Sanitise name according to Keycloak regex
Browse files Browse the repository at this point in the history
Signed-off-by: John Gomersall <[email protected]>
  • Loading branch information
john-gom committed Dec 20, 2024
1 parent 596c55e commit cbe3c94
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scripts/migrate_users_to_keycloak.pl
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ ($user_file, $anonymize)
my $credential
= $anonymize ? {} : convert_scrypt_password_to_keycloak_credentials($user_ref->{'encrypted_password'}) // {};
my $userid = $user_ref->{userid};
my $name = ($anonymize ? $userid : $user_ref->{name});
# Inverted expression from: https://github.com/keycloak/keycloak/blob/2eae68010877c6807b6a454c2d54e0d1852ed1c0/services/src/main/java/org/keycloak/userprofile/validator/PersonNameProhibitedCharactersValidator.java#L42C63-L42C114
$name =~ s/[<>&"$%!#?§;*~\/\\|^=\[\]{}()\x00-\x1F\x7F]+//g;

my $keycloak_user_ref = {
enabled => $JSON::PP::true,
username => $userid,
credentials => [$credential],
attributes => {
# Truncate name more than 255 because of UTF-8 encoding. Could do this more precisely...
name => substr(($anonymize ? $userid : $user_ref->{name}), 0, 128),
name => substr($name, 0, 128),
locale => $user_ref->{initial_lc},
country => $user_ref->{initial_cc},
registered => 'registered', # The prevents welcome emails from being sent
Expand Down

0 comments on commit cbe3c94

Please sign in to comment.