diff --git a/includes/simplesamlphp_auth.drupal.inc b/includes/simplesamlphp_auth.drupal.inc index 0cdd638..7395a8e 100644 --- a/includes/simplesamlphp_auth.drupal.inc +++ b/includes/simplesamlphp_auth.drupal.inc @@ -137,7 +137,12 @@ class SimpleSAML_Drupal { if ($key == 'cs_fields') { foreach ($data as $additional_data) { $additional_data = explode(':', $additional_data); - $this->_simplesaml_auth_source->{$additional_data[0]} = $additional_data[1]; + if (isset($additional_data[1]) && !empty($additional_data[1])) { + // Wrap all custom fields around the custom fields property to access them later + $this->_simplesaml_auth_source->custom_fields[$additional_data[0]] = $additional_data[1]; + } else { + watchdog('simplesamlphp_auth', 'Unable to load custom field into the SAML object, verify that you\'re using the correct operator', array(), WATCHDOG_DEBUG); + } // end if - else } // end foreach } // end if $this->_simplesaml_auth_source->{$key} = $data; diff --git a/simplesamlphp_auth.inc b/simplesamlphp_auth.inc index 4a853dd..78cbb6f 100644 --- a/simplesamlphp_auth.inc +++ b/simplesamlphp_auth.inc @@ -133,22 +133,26 @@ function _simplesaml_auth_user_register($authname) { 'timezone' => date_default_timezone_get(), ); + /** + * Populate custom fields + */ + if (isset($simplesamlphp_authsource->custom_fields)) { + foreach($simplesamlphp_authsource->custom_fields as $field_name => $attribute_name) { + if (!empty($field_name) && !empty($attribute_name)) { + $userinfo[$field_name] = array( + 'und' => array(array('value' => $simplesamlphp_drupal->getAttrsFromAssertion($attribute_name))) + ); + } // end if + } // end foreach + } // end if + /** - * If you want, you can place more custom fields and populate them here - * @example - * if (isset($simplesamlphp_authsource->firstname)) { - * $userinfo['field_first_name'] = array( - * 'und' => array(array('value' => $simplesamlphp_drupal->getAttrsFromAssertion($simplesamlphp_authsource->firstname))) - * ); - * } - */ - /** - * Populate roles + * Populate roles */ $roles = array(); try { // Get SAML attributes - $attrs = $simplesamlphp_auth_as->getAttributes(); + $attrs = $simplesamlphp_auth_as->getAttributes(); if ($simplesamlphp_authsource->syncroles) { // The roles provided by the IdP.