<?PHP if (!defined('PmWiki')) exit();

//Include the CAS php module

if (isset($AuthUser['CasPath'])) {
  include_once($AuthUser['CasPath']);
} else {
  include_once('CAS/CAS.php');
}

$HandleActions['logout'] = 'casLogout';
//Uncomment for debugging;
#error_reporting(E_ALL & ~E_NOTICE);
#  phpCAS::setDebug('');

if (!isset($AuthUser['CasPort'])) { $AuthUser['CasPort'] = 443;}
if (!isset($AuthUser['CasUri'])) { $AuthUser['CasPort'] = '';}

//Check to see if a CAS server has been set, if so go ahead and 
//setup the connect string, if not just exit the script.
if (isset($AuthUser['CasServer'])) {

  phpCAS::client(CAS_VERSION_2_0,$AuthUser['CasServer'],$AuthUser['CasPort'],$AuthUser['CasUri']);
  phpCAS::setNoCasServerValidation();

 if (!phpCAS::checkAuthentication()) {
   phpCAS::forceAuthentication();
   $AuthId = phpCAS::getUser();
 } else {
   $AuthId = phpCAS::getUser();

 }
}


function casLogout($pagename) {
  global $AuthUser;
  if (isset($AuthUser['CasRedirectUrl'])) {
    phpCAS::logoutWithRedirectServiceAndUrl($AuthUser['CasRedirectUrl'], $AuthUser['CasRedirectUrl']);
  } else {
    phpCAS::logout();
  }
}

?>