| 1 |
<?php |
<?php |
| 2 |
// $Id: cas.module,v 1.36 2008/02/02 21:04:44 metzlerd Exp $ |
// $Id: cas.module,v 1.37 2008/02/06 06:14:25 metzlerd Exp $ |
| 3 |
/** |
/** |
| 4 |
* Enables users to authenticate via a Central Authentication Service (CAS) |
* Enables users to authenticate via a Central Authentication Service (CAS) |
| 5 |
* Cas will currently work if the auto registration is turned on and will |
* Cas will currently work if the auto registration is turned on and will |
| 15 |
* Implementation of hook_init |
* Implementation of hook_init |
| 16 |
* Traps a page load to see if authentication is required. |
* Traps a page load to see if authentication is required. |
| 17 |
*/ |
*/ |
| 18 |
|
function cas_init() |
| 19 |
|
{ |
| 20 |
|
cas_login_check(); |
| 21 |
|
} |
| 22 |
|
|
| 23 |
|
/** |
| 24 |
|
* Access function used to make sure cas menu doesn't show up when |
| 25 |
|
* Not needed. |
| 26 |
|
* |
| 27 |
|
* @return boolean |
| 28 |
|
*/ |
| 29 |
|
function cas_menu_check() |
| 30 |
|
{ |
| 31 |
|
global $user; |
| 32 |
|
$access = false; |
| 33 |
|
if ($user->uid==0) |
| 34 |
|
$access=TRUE; |
| 35 |
|
if (strpos($_GET['q'],'admin/build/menu')!==false) |
| 36 |
|
{ |
| 37 |
|
$access=TRUE; |
| 38 |
|
} |
| 39 |
|
return $access; |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
/** |
| 43 |
|
* Check to see if we need to display the logout menu. |
| 44 |
|
* @return boolean |
| 45 |
|
*/ |
| 46 |
|
function cas_menu_logout_check() |
| 47 |
|
{ |
| 48 |
|
global $user; |
| 49 |
|
$access = false; |
| 50 |
|
if ($user->uid) |
| 51 |
|
$access = true; |
| 52 |
|
return $access; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
/** |
| 56 |
|
* Checks to see if the user needs to be logged in |
| 57 |
|
* |
| 58 |
|
*/ |
| 59 |
function cas_login_check() { |
function cas_login_check() { |
| 60 |
global $user, $account; |
global $user, $account; |
| 61 |
|
|
| 155 |
|
|
| 156 |
// now save the user and become the new user. |
// now save the user and become the new user. |
| 157 |
$user = user_save("", $user_default); |
$user = user_save("", $user_default); |
| 158 |
$sesion_save_session(true); |
session_save_session(true); |
| 159 |
watchdog("user", t('new user: %n (CAS)', array('%n' => $user->name)), WATCHDOG_NOTICE, l(t("edit user"), "admin/user/edit/$user->uid")); |
watchdog("user", 'new user: %n (CAS)', array('%n' => $user->name), WATCHDOG_NOTICE, l(t("edit user"), "admin/user/edit/$user->uid")); |
| 160 |
if(($user->uid) && ($user->uid > 0) && $cas_authmap) |
if(($user->uid) && ($user->uid > 0) && $cas_authmap) |
| 161 |
{ |
{ |
| 162 |
module_invoke_all('user', 'login', null, $user); |
module_invoke_all('user', 'login', null, $user); |
| 163 |
unset($_SESSION['cas_goto']); |
unset($_SESSION['cas_goto']); |
| 164 |
watchdog('user', t('Session opened for %name.', array('%name' => $user->name))); |
watchdog('user', 'Session opened for %name.', array('%name' => $user->name)); |
| 165 |
drupal_goto("user/" . $user->uid . "/edit"); |
drupal_goto("user/" . $user->uid . "/edit"); |
| 166 |
} |
} |
| 167 |
|
|
| 205 |
|
|
| 206 |
module_invoke_all('user', 'login', null, $user); |
module_invoke_all('user', 'login', null, $user); |
| 207 |
drupal_set_message(t(variable_get('cas_login_message', 'Logged in via CAS as %cas_username.'), array('%cas_username' => $user->name))); |
drupal_set_message(t(variable_get('cas_login_message', 'Logged in via CAS as %cas_username.'), array('%cas_username' => $user->name))); |
| 208 |
watchdog('user', t('Session opened for %name.', array('%name' => $user->name))); |
watchdog('user', 'Session opened for %name.', array('%name' => $user->name)); |
| 209 |
// We can't count on the menu because we're changing login states. |
// We can't count on the menu because we're changing login states. |
| 210 |
cas_login_page(); |
cas_login_page(); |
| 211 |
|
|
| 241 |
* Implements hook_menu. |
* Implements hook_menu. |
| 242 |
* |
* |
| 243 |
*/ |
*/ |
| 244 |
function cas_menu($may_cache) { |
function cas_menu() { |
| 245 |
global $user; |
global $user; |
| 246 |
$items = array(); |
$items = array(); |
| 247 |
cas_login_check(); |
//cas_login_check(); |
| 248 |
if ($may_cache) { |
$items['admin/user/cas'] = array( |
|
$items[] = array( |
|
|
'path' => 'admin/user/cas', |
|
| 249 |
'title' => t('CAS settings'), |
'title' => t('CAS settings'), |
| 250 |
'description' => 'Configure central authentication services', |
'description' => 'Configure central authentication services', |
| 251 |
'callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 252 |
'callback arguments' => 'cas_admin_settings', |
'page arguments' => array('cas_admin_settings'), |
| 253 |
'access' => user_access('administer cas'), |
'access arguments' => array('administer cas'), |
| 254 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 255 |
); |
); |
| 256 |
if ((!$user->uid) || ((arg(0)=='admin') && (arg(1) == 'build') && (arg(2) == 'menu'))) |
|
| 257 |
{ |
$items['cas'] = array( |
|
$items[] = array( |
|
| 258 |
'path' => 'cas', |
'path' => 'cas', |
| 259 |
'title' => t('CAS Login'), |
'title' => t('CAS Login'), |
| 260 |
'callback' => 'cas_login_page', |
'page callback' => 'cas_login_page', |
| 261 |
'access' => TRUE, |
'access callback' => 'cas_menu_check', |
| 262 |
'type' => MENU_SUGGESTED_ITEM, |
'type' => MENU_SUGGESTED_ITEM, |
| 263 |
); |
); |
| 264 |
} |
|
| 265 |
if (($user->uid) || ((arg(0)=='admin') && (arg(1) == 'build') && (arg(2) == 'menu'))) |
|
| 266 |
{ |
$items['caslogout'] = array( |
|
$items[] = array( |
|
|
'path' => 'caslogout', |
|
| 267 |
'title' => t('CAS Logout'), |
'title' => t('CAS Logout'), |
| 268 |
'callback' => 'cas_logout', |
'page callback' => 'cas_logout', |
| 269 |
'access' => TRUE, |
'access callback' => 'cas_menu_logout_check', |
| 270 |
'type' => MENU_SUGGESTED_ITEM, |
'type' => MENU_SUGGESTED_ITEM, |
| 271 |
); |
); |
| 272 |
} |
|
| 273 |
|
|
| 274 |
} |
return $items; |
|
return $items; |
|
| 275 |
} |
} |
| 276 |
|
|
| 277 |
/** |
/** |
| 352 |
|
|
| 353 |
$form['account']['cas_hijack_user'] = array( |
$form['account']['cas_hijack_user'] = array( |
| 354 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 355 |
'#title' => t('If CAS is not the user repository, should cas highjack users with the same name?'), |
'#title' => t('If Drupal is not the user repository, should cas highjack users with the same name?'), |
| 356 |
'#default_value' => variable_get('cas_hijack_user', 0), |
'#default_value' => variable_get('cas_hijack_user', 0), |
| 357 |
'#description' => t('If you have pre-created regular accounts in cas that you want converted to mapped accounts, check this box. Otherwise CAS will likely throw duplicate key violation errors on new users.'), |
'#description' => t('If you have pre-created regular accounts in cas that you want converted to mapped accounts, check this box. Otherwise CAS will likely throw duplicate key violation errors on new users.'), |
| 358 |
); |
); |
| 572 |
{ |
{ |
| 573 |
global $user; |
global $user; |
| 574 |
|
|
| 575 |
watchdog('user', t('Session closed for %name.', array('%name' => theme('placeholder', $user->name)))); |
watchdog('user', 'Session closed for %name.', array('%name' => theme('placeholder', $user->name))); |
| 576 |
|
|
| 577 |
// Destroy the current session: |
// Destroy the current session: |
| 578 |
session_destroy(); |
session_destroy(); |
| 686 |
* implementation of hook_form_alter |
* implementation of hook_form_alter |
| 687 |
* Overrides specific from settings based on user policy. |
* Overrides specific from settings based on user policy. |
| 688 |
*/ |
*/ |
| 689 |
function cas_form_alter($form_id,&$form) |
function cas_form_alter(&$form, $formid, $form_state) |
| 690 |
{ |
{ |
| 691 |
switch ($form_id){ |
switch ($form_id){ |
| 692 |
case 'user_edit': |
case 'user_edit': |