{"record":{"id":"59f1b0577a678b66","repo":"apereo/cas","slug":"requested-attribute-could-not-be-found-in-the","errorCode":null,"errorMessage":"Requested attribute [{}] could not be found in the query results","messagePattern":"Requested attribute \\[(.+?)\\] could not be found in the query results","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"support/cas-server-support-jdbc-authentication/src/main/java/org/apereo/cas/jdbc/AbstractJdbcUsernamePasswordAuthenticationHandler.java","lineNumber":58,"sourceCode":"        this.dataSource = dataSource;\n        this.jdbcTemplate = new JdbcTemplate(dataSource);\n        this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);\n    }\n\n    protected Map<String, List<Object>> collectPrincipalAttributes(final Map<String, Object> dbFields) {\n        val attributes = new HashMap<String, List<Object>>();\n        val principalAttributeMap = CoreAuthenticationUtils.transformPrincipalAttributesListIntoMultiMap(properties.getPrincipalAttributeList());\n        principalAttributeMap.forEach((key, names) -> {\n            val attribute = dbFields.get(key);\n            if (attribute != null) {\n                LOGGER.debug(\"Found attribute [{}] from the query results\", key);\n                val attributeNames = CollectionUtils.toCollection(names);\n                attributeNames.forEach(attrName -> {\n                    LOGGER.debug(\"Principal attribute [{}] is virtually remapped/renamed to [{}]\", key, attrName);\n                    attributes.put(attrName.toString(), CollectionUtils.wrap(attribute.toString()));\n                });\n            } else {\n                LOGGER.warn(\"Requested attribute [{}] could not be found in the query results\", key);\n            }\n        });\n        return attributes;\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":64,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-jdbc-authentication/src/main/java/org/apereo/cas/jdbc/AbstractJdbcUsernamePasswordAuthenticationHandler.java#L40-L64","documentation":"This WARN is logged by AbstractJdbcUsernamePasswordAuthenticationHandler.collectPrincipalAttributes when an attribute name listed in the SQL query's attribute-mapping configuration is absent from the query result row. CAS iterates the expected attribute names, and any name with no corresponding column/value in the ResultSet is reported and simply skipped - the returned principal just lacks that attribute. It signals a mismatch between configured attribute mappings and what the SQL query actually returns.","triggerScenarios":"Configuring cas.authn.jdbc.query[].attributeMappings whose keys/values reference columns not selected by the configured sql statement; virtual attribute remapping (names) pointing at a source attribute that the query did not return; renaming a DB column without updating attributeMappings; sql returning a single-row result missing expected fields due to NULL or join misses.","commonSituations":"Typo in attributeMappings vs actual SELECT column aliases; DBA added a column but forgot to add it to the SQL; empty/NULL result columns for some users; migrating from another authn handler whose attribute names differed.","solutions":["Align the sql SELECT clause with the configured attributeMappings so every mapped attribute (and its source key) is actually returned by the query","Fix typos or case mismatches between attributeMappings keys and result-set column names/aliases","If the attribute is legitimately optional per user, ignore the warning or coalesce the column in SQL (e.g. COALESCE(col, '')) ","Verify the principal's row exists and is not missing joined data for the specific user"],"exampleFix":"// before\nsql=SELECT username, email FROM users WHERE username=?\nattributeMappings.email=mail\nattributeMappings.displayName=displayName\n// after\nsql=SELECT username, email, display_name FROM users WHERE username=?\nattributeMappings.email=mail\nattributeMappings.displayName=displayName","handlingStrategy":"validation","validationCode":"Set<String> selectAliases = extractSelectAliases(properties.getSql());\nfor (String attr : properties.getAttributeMappings().keySet()) {\n    if (!selectAliases.contains(attr)) throw new IllegalStateException(\"attributeMappings key not in SELECT: \" + attr);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep attributeMappings and the sql SELECT clause in sync; review both together in code review","Use explicit column aliases in SQL matching config keys exactly","Test authentication for users with NULL/optional columns","Add startup validation that parsed query columns cover all mapped attributes"],"tags":["jdbc","authentication","attribute-resolution","config-mismatch"],"backgroundTag":"empty-result-set","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"}