fix(auth): move SecureRandom out of static field for native-image compat
CI / Build Native (push) Successful in 7m25s

GraalVM native-image rejects static fields of type Random/SecureRandom
(their internal state is captured at build time and can't be replayed
deterministically). Move the instance into generatePassword() as a
local variable - it is only used once at startup anyway.
This commit is contained in:
2026-08-14 22:16:36 -04:00
parent a171943f98
commit 6a7f01289b
@@ -21,7 +21,6 @@ import java.security.SecureRandom;
public class BootstrapAdmin { public class BootstrapAdmin {
private static final Logger LOG = Logger.getLogger(BootstrapAdmin.class); private static final Logger LOG = Logger.getLogger(BootstrapAdmin.class);
private static final SecureRandom RANDOM = new SecureRandom();
// Alfabeto sin chars ambiguos (0/o/O, 1/l/I) para no cansar al tipear. // Alfabeto sin chars ambiguos (0/o/O, 1/l/I) para no cansar al tipear.
private static final char[] ALPHABET = private static final char[] ALPHABET =
"ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz".toCharArray(); "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz".toCharArray();
@@ -61,9 +60,12 @@ public class BootstrapAdmin {
} }
private static String generatePassword() { private static String generatePassword() {
// Local para evitar un campo estático (GraalVM native-image no permite
// instancias de Random/SecureRandom en el image heap; las crea en runtime).
SecureRandom random = new SecureRandom();
StringBuilder sb = new StringBuilder(PASSWORD_LENGTH); StringBuilder sb = new StringBuilder(PASSWORD_LENGTH);
for (int i = 0; i < PASSWORD_LENGTH; i++) { for (int i = 0; i < PASSWORD_LENGTH; i++) {
sb.append(ALPHABET[RANDOM.nextInt(ALPHABET.length)]); sb.append(ALPHABET[random.nextInt(ALPHABET.length)]);
} }
return sb.toString(); return sb.toString();
} }