debug(auth): trace de login en AuthService + SQL log en app props
CI / Build Native (push) Failing after 1m19s
CI / Build Native (push) Failing after 1m19s
Para diagnosticar por qué el login devuelve 401 con la password correcta del bootstrap admin. Imprime: - username/pw.length al entrar - si la busqueda del user en la DB da null - hash.len y hash.prefix para confirmar que el user esta bien almacenado - bcrypt.matches(true/false) Tambien activamos quarkus.hibernate-orm.log.sql=true y quarkus.log.category.'com.l2.shots.auth'.level=DEBUG.
This commit is contained in:
@@ -12,3 +12,4 @@ src/frontend/tsconfig.node.tsbuildinfo
|
||||
*.iml
|
||||
.DS_Store
|
||||
*.log
|
||||
build-output/
|
||||
|
||||
@@ -67,9 +67,17 @@ public class AuthService {
|
||||
@Transactional
|
||||
public Optional<User> authenticate(String username, String password) {
|
||||
if (username == null || password == null) return Optional.empty();
|
||||
User user = User.findByUsernameCaseInsensitive(username.trim());
|
||||
if (user == null) return Optional.empty();
|
||||
if (!BcryptUtil.matches(password, user.passwordHash)) return Optional.empty();
|
||||
String trimmed = username.trim();
|
||||
LOG.infof("authenticate: username=%s trimmed=%s pw.len=%d", trimmed, trimmed, password.length());
|
||||
User user = User.findByUsernameCaseInsensitive(trimmed);
|
||||
if (user == null) {
|
||||
LOG.warnf("authenticate: user '%s' NOT FOUND in DB", trimmed);
|
||||
return Optional.empty();
|
||||
}
|
||||
LOG.infof("authenticate: found user id=%s hash.len=%d hash.prefix=%s", user.id, user.passwordHash == null ? -1 : user.passwordHash.length(), user.passwordHash == null ? "null" : user.passwordHash.substring(0, Math.min(7, user.passwordHash.length())));
|
||||
boolean matches = BcryptUtil.matches(password, user.passwordHash);
|
||||
LOG.infof("authenticate: bcrypt.matches=%s for user=%s", matches, trimmed);
|
||||
if (!matches) return Optional.empty();
|
||||
user.lastLoginAt = Instant.now();
|
||||
user.persist();
|
||||
return Optional.of(user);
|
||||
|
||||
Reference in New Issue
Block a user