Replace the `ldap_user_identities` table with the authmap (or whatever) table from External Authentication module and make it a dependency.
https://www.drupal.org/project/externalauth

@svendecabooter

queenvictoria: simplesamlphp_auth/src/Service/SimplesamlphpDrupalAuth.php adds the externalauth service, which could be useful as an example

@svendecabooter

The module came about when porting the https://www.drupal.org/project/simplesamlphp_auth module to Drupal 8.
It's an attempt to create a generic solution for the problems that were solved in Drupal 7 core with regards to external login.
It would indeed be interesting to see if the module can be used for the LDAP module in Drupal 8.

The outcome of the conversation is that externalauth pretty much just provides the authmap table that was removed from core in D8. It provides other bits and pieces. @svendecabooter is happy to receive patches for other functionality. I will rework ldap_authenication to use externalauth where possible (at least the authmap table).

Then we can move the Views issue into External Authentication's queue
https://github.com/Laudanum/ldap/pull/32

Comments

queenvictoria created an issue. See original summary.

queenvictoria’s picture

Issue summary: View changes
queenvictoria’s picture

Issue summary: View changes
queenvictoria’s picture

Issue summary: View changes
queenvictoria’s picture

Assigned: Unassigned » queenvictoria
queenvictoria’s picture

StatusFileSize
new4.82 KB

As this is a reasonable change please review it.

* Run update.php. Notice that the ldap_user_identities table disappears and authmap is populated with the data from the ldap_user_identities table.
* You should still be able to authenticate (and create a new user by so doing) which will create a row in the authmap table.

queenvictoria’s picture

Assigned: queenvictoria » Unassigned
Status: Active » Needs review
larowlan’s picture

Some minor remarks/comments - happy for all of these to be follow up tasks

  1. +++ b/ldap_user/ldap_user.install
    @@ -127,3 +77,30 @@ function ldap_user_update_8001() {
    +    drupal_set_message("Please install the <a href='https://drupal.org/project/externalauth'>External Auth</a> module.", "error");
    

    We should wrap this in t()

  2. +++ b/ldap_user/ldap_user.install
    @@ -127,3 +77,30 @@ function ldap_user_update_8001() {
    +    // @TODO Throw an \Drupal\Core\Utility\UpdateException
    

    We should do that here too.

  3. +++ b/ldap_user/ldap_user.install
    @@ -127,3 +77,30 @@ function ldap_user_update_8001() {
    +  foreach ( db_query("SELECT aid, uid, identifier FROM {ldap_user_identities}")->fetchAll() as $identity ) {
    +    // Load the user as the service expects an account.
    +    $account = user_load($identity->uid);
    +    $authmap = \Drupal::service('externalauth.authmap');
    +    $authmap->save($account, 'ldap_user', $identity->identifier);
    +
    +    // Delete the row if successful.
    +    db_query("DELETE FROM {ldap_user_identities} WHERE aid = :aid", array(':aid' => $identity->aid));
    +  }
    

    Should we do this in a batch (using the passed $sandbox argument) in case there are some sites with 1000s of users?

  4. +++ b/ldap_user/ldap_user.install
    @@ -127,3 +77,30 @@ function ldap_user_update_8001() {
    +  // Drop the table if successful.
    +  db_query("DROP TABLE {ldap_user_identities}");
    

    I think we should do this in a separate update hook, just for clean separation - this is something @andypost taught me.

queenvictoria’s picture

StatusFileSize
new6.55 KB

Thanks for the feedback and fixes. I've updated the patch please take a look!

grahl’s picture

There is at least one functional error in patch #9 in ldap_user_get_identifier_from_map(), where $authname is declared but $authmap used.

larowlan’s picture

+++ b/ldap_user/ldap_user.module
@@ -568,19 +568,21 @@ function ldap_user_grab_password_validate($form, FormState &$form_state) {
+  $authname = \Drupal::service('externalauth.authmap')->getAuthdata($uid, 'ldap_user');
+  return $authmap->authname;

This looks wrong

queenvictoria’s picture

Status: Needs review » Fixed

Good catch @grahl. Committed in 7f13ffe9798125a067f21b3dfd55a31d8d965062

  • queenvictoria committed 61a0e31 on 8.x-3.x
    #2698157 Update hook to migrate tables.
    
  • queenvictoria committed 7f13ffe on 8.x-3.x
    Issue #2698157 by queenvictoria, larowlan, grahl: Implement externalauth...
  • queenvictoria committed bebc0ff on 8.x-3.x
    #2698157 Remove the ldap_user_identities schema.
    
  • queenvictoria committed f4189e6 on 8.x-3.x
    #2698157 Rework ldap_user identity methods to use externalauth services...
grahl’s picture

Status: Fixed » Active
StatusFileSize
new639 bytes

Sorry to reopen this but I think something obvious is still missing: ldap_user should have externalauth as a dependency so that this gets enabled automatically. The trivial patch for that is attached.

grahl’s picture

StatusFileSize
new985 bytes

Additional patch needed since ldap_user_get_identifier_from_map() still gets called with uid instead of id().

grahl’s picture

StatusFileSize
new2.42 KB

Sorry, one more update but ldap_user_get_identifier_from_map() was calling its service incorrectly. Weird since all other functions did it correctly.

  • larowlan committed 5f4bf3e on 8.x-3.x authored by grahl
    Issue #2698157 by grahl, queenvictoria, larowlan: Implement externalauth...
  • larowlan committed 8c24f83 on 8.x-3.x authored by grahl
    Issue #2698157 by grahl, queenvictoria, larowlan: Implement externalauth...
larowlan’s picture

Status: Active » Fixed

thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

DarcyB’s picture

It looks like Provisioning Drupal accounts from LDAP is not functioning. A browse of the source makes me think this might be intentional, or at least somewhat known. Is there a plan/timeline for enabling this ?

DarcyB’s picture

Status: Closed (fixed) » Needs work
thtas’s picture

StatusFileSize
new648 bytes

ldap_user_get_identifier_from_map is not properly returning the authname.

see patch

larowlan’s picture

Status: Needs work » Reviewed & tested by the community

LGTM

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

The last submitted patch, 22: implement_externalauth-2698157-22.patch, failed testing.

queenvictoria’s picture

Status: Needs work » Fixed

Committed thanks!

  • queenvictoria committed 61d9d12 on 8.x-3.x authored by thtas
    Issue #2698157 by grahl, queenvictoria, thtas, larowlan: Implement...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.