I know this has been discussed before with the provisioning of roles to groups, but what about simply mapping to an multivalue attribute. Currently, the Field Roles doesn't seem to do much of anything when provisioning to LDAP (the field has target_id not value). Would it make sense to add an exception to a map this field? Just as a real quick example:

LdapUserProcessor.php

if ($ldapAttributeName == 'dn' && $value) {
  $ldapUserEntry['dn'] = $value;
}
elseif($field_detail['user_attr'] == '[field.roles]') {
  $roles = $account->getRoles();
  $ldapUserEntry[$ldapAttributeName] = [];
  foreach($roles as $key => $value) {
    $ldapUserEntry[$ldapAttributeName][$key] = $value;
  }
}

Otherwise, i'm not sure how to store Drupal roles in LDAP other than maybe writing a hook for ldap_entry_pre_provision_alter.

Comments

zrisha created an issue. See original summary.

grahl’s picture

Title: Provisioning Drupal roles to an LDAP attribute » User field mappings: Better support for entity references and multi-value fields
Issue tags: -drupal roles, -user roles

Hi

Thanks for your report.

I‘m happy to consider adding better multi-value support and also better support for entity reference fields (which would be the more generic fix here), if someone wants to invest a bit more time here for a patch and also add the relevant test cases. I‘ve rephrased the title somewhat to reflect this.

However, this would not be the usual solution for role assignment in most LDAP setups, where this is handled by groups. We specifically have groups support and the ldap_authorization module to allow for role assignment either based on a single attribute or a regular expression. I‘d recommend to you to not try to map roles directly in the field mappings but rather use the intended mechanism in your setup.

We do have roles as a field mapping available so it‘s possible to send them in the other direction. Nonetheless, we could try to make this a bit clearer by hiding that mapping at least with the to_drupal direction. Patches would be welcome for that, too, if someone doesn‘t have another use case that isn‘t documented yet.

grahl’s picture

Status: Active » Postponed
bluegeek9’s picture

Status: Postponed » Closed (duplicate)

There are two other issues. One addresses multi-value fields, and the other addresses entity references. I think it makes sense to address them as separate requests, and patches have been submitted on the other issues.

#3088247: Support entity references on synchronization
#3024428: Support multi-value mappings