function _shib_auth_update_fields in Shibboleth Authentication 7.4
Helper function, actually update the fields on user_login or user_insert.
2 calls to _shib_auth_update_fields()
- shib_auth_profile_user_login in shib_auth_profile/
shib_auth_profile.module - Implements hook_user_login().
- shib_auth_profile_user_presave in shib_auth_profile/
shib_auth_profile.module - Implements hook_user_presave().
File
- shib_auth_profile/
shib_auth_profile.module, line 86 - Drupal Shibboleth authentication profile module.
Code
function _shib_auth_update_fields($op) {
$edit = array();
foreach (field_read_fields(array(
'entity_type' => 'user',
)) as $field_name => $field) {
foreach (field_read_instances(array(
'field_id' => $field['id'],
)) as $instance) {
$mode = (string) @$instance['settings']['shib_auth_profile']['mode'];
$value = (string) @$instance['settings']['shib_auth_profile']['server_variables'];
if (empty($mode)) {
continue;
}
if ($op == 'login' && $mode == 'editable') {
continue;
}
/* Replace all [foo] occurrences if "foo" is a Shibboleth attribute
(header, CGI environment variable) i.e. $_SERVER[foo] exists, with
the corresponding attribute value.
If the attribute doesn't exist, it will remain unmolested ("[foo]").
Note that an attribute name may only contain [a-zA-Z0-9_-] characters.
*/
$replace_map = array();
if (preg_match_all('/\\[([\\w-]+)\\]/', $value, $attributes)) {
foreach ($attributes[1] as $a) {
if (shib_auth_getenv($a) != NULL) {
$replace_map['[' . $a . ']'] = shib_auth_getenv($a);
}
}
}
if ($replace_map) {
$value = str_replace(array_keys($replace_map), array_values($replace_map), $value);
}
$edit[$field['field_name']][LANGUAGE_NONE][0]['value'] = $value;
}
}
return $edit;
}