function samlauth_user_presave in SAML Authentication 8.2
Same name and namespace in other branches
- 8.3 samlauth.module \samlauth_user_presave()
- 4.x samlauth.module \samlauth_user_presave()
Implements hook_user_presave().
File
- ./
samlauth.module, line 64 - Contains samlauth.module.
Code
function samlauth_user_presave(UserInterface $account) {
// Hook into the user creation process from ExternalAuth::register() so that
// we don't need to save the new user a second time to add our SAML attribute
// values into the new user object. The way externalauth prefixes account
// names acts as a recursion stop, in case any called code (e.g. event) saves
// the account.
if ($account
->isNew() && strpos($account
->getAccountName(), 'samlauth_') === 0) {
// Doublecheck that we're actually processing an ACS request, which we can
// do by checking the request for presence of a user name attribute.
/** @var \Drupal\samlauth\SamlService $saml_service */
$saml_service = \Drupal::service('samlauth.saml');
if ($saml_service
->getAttributeByConfig('user_name_attribute')) {
$saml_service
->synchronizeUserAttributes($account, TRUE);
}
}
}