{"record":{"id":"0678c4446ff2fa8c","repo":"quarkusio/quarkus","slug":"authenticationfailedexception-0678c4","errorCode":null,"errorMessage":"AuthenticationFailedException","messagePattern":"AuthenticationFailedException","errorType":"exception","errorClass":"AuthenticationFailedException","httpStatus":401,"severity":"error","filePath":"extensions/security-jpa/runtime/src/main/java/io/quarkus/security/jpa/runtime/JpaIdentityProvider.java","lineNumber":63,"sourceCode":"                    try {\n                        return authenticate(request);\n                    } finally {\n                        requestContext.terminate();\n                    }\n                }\n                return authenticate(request);\n            }\n        });\n    }\n\n    private SecurityIdentity authenticate(UsernamePasswordAuthenticationRequest request) {\n        try (Session session = sessionFactory.openSession()) {\n            session.setHibernateFlushMode(FlushMode.MANUAL);\n            session.setDefaultReadOnly(true);\n            return authenticate(session, request);\n        } catch (SecurityException e) {\n            log.debug(\"Authentication failed\", e);\n            throw new AuthenticationFailedException(e);\n        }\n    }\n\n    protected <T> T getSingleUser(Query query) {\n        @SuppressWarnings(\"unchecked\")\n        List<T> results = (List<T>) query.getResultList();\n        return JpaIdentityProviderUtil.getSingleUser(results);\n    }\n\n    protected boolean requireActiveCDIRequestContext() {\n        return false;\n    }\n\n    public abstract SecurityIdentity authenticate(EntityManager em,\n            UsernamePasswordAuthenticationRequest request);\n\n}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/security-jpa/runtime/src/main/java/io/quarkus/security/jpa/runtime/JpaIdentityProvider.java#L45-L81","documentation":"JpaIdentityProvider.authenticate() opens a read-only Hibernate session and delegates to authenticate(session, request). Any SecurityException raised while loading/validating the user (credential verification failure, lookup failure) is wrapped in an AuthenticationFailedException, which the HTTP auth machinery turns into a 401.","triggerScenarios":"A login request against the JPA identity provider whose authenticate() throws SecurityException — e.g. stored-password verification failing or the user query failing validation.","commonSituations":"User typing wrong username/password; password hash algorithm mismatch between stored hash and configured PasswordProvider; custom JpaIdentityProvider subclass throwing SecurityException for business reasons; database errors surfaced as auth failures.","solutions":["Check server logs at debug level for the wrapped SecurityException ('Authentication failed') to find the root cause.","Verify the user's credentials and that the stored password hash matches the configured password type/provider (e.g. bcrypt vs clear).","Confirm the user exists and the user-definition entity mappings are correct.","If credentials are fine, inspect the session/DB connectivity and query configuration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    SecurityIdentity id = identityProviderManager.authenticate(request).await().indefinitely();\n} catch (AuthenticationFailedException e) {\n    log.debug(\"auth failed\", e.getCause()); // inspect wrapped SecurityException\n    return Response.status(401).build();\n}","preventionTips":["Enable debug logging for io.quarkus.security.jpa to see root causes","Keep stored password hash type in sync with configured PasswordType","Test login credentials against the exact datasource/PU configured"],"tags":["security","authentication","jpa","hibernate"],"backgroundTag":"authentication-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}