passbolt/passbolt_api · error
There is no mapping rule associated for the field:
Error message
There is no mapping rule associated for the field:
What it means
DirectoryEntry::getLdapObjectFieldValue looks up the LDAP attribute name for a logical field (e.g. 'firstname', 'email') in the directory-type-specific mapping rules. If the field has no mapping rule for the LDAP object's objectType, the code cannot translate the field and throws.
Solutions
- Ensure the mapping rules for the LDAP object's objectType contain an entry for the requested fieldName
- Review directory sync settings JSON (directoryMapping) and add the missing field mapping
- Use the fallbackFields parameter to provide alternative attribute names for fields lacking a primary rule
- Log the resolved $type and available mapping keys to spot objectType vs mapping key mismatches
Example fix
// before
$mappingRules = $mappingRules[$type];
if (!isset($mappingRules[$fieldName])) {
throw new Exception('There is no mapping rule associated for the field: ' . $fieldName);
}
// after
$mappingRules = $mappingRules[$type] ?? [];
if (!isset($mappingRules[$fieldName]) && !isset($fallbackFields[$fieldName])) {
throw new Exception('There is no mapping rule associated for the field: ' . $fieldName);
}
$fieldEquivalent = $mappingRules[$fieldName] ?? $fallbackFields[$fieldName]; Defensive patterns
Strategy: validation
Validate before calling
$rules = $mappingRules[$objectType] ?? [];
if (!array_key_exists($fieldName, $rules)) {
// skip field or configure mapping before calling getFieldValue
} Type guard
$fieldEquivalent = $mappingRules[$type][$fieldName] ?? $fallbackFields[$fieldName] ?? null;
if (!is_string($fieldEquivalent)) { return null; } Try / catch
try {
$value = $entry->getFieldValue($ldapObject, 'username', $mappingRules);
} catch (Exception $e) {
$value = null; // fall back to default attribute
} Prevention
- Keep complete field mappings (id, username, firstname, etc.) for every directory type in settings
- Provide fallbackFields when using custom LDAP schemas
- Log objectType values from LDAP to ensure mapping keys align
When it happens
Trigger: Requesting a field value via getFieldValue/getLdapObjectFieldValue whose key is absent from mappingRules[objectType], e.g. asking for 'username' when the active directory mapping only defines 'id' and 'email', or objectType typo/mismatch.
Common situations: Custom LDAP attribute mappings in directory sync settings omitting a required field; switching directory type (AD vs OpenLDAP) with mappings copied incorrectly; objectClass not matching expected keys.
Related errors
- A mapping rule for ID attribute could not be found for…
- A mapping rule for username attribute could not be found…
- Mapping rules could not be found for directory type
- 500
- An error has occurred parsing groupCustomFilter
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/04b26b1cd4f6dffb.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/PassboltEe/DirectorySync/src/Utility/DirectoryEntry/DirectoryEntry.php:206
* @param string $fieldName field name.
* @param array $mappingRules mapping rules.
* @param bool $first Returns first attribute found
* @param array|null $fallbackFields Fallback fields
* @return mixed field
* @throws \Exception
*/
private static function getLdapObjectFieldValue(
Entry $ldapObject,
string $fieldName,
array $mappingRules,
bool $first = true,
?array $fallbackFields = null
): mixed {
/** @var string $type */
$type = $ldapObject->getFirstAttribute('objectType');
$mappingRules = $mappingRules[$type];
if (!isset($mappingRules[$fieldName])) {
throw new Exception('There is no mapping rule associated for the field: ' . $fieldName);
}
$fieldEquivalent = $mappingRules[$fieldName];
$value = $first ?
$ldapObject->getFirstAttribute(ucfirst($fieldEquivalent)) :
$ldapObject->getAttribute(ucfirst($fieldEquivalent));
if (!is_null($value)) {
return $value;
}
// Use fallback field's value, if present
if (
is_null($fallbackFields)
|| !array_key_exists($fieldName, $fallbackFields)
|| empty($fallbackFields[$fieldName])
) {View on GitHub (pinned to 31c1bbc10f)