{"record":{"id":"ca8f0f93b87e3800","repo":"apereo/cas","slug":"e-getmessage-ca8f0f","errorCode":null,"errorMessage":"[e.getMessage()]","messagePattern":"\\[e\\.getMessage\\(\\)\\]","errorType":"exception","errorClass":"FailedLoginException","httpStatus":null,"severity":"error","filePath":"support/cas-server-support-jdbc-authentication/src/main/java/org/apereo/cas/jdbc/SearchModeSearchDatabaseAuthenticationHandler.java","lineNumber":54,"sourceCode":"    protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(\n        final UsernamePasswordCredential credential, final String originalPassword) throws Throwable {\n        val sql = \"SELECT COUNT('x') FROM \".concat(properties.getTableUsers())\n            .concat(\" WHERE \")\n            .concat(properties.getFieldUser())\n            .concat(\" = ? AND \")\n            .concat(properties.getFieldPassword()).concat(\"= ?\");\n        val username = credential.getUsername();\n        try {\n            LOGGER.debug(\"Executing SQL query [{}]\", sql);\n            val count = getJdbcTemplate().queryForObject(sql, Integer.class, username, credential.toPassword());\n            if (count == null || count == 0) {\n                throw new FailedLoginException(username + \" not found with SQL query.\");\n            }\n            val principal = principalFactory.createPrincipal(username);\n            return createHandlerResult(credential, principal, new ArrayList<>());\n        } catch (final Throwable e) {\n            LoggingUtils.error(LOGGER, e);\n            throw new FailedLoginException(e.getMessage());\n        }\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":58,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-jdbc-authentication/src/main/java/org/apereo/cas/jdbc/SearchModeSearchDatabaseAuthenticationHandler.java#L36-L58","documentation":"The handler wraps the whole authentication attempt in catch (Throwable) and rethrows FailedLoginException(e.getMessage()). Any database-level failure (SQL syntax error, connection failure, driver missing, NPE) surfaces as this generic failed-login message with the original message text.","triggerScenarios":"Any Throwable escaping queryForObject: DataAccessException from a broken SQL string, DataSource connectivity problems, NullPointerException on misconfigured properties, ClassCastException on unexpected count types.","commonSituations":"Typo in cas.authn.jdbc.search[].sql; DB down or network blocked; JDBC driver not on classpath; jdbcTemplate/datasource bean misconfiguration.","solutions":["Read the logged stack trace via LoggingUtils output to identify the root cause.","Test the datasource connectivity and run the generated SQL directly in the DB.","Validate cas.authn.jdbc.search[] properties (sql, table, fields) and the JDBC driver dependency.","Replace generic handling by checking DB health and configuration before enabling this handler."],"exampleFix":"// before: sql missing FROM table\ncas.authn.jdbc.search[0].sql=SELECT COUNT(*) FROM WHERE username=? AND password=?\n// after\ncas.authn.jdbc.search[0].sql=SELECT COUNT(*) FROM users WHERE username=? AND password=?","handlingStrategy":"try-catch","validationCode":"// health-check the datasource before attempting auth\njdbcTemplate.queryForObject(\"SELECT 1\", Integer.class);","typeGuard":null,"tryCatchPattern":"try { result = handler.authenticate(credential); }\ncatch (FailedLoginException e) {\n  Throwable root = ExceptionUtils.getRootCause(e);\n  log.error(\"Auth failed: {}\", root == null ? e.getMessage() : root.getMessage());\n}","preventionTips":["Enable debug logging for the handler to capture the root stack trace.","Validate SQL syntax in a DB console before deploying config.","Keep the JDBC driver on the classpath and connection pool tested at startup."],"tags":["jdbc","sql","database"],"backgroundTag":"sql-query-failed","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}