class ExternalAuthenticationHelper in Lightweight Directory Access Protocol (LDAP) 8.3
Helper class to wrap external_auth service.
@TODO: Inject service properly.
Hierarchy
- class \Drupal\ldap_user\Helper\ExternalAuthenticationHelper
Expanded class hierarchy of ExternalAuthenticationHelper
8 files declare their use of ExternalAuthenticationHelper
- DrupalUserProcessor.php in ldap_user/
src/ Processor/ DrupalUserProcessor.php - ExternalAuthenticationHelperTests.php in ldap_user/
tests/ src/ Unit/ ExternalAuthenticationHelperTests.php - GroupUserUpdateProcessor.php in ldap_user/
src/ Processor/ GroupUserUpdateProcessor.php - LDAPAuthorizationProvider.php in ldap_authorization/
src/ Plugin/ authorization/ Provider/ LDAPAuthorizationProvider.php - LdapUserTestForm.php in ldap_user/
src/ Form/ LdapUserTestForm.php
File
- ldap_user/
src/ Helper/ ExternalAuthenticationHelper.php, line 12
Namespace
Drupal\ldap_user\HelperView source
class ExternalAuthenticationHelper {
/**
* Replaces the authmap table retired in Drupal 8.
*
* In Drupal 7 this was user_set_authmap.
*
* @param \Drupal\user\UserInterface $account
* Drupal user account.
* @param string $identifier
* Authentication name.
*/
public static function setUserIdentifier(UserInterface $account, $identifier) {
$authmap = \Drupal::service('externalauth.authmap');
$authmap
->save($account, 'ldap_user', $identifier);
}
/**
* Called from hook_user_delete ldap_user_user_delete.
*
* @param int $uid
* Drupal user ID.
*/
public static function deleteUserIdentifier($uid) {
$authmap = \Drupal::service('externalauth.authmap');
$authmap
->delete($uid);
}
/**
* Replaces the authmap table retired in Drupal 8.
*/
public static function getUidFromIdentifierMap($identifier) {
$authmap = \Drupal::service('externalauth.authmap');
return $authmap
->getUid($identifier, 'ldap_user');
}
/**
* Replaces the authmap table retired in Drupal 8.
*
* @param int $uid
* Drupal user ID.
*
* @return string
* Authentication name.
*/
public static function getUserIdentifierFromMap($uid) {
$authmap = \Drupal::service('externalauth.authmap');
$authdata = $authmap
->getAuthdata($uid, 'ldap_user');
if (isset($authdata['authname']) && !empty($authdata['authname'])) {
return $authdata['authname'];
}
}
/**
* Check if user is excluded.
*
* @param mixed $account
* A Drupal user object.
*
* @return bool
* TRUE if user should be excluded from LDAP provision/syncing
*/
public static function excludeUser($account = NULL) {
// @TODO 2914053.
// Always exclude user 1.
if (is_object($account) && $account
->id() == 1) {
return TRUE;
}
// Exclude users who have been manually flagged as excluded.
if (is_object($account) && $account
->get('ldap_user_ldap_exclude')->value == 1) {
return TRUE;
}
// Everyone else is fine.
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExternalAuthenticationHelper:: |
public static | function | Called from hook_user_delete ldap_user_user_delete. | |
ExternalAuthenticationHelper:: |
public static | function | Check if user is excluded. | |
ExternalAuthenticationHelper:: |
public static | function | Replaces the authmap table retired in Drupal 8. | |
ExternalAuthenticationHelper:: |
public static | function | Replaces the authmap table retired in Drupal 8. | |
ExternalAuthenticationHelper:: |
public static | function | Replaces the authmap table retired in Drupal 8. |