? .cache ? .project ? .settings Index: cas.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cas/cas.module,v retrieving revision 1.45 diff -u -p -r1.45 cas.module --- cas.module 16 Mar 2009 16:41:50 -0000 1.45 +++ cas.module 28 Apr 2009 17:53:45 -0000 @@ -125,6 +125,10 @@ function cas_login_check() { $cas_domain = (string)variable_get('cas_domain', ''); $cas_cert_verify = (string)variable_get('cas_cert_verify', CAS_NO_VERIFY); $cas_cert = (string)variable_get('cas_cert', ''); + $cas_attributes = (int)variable_get('cas_attributes', 0); + $cas_attributes_uid = (string)variable_get('cas_attributes_uid', ''); + $cas_attributes_name = (string)variable_get('cas_attributes_name', ''); + $cas_attributes_mail = (string)variable_get('cas_attributes_mail', ''); // Drupal takes care of its own session $start_session = (boolean)FALSE; cas_save_page(); @@ -158,9 +162,30 @@ function cas_login_check() { else { phpCAS::forceAuthentication(); } + + if (method_exists("phpCAS","getAttributes")) { + $attributes = phpCAS::getAttributes(); + } + else { + $cas_attributes = 0; + } $cas_name = phpCAS::getUser(); + if ($cas_attributes && $cas_attributes_uid) { + $cas_name = cas_attributes_concat($cas_attributes_uid, $attributes); + } + + $cas_uid = "name"; + if ($cas_attributes && $cas_attributes_uid) { + if ($cas_authmap) { + $cas_uid = "init"; + } + else { + $cas_uid = "uid"; + } + } + /* * Invoke hook_auth_transform($op, &$username) * @@ -199,13 +224,13 @@ function cas_login_check() { // try to log into Drupal if ($cas_authmap) { // users are coming from Drupal; no need to use the external_load and the authmap - $user = user_load(array("name" => $cas_name)); + $user = user_load(array($cas_uid => $cas_name)); } else { // users are external; use authmap table for associating external users $user = user_external_load($cas_name); if (!$user->uid && variable_get('cas_hijack_user', 0)) { - $user = user_load(array("name" => $cas_name)); + $user = user_load(array($cas_uid => $cas_name)); if ($user->uid) user_set_authmaps($user, array('authname_cas' => $cas_name)); } } @@ -223,6 +248,15 @@ function cas_login_check() { if (!$cas_authmap) $user_default['authname_cas'] = $cas_name; if ($cas_domain) $user_default['mail'] = $cas_name .'@'. $cas_domain; + if ($cas_attributes) { + if ($cas_attributes_name) { + $user_default['name'] = cas_attributes_concat($cas_attributes_name, $attributes); + } + if ($cas_attributes_mail) { + $user_default['mail'] = cas_attributes_concat($cas_attributes_mail, $attributes); + } + } + // Become user 1 to be able to save profile information session_save_session(FALSE); $admin = array('uid' => 1); @@ -483,6 +517,55 @@ function cas_admin_settings() { '#description' => t('This value can be used to establish a role automatically for all CAS users. As an example, if you are also using the simple_ldap module, you can use this role to establish a tie between CAS and LDAP-populated data. i.e. Users with the role of \'cas:user\' should have their LDAP data updated automatically.'), ); + if (method_exists("phpCAS", "getAttributes")) { + + $form['attributes'] = array( + '#type' => 'fieldset', + '#title' => t('User attribute settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $form['attributes']['cas_attributes'] = array( + '#type' => 'checkbox', + '#title' => t('Use user attributes'), + '#default_value' => variable_get('cas_attributes', 0), + '#description' => t('If your installation of CAS is set to send back user attributes and your phpCAS supports receiving them, use these options to assign the attributes to drupal user fields. To use multiple attributes in a single field, enter a comma separated list. Their values will be concatenated with a space separator (e.g. FirstName,LastName).'), + ); + + $form['attributes']['cas_attributes_concat'] = array( + '#type' => 'textfield', + '#title' => t('concatenation string'), + '#default_value' => variable_get('cas_attributes_concat', ' '), + '#size' => 30, + '#description' => t('String to use when concatenating attributes'), + ); + + $form['attributes']['cas_attributes_uid'] = array( + '#type' => 'textfield', + '#title' => t('uid'), + '#default_value' => variable_get('cas_attributes_uid', ''), + '#size' => 30, + '#description' => t('drupal\'s internal user id'), + ); + + $form['attributes']['cas_attributes_name'] = array( + '#type' => 'textfield', + '#title' => t('name'), + '#default_value' => variable_get('cas_attributes_name', ''), + '#size' => 30, + '#description' => t('A display name for the user'), + ); + + $form['attributes']['cas_attributes_mail'] = array( + '#type' => 'textfield', + '#title' => t('email'), + '#default_value' => variable_get('cas_attributes_mail', ''), + '#size' => 30, + '#description' => t('The user\'s email address'), + ); + + } $form['pages'] = array( '#type' => 'fieldset', @@ -894,4 +977,14 @@ function _cas_single_sign_out_save_token /* ** CAS Sigle Sign Out - END -*/ \ No newline at end of file +*/ + +/** + * Helper function to concatenate attribute strings. + * + * @return string + * The values of the input attributes concatenated by the value in cas_attributes_concat. + */ +function cas_attributes_concat($attribute_names, $attribute_values) { + return implode(variable_get('cas_attributes_concat', " "), array_intersect_key($attribute_values, array_flip(split(",", $attribute_names)))); +} \ No newline at end of file