diff --git a/lib/CAS.php b/lib/CAS.php
index a446f34ea0..0e95c7a26d 100755
--- a/lib/CAS.php
+++ b/lib/CAS.php
@@ -40,10 +40,8 @@
// hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI']
// in IIS
//
-if (php_sapi_name() != 'cli') {
- if (!isset($_SERVER['REQUEST_URI'])) {
- $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
- }
+if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['QUERY_STRING'])) {
+ $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
}
// Add a E_USER_DEPRECATED for php versions <= 5.2
@@ -63,7 +61,7 @@
/**
* phpCAS version. accessible for the user by phpCAS::getVersion().
*/
-define('PHPCAS_VERSION', '1.3.2');
+define('PHPCAS_VERSION', '1.3.5');
/**
* @addtogroup public
@@ -78,6 +76,10 @@
* CAS version 2.0
*/
define("CAS_VERSION_2_0", '2.0');
+/**
+ * CAS version 3.0
+ */
+define("CAS_VERSION_3_0", '3.0');
// ------------------------------------------------------------------------
// SAML defines
@@ -134,6 +136,11 @@
*/
define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
+/**
+ * SAML Attributes
+ */
+define("DEFAULT_ERROR", 'Internal script failure');
+
/** @} */
/**
* @addtogroup publicPGTStorage
@@ -212,6 +219,7 @@
define("PHPCAS_LANG_JAPANESE", 'CAS_Languages_Japanese');
define("PHPCAS_LANG_SPANISH", 'CAS_Languages_Spanish');
define("PHPCAS_LANG_CATALAN", 'CAS_Languages_Catalan');
+define("PHPCAS_LANG_CHINESE_SIMPLIFIED", 'CAS_Languages_ChineseSimplified');
/** @} */
@@ -237,7 +245,13 @@
/**
* The default directory for the debug file under Unix.
*/
-define('DEFAULT_DEBUG_DIR', '/tmp/');
+function gettmpdir() {
+if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
+if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
+if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
+return "/tmp";
+}
+define('DEFAULT_DEBUG_DIR', gettmpdir()."/");
/** @} */
@@ -267,6 +281,7 @@ class phpCAS
/**
* This variable is used by the interface class phpCAS.
*
+ * @var CAS_Client
* @hideinitializer
*/
private static $_PHPCAS_CLIENT;
@@ -286,6 +301,15 @@ class phpCAS
*/
private static $_PHPCAS_DEBUG;
+ /**
+ * This variable is used to enable verbose mode
+ * This pevents debug info to be show to the user. Since it's a security
+ * feature the default is false
+ *
+ * @hideinitializer
+ */
+ private static $_PHPCAS_VERBOSE = false;
+
// ########################################################################
// INITIALIZATION
@@ -313,7 +337,7 @@ class phpCAS
*/
public static function client($server_version, $server_hostname,
$server_port, $server_uri, $changeSessionID = true,
- $service_address = null // Utilisé pour forcer l'URL de base
+ $service_address = null // Utilisé pour forcer l'URL de base
) {
phpCAS :: traceBegin();
if (is_object(self::$_PHPCAS_CLIENT)) {
@@ -342,11 +366,15 @@ public static function client($server_version, $server_hostname,
);
// initialize the object $_PHPCAS_CLIENT
+ try {
self::$_PHPCAS_CLIENT = new CAS_Client(
$server_version, false, $server_hostname, $server_port, $server_uri,
$changeSessionID,
$service_address
- );
+ );
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
+ }
phpCAS :: traceEnd();
}
@@ -395,13 +423,27 @@ public static function proxy($server_version, $server_hostname,
);
// initialize the object $_PHPCAS_CLIENT
- self::$_PHPCAS_CLIENT = new CAS_Client(
- $server_version, true, $server_hostname, $server_port, $server_uri,
- $changeSessionID
- );
+ try {
+ self::$_PHPCAS_CLIENT = new CAS_Client(
+ $server_version, true, $server_hostname, $server_port, $server_uri,
+ $changeSessionID
+ );
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
+ }
phpCAS :: traceEnd();
}
+ /**
+ * Answer whether or not the client or proxy has been initialized
+ *
+ * @return bool
+ */
+ public static function isInitialized ()
+ {
+ return (is_object(self::$_PHPCAS_CLIENT));
+ }
+
/** @} */
// ########################################################################
// DEBUGGING
@@ -449,11 +491,39 @@ public static function setDebug($filename = '')
self::$_PHPCAS_DEBUG['filename'] = $filename;
self::$_PHPCAS_DEBUG['indent'] = 0;
- phpCAS :: trace('START phpCAS-' . PHPCAS_VERSION . ' ******************');
+ phpCAS :: trace('START ('.date("Y-m-d H:i:s").') phpCAS-' . PHPCAS_VERSION . ' ******************');
+ }
+ }
+
+ /**
+ * Enable verbose errors messages in the website output
+ * This is a security relevant since internal status info may leak an may
+ * help an attacker. Default is therefore false
+ *
+ * @param bool $verbose enable verbose output
+ *
+ * @return void
+ */
+ public static function setVerbose($verbose)
+ {
+ if ($verbose === true) {
+ self::$_PHPCAS_VERBOSE = true;
+ } else {
+ self::$_PHPCAS_VERBOSE = false;
}
}
+ /**
+ * Show is verbose mode is on
+ *
+ * @return boot verbose
+ */
+ public static function getVerbose()
+ {
+ return self::$_PHPCAS_VERBOSE;
+ }
+
/**
* Logs a string in debug mode.
*
@@ -498,6 +568,7 @@ public static function log($str)
*/
public static function error($msg)
{
+ phpCAS :: traceBegin();
$dbg = debug_backtrace();
$function = '?';
$file = '?';
@@ -513,8 +584,12 @@ public static function error($msg)
}
}
}
- echo "
\nphpCAS error: " . __CLASS__ . "::" . $function . '(): ' . htmlentities($msg) . " in " . $file . " on line " . $line . "
\n";
- phpCAS :: trace($msg);
+ if (self::$_PHPCAS_VERBOSE) {
+ echo "
\nphpCAS error: " . __CLASS__ . "::" . $function . '(): ' . htmlentities($msg) . " in " . $file . " on line " . $line . "
\n";
+ } else {
+ echo "
\nError: ". DEFAULT_ERROR ."
\n";
+ }
+ phpCAS :: trace($msg . ' in ' . $file . 'on line ' . $line );
phpCAS :: traceEnd();
throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
@@ -534,7 +609,8 @@ public static function trace($str)
}
/**
- * This method is used to indicate the start of the execution of a function in debug mode.
+ * This method is used to indicate the start of the execution of a function
+ * in debug mode.
*
* @return void
*/
@@ -638,13 +714,13 @@ public static function traceExit()
*/
public static function setLang($lang)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (gettype($lang) != 'string') {
- phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setLang($lang);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setLang($lang);
}
/** @} */
@@ -684,13 +760,13 @@ public static function getVersion()
*/
public static function setHTMLHeader($header)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (gettype($header) != 'string') {
- phpCAS :: error('type mismatched for parameter $header (should be `string\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setHTMLHeader($header);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setHTMLHeader($header);
}
/**
@@ -702,13 +778,13 @@ public static function setHTMLHeader($header)
*/
public static function setHTMLFooter($footer)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (gettype($footer) != 'string') {
- phpCAS :: error('type mismatched for parameter $footer (should be `string\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
}
/** @} */
@@ -731,19 +807,13 @@ public static function setHTMLFooter($footer)
public static function setPGTStorage($storage)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
- }
- if ( !($storage instanceof CAS_PGTStorage) ) {
- phpCAS :: error('type mismatched for parameter $storage (should be a CAS_PGTStorage `object\')');
+ phpCAS::_validateProxyExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setPGTStorage($storage);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setPGTStorage($storage);
phpCAS :: traceEnd();
}
@@ -768,25 +838,13 @@ public static function setPGTStorageDb($dsn_or_pdo, $username='',
$password='', $table='', $driver_options=null
) {
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
- }
- if (gettype($username) != 'string') {
- phpCAS :: error('type mismatched for parameter $username (should be `string\')');
- }
- if (gettype($password) != 'string') {
- phpCAS :: error('type mismatched for parameter $password (should be `string\')');
- }
- if (gettype($table) != 'string') {
- phpCAS :: error('type mismatched for parameter $table (should be `string\')');
+ phpCAS::_validateProxyExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
phpCAS :: traceEnd();
}
@@ -801,19 +859,13 @@ public static function setPGTStorageDb($dsn_or_pdo, $username='',
public static function setPGTStorageFile($path = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
- }
- if (gettype($path) != 'string') {
- phpCAS :: error('type mismatched for parameter $path (should be `string\')');
+ phpCAS::_validateProxyExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
phpCAS :: traceEnd();
}
/** @} */
@@ -838,23 +890,13 @@ public static function setPGTStorageFile($path = '')
public static function getProxiedService ($type)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
- }
- if (gettype($type) != 'string') {
- phpCAS :: error('type mismatched for parameter $type (should be `string\')');
- }
+ phpCAS::_validateProxyExists();
- $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
+ try {
+ $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
+ }
phpCAS :: traceEnd();
return $res;
@@ -874,20 +916,13 @@ public static function getProxiedService ($type)
*/
public static function initializeProxiedService (CAS_ProxiedService $proxiedService)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
- }
+ phpCAS::_validateProxyExists();
- self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
+ try {
+ self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
+ }
}
/**
@@ -908,23 +943,13 @@ public static function initializeProxiedService (CAS_ProxiedService $proxiedServ
public static function serviceWeb($url, & $err_code, & $output)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string\')');
- }
+ phpCAS::_validateProxyExists();
- $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
+ try {
+ $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
+ }
phpCAS :: traceEnd($res);
return $res;
@@ -952,28 +977,14 @@ public static function serviceWeb($url, & $err_code, & $output)
public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string\')');
- }
+ phpCAS::_validateProxyExists();
- if (gettype($flags) != 'integer') {
- phpCAS :: error('type mismatched for parameter $flags (should be `integer\')');
+ try {
+ $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
-
phpCAS :: traceEnd($res);
return $res;
}
@@ -1000,13 +1011,32 @@ public static function serviceMail($url, $service, $flags, & $err_code, & $err_m
*/
public static function setCacheTimesForAuthRecheck($n)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (gettype($n) != 'integer') {
- phpCAS :: error('type mismatched for parameter $n (should be `integer\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
+ }
+
+
+ /**
+ * Set a callback function to be run when receiving CAS attributes
+ *
+ * The callback function will be passed an $success_elements
+ * payload of the response (\DOMElement) as its first parameter.
+ *
+ * @param string $function Callback function
+ * @param array $additionalArgs optional array of arguments
+ *
+ * @return void
+ */
+ public static function setCasAttributeParserCallback($function, array $additionalArgs = array())
+ {
+ phpCAS::_validateClientExists();
+
+ self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
}
/**
@@ -1030,9 +1060,7 @@ public static function setCacheTimesForAuthRecheck($n)
*/
public static function setPostAuthenticateCallback ($function, array $additionalArgs = array())
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
}
@@ -1053,9 +1081,7 @@ public static function setPostAuthenticateCallback ($function, array $additional
*/
public static function setSingleSignoutCallback ($function, array $additionalArgs = array())
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
}
@@ -1073,9 +1099,7 @@ public static function setSingleSignoutCallback ($function, array $additionalArg
public static function checkAuthentication()
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
$auth = self::$_PHPCAS_CLIENT->checkAuthentication();
@@ -1096,16 +1120,13 @@ public static function checkAuthentication()
public static function forceAuthentication()
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
-
+ phpCAS::_validateClientExists();
$auth = self::$_PHPCAS_CLIENT->forceAuthentication();
// store where the authentication has been checked and the result
self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
- /* if (!$auth) {
+ /* if (!$auth) {
phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
self::$_PHPCAS_CLIENT->forceAuthentication();
} else {
@@ -1124,9 +1145,8 @@ public static function forceAuthentication()
public static function renewAuthentication()
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
$auth = self::$_PHPCAS_CLIENT->renewAuthentication();
// store where the authentication has been checked and the result
@@ -1145,9 +1165,7 @@ public static function renewAuthentication()
public static function isAuthenticated()
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
// call the isAuthenticated method of the $_PHPCAS_CLIENT object
$auth = self::$_PHPCAS_CLIENT->isAuthenticated();
@@ -1168,9 +1186,8 @@ public static function isAuthenticated()
*/
public static function isSessionAuthenticated()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
}
@@ -1178,65 +1195,56 @@ public static function isSessionAuthenticated()
* This method returns the CAS user's login name.
*
* @return string the login name of the authenticated user
- * @warning should not be called only after phpCAS::forceAuthentication()
+ * @warning should only be called after phpCAS::forceAuthentication()
* or phpCAS::checkAuthentication().
* */
public static function getUser()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
+ phpCAS::_validateClientExists();
+
+ try {
+ return self::$_PHPCAS_CLIENT->getUser();
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- return self::$_PHPCAS_CLIENT->getUser();
}
/**
* Answer attributes about the authenticated user.
*
- * @warning should not be called only after phpCAS::forceAuthentication()
+ * @warning should only be called after phpCAS::forceAuthentication()
* or phpCAS::checkAuthentication().
*
* @return array
*/
public static function getAttributes()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
+ phpCAS::_validateClientExists();
+
+ try {
+ return self::$_PHPCAS_CLIENT->getAttributes();
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- return self::$_PHPCAS_CLIENT->getAttributes();
}
/**
* Answer true if there are attributes for the authenticated user.
*
- * @warning should not be called only after phpCAS::forceAuthentication()
+ * @warning should only be called after phpCAS::forceAuthentication()
* or phpCAS::checkAuthentication().
*
* @return bool
*/
public static function hasAttributes()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
+ phpCAS::_validateClientExists();
+
+ try {
+ return self::$_PHPCAS_CLIENT->hasAttributes();
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- return self::$_PHPCAS_CLIENT->hasAttributes();
}
/**
@@ -1245,21 +1253,18 @@ public static function hasAttributes()
* @param string $key attribute name
*
* @return bool
- * @warning should not be called only after phpCAS::forceAuthentication()
+ * @warning should only be called after phpCAS::forceAuthentication()
* or phpCAS::checkAuthentication().
*/
public static function hasAttribute($key)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
+ phpCAS::_validateClientExists();
+
+ try {
+ return self::$_PHPCAS_CLIENT->hasAttribute($key);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- return self::$_PHPCAS_CLIENT->hasAttribute($key);
}
/**
@@ -1268,21 +1273,18 @@ public static function hasAttribute($key)
* @param string $key attribute name
*
* @return mixed string for a single value or an array if multiple values exist.
- * @warning should not be called only after phpCAS::forceAuthentication()
+ * @warning should only be called after phpCAS::forceAuthentication()
* or phpCAS::checkAuthentication().
*/
public static function getAttribute($key)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
- }
- if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
- phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
+ phpCAS::_validateClientExists();
+
+ try {
+ return self::$_PHPCAS_CLIENT->getAttribute($key);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- return self::$_PHPCAS_CLIENT->getAttribute($key);
}
/**
@@ -1295,9 +1297,8 @@ public static function getAttribute($key)
*/
public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
}
@@ -1309,9 +1310,8 @@ public static function handleLogoutRequests($check_client = true, $allowed_clien
*/
public static function getServerLoginURL()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
return self::$_PHPCAS_CLIENT->getServerLoginURL();
}
@@ -1326,19 +1326,24 @@ public static function getServerLoginURL()
public static function setServerLoginURL($url = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string`)');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setServerLoginURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setServerLoginURL($url);
+
phpCAS :: traceEnd();
}
/**
* Set the serviceValidate URL of the CAS server.
- * Used only in CAS 1.0 validations
+ * Used for all CAS versions of URL validations.
+ * Examples:
+ * CAS 1.0 http://www.exemple.com/validate
+ * CAS 2.0 http://www.exemple.com/validateURL
+ * CAS 3.0 http://www.exemple.com/p3/serviceValidate
*
* @param string $url the serviceValidate URL
*
@@ -1347,19 +1352,24 @@ public static function setServerLoginURL($url = '')
public static function setServerServiceValidateURL($url = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string`)');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
+
phpCAS :: traceEnd();
}
/**
* Set the proxyValidate URL of the CAS server.
- * Used for all CAS 2.0 validations
+ * Used for all CAS versions of proxy URL validations
+ * Examples:
+ * CAS 1.0 http://www.exemple.com/
+ * CAS 2.0 http://www.exemple.com/proxyValidate
+ * CAS 3.0 http://www.exemple.com/p3/proxyValidate
*
* @param string $url the proxyValidate URL
*
@@ -1368,13 +1378,14 @@ public static function setServerServiceValidateURL($url = '')
public static function setServerProxyValidateURL($url = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string`)');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
+
phpCAS :: traceEnd();
}
@@ -1388,13 +1399,14 @@ public static function setServerProxyValidateURL($url = '')
public static function setServerSamlValidateURL($url = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be`string\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
+
phpCAS :: traceEnd();
}
@@ -1406,9 +1418,8 @@ public static function setServerSamlValidateURL($url = '')
*/
public static function getServerLogoutURL()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
return self::$_PHPCAS_CLIENT->getServerLogoutURL();
}
@@ -1423,17 +1434,14 @@ public static function getServerLogoutURL()
public static function setServerLogoutURL($url = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error(
- 'this method should only be called after' . __CLASS__ . '::client()'
- );
- }
- if (gettype($url) != 'string') {
- phpCAS :: error(
- 'type mismatched for parameter $url (should be `string`)'
- );
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
+
phpCAS :: traceEnd();
}
@@ -1448,9 +1456,8 @@ public static function setServerLogoutURL($url = '')
public static function logout($params = "")
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
$parsedParams = array ();
if ($params != "") {
if (is_string($params)) {
@@ -1475,16 +1482,15 @@ public static function logout($params = "")
* This method is used to logout from CAS. Halts by redirecting to the CAS
* server.
*
- * @param service $service a URL that will be transmitted to the CAS server
+ * @param string $service a URL that will be transmitted to the CAS server
*
* @return void
*/
public static function logoutWithRedirectService($service)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
if (!is_string($service)) {
phpCAS :: error('type mismatched for parameter $service (should be `string\')');
}
@@ -1534,9 +1540,8 @@ public static function logoutWithRedirectServiceAndUrl($service, $url)
{
trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
if (!is_string($service)) {
phpCAS :: error('type mismatched for parameter $service (should be `string\')');
}
@@ -1565,16 +1570,14 @@ public static function logoutWithRedirectServiceAndUrl($service, $url)
public static function setFixedCallbackURL($url = '')
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (!self::$_PHPCAS_CLIENT->isProxy()) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string\')');
+ phpCAS::_validateProxyExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setCallbackURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setCallbackURL($url);
+
phpCAS :: traceEnd();
}
@@ -1589,13 +1592,14 @@ public static function setFixedCallbackURL($url = '')
public static function setFixedServiceURL($url)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (gettype($url) != 'string') {
- phpCAS :: error('type mismatched for parameter $url (should be `string\')');
+ phpCAS::_validateProxyExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setURL($url);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setURL($url);
+
phpCAS :: traceEnd();
}
@@ -1606,9 +1610,7 @@ public static function setFixedServiceURL($url)
*/
public static function getServiceURL()
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateProxyExists();
return (self::$_PHPCAS_CLIENT->getURL());
}
@@ -1623,13 +1625,13 @@ public static function getServiceURL()
*/
public static function retrievePT($target_service, & $err_code, & $err_msg)
{
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
- }
- if (gettype($target_service) != 'string') {
- phpCAS :: error('type mismatched for parameter $target_service(should be `string\')');
+ phpCAS::_validateProxyExists();
+
+ try {
+ return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
}
/**
@@ -1644,16 +1646,14 @@ public static function retrievePT($target_service, & $err_code, & $err_msg)
public static function setCasServerCACert($cert, $validate_cn = true)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
- if (gettype($cert) != 'string') {
- phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
- }
- if (gettype($validate_cn) != 'boolean') {
- phpCAS :: error('type mismatched for parameter $validate_cn (should be `boolean\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
+
phpCAS :: traceEnd();
}
@@ -1665,9 +1665,8 @@ public static function setCasServerCACert($cert, $validate_cn = true)
public static function setNoCasServerValidation()
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
phpCAS :: trace('You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
self::$_PHPCAS_CLIENT->setNoCasServerValidation();
phpCAS :: traceEnd();
@@ -1686,9 +1685,8 @@ public static function setNoCasServerValidation()
public static function setNoClearTicketsFromUrl()
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
phpCAS :: traceEnd();
}
@@ -1707,9 +1705,8 @@ public static function setNoClearTicketsFromUrl()
public static function setExtraCurlOption($key, $value)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
+ phpCAS::_validateClientExists();
+
self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
phpCAS :: traceEnd();
}
@@ -1753,11 +1750,12 @@ public static function setExtraCurlOption($key, $value)
public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
- if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0) {
- phpCAS :: error('this method can only be used with the cas 2.0 protool');
+ phpCAS::_validateClientExists();
+
+ if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0
+ && self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_3_0
+ ) {
+ phpCAS :: error('this method can only be used with the cas 2.0/3.0 protocols');
}
self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
phpCAS :: traceEnd();
@@ -1774,9 +1772,7 @@ public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
*/
public static function getProxies ()
{
- if ( !is_object(self::$_PHPCAS_CLIENT) ) {
- phpCAS::error('this method should only be called after '.__CLASS__.'::client()');
- }
+ phpCAS::_validateProxyExists();
return(self::$_PHPCAS_CLIENT->getProxies());
}
@@ -1797,13 +1793,14 @@ public static function addRebroadcastNode($rebroadcastNodeUrl)
{
phpCAS::traceBegin();
phpCAS::log('rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
- }
- if ( !(bool)preg_match("/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i", $rebroadcastNodeUrl)) {
- phpCAS::error('type mismatched for parameter $rebroadcastNodeUrl (should be `url\')');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
+
phpCAS::traceEnd();
}
@@ -1818,14 +1815,55 @@ public static function addRebroadcastNode($rebroadcastNodeUrl)
public static function addRebroadcastHeader($header)
{
phpCAS :: traceBegin();
- if (!is_object(self::$_PHPCAS_CLIENT)) {
- phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
+ phpCAS::_validateClientExists();
+
+ try {
+ self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
+ } catch (Exception $e) {
+ phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
- self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
+
phpCAS :: traceEnd();
}
-}
+ /**
+ * Checks if a client already exists
+ *
+ * @throws CAS_OutOfSequenceBeforeClientException
+ *
+ * @return void
+ */
+ private static function _validateClientExists()
+ {
+ if (!is_object(self::$_PHPCAS_CLIENT)) {
+ throw new CAS_OutOfSequenceBeforeClientException();
+ }
+ }
+
+ /**
+ * Checks of a proxy client aready exists
+ *
+ * @throws CAS_OutOfSequenceBeforeProxyException
+ *
+ * @return void
+ */
+ private static function _validateProxyExists()
+ {
+ if (!is_object(self::$_PHPCAS_CLIENT)) {
+ throw new CAS_OutOfSequenceBeforeProxyException();
+ }
+ }
+
+ /**
+ * For testing purposes, use this method to set the client to a test double
+ *
+ * @return void
+ */
+ public static function setCasClient(\CAS_Client $client)
+ {
+ self::$_PHPCAS_CLIENT = $client;
+ }
+}
// ########################################################################
// DOCUMENTATION
// ########################################################################
diff --git a/lib/CAS/AuthenticationException.php b/lib/CAS/AuthenticationException.php
index 801156e881..1a98d753c3 100755
--- a/lib/CAS/AuthenticationException.php
+++ b/lib/CAS/AuthenticationException.php
@@ -68,39 +68,43 @@ class CAS_AuthenticationException
public function __construct($client,$failure,$cas_url,$no_response,
$bad_response='',$cas_response='',$err_code='',$err_msg=''
) {
+ $messages = array();
phpCAS::traceBegin();
$lang = $client->getLangObj();
$client->printHTMLHeader($lang->getAuthenticationFailed());
printf(
$lang->getYouWereNotAuthenticated(),
htmlentities($client->getURL()),
- $_SERVER['SERVER_ADMIN']
+ isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN']:''
);
- phpCAS::trace('CAS URL: '.$cas_url);
- phpCAS::trace('Authentication failure: '.$failure);
+ phpCAS::trace($messages[] = 'CAS URL: '.$cas_url);
+ phpCAS::trace($messages[] = 'Authentication failure: '.$failure);
if ( $no_response ) {
- phpCAS::trace('Reason: no response from the CAS server');
+ phpCAS::trace($messages[] = 'Reason: no response from the CAS server');
} else {
if ( $bad_response ) {
- phpCAS::trace('Reason: bad response from the CAS server');
+ phpCAS::trace($messages[] = 'Reason: bad response from the CAS server');
} else {
switch ($client->getServerVersion()) {
case CAS_VERSION_1_0:
- phpCAS::trace('Reason: CAS error');
+ phpCAS::trace($messages[] = 'Reason: CAS error');
break;
case CAS_VERSION_2_0:
+ case CAS_VERSION_3_0:
if ( empty($err_code) ) {
- phpCAS::trace('Reason: no CAS error');
+ phpCAS::trace($messages[] = 'Reason: no CAS error');
} else {
- phpCAS::trace('Reason: ['.$err_code.'] CAS error: '.$err_msg);
+ phpCAS::trace($messages[] = 'Reason: ['.$err_code.'] CAS error: '.$err_msg);
}
break;
}
}
- phpCAS::trace('CAS response: '.$cas_response);
+ phpCAS::trace($messages[] = 'CAS response: '.$cas_response);
}
$client->printHTMLFooter();
phpCAS::traceExit();
+
+ parent::__construct(implode("\n", $messages));
}
}
diff --git a/lib/CAS/Autoload.php b/lib/CAS/Autoload.php
index c7d436e199..e56dbdfa93 100755
--- a/lib/CAS/Autoload.php
+++ b/lib/CAS/Autoload.php
@@ -25,35 +25,39 @@ function CAS_autoload($class)
{
// Static to hold the Include Path to CAS
static $include_path;
- // Setup the include path if it's not already set from a previous call
- if (!$include_path) {
- $include_path = dirname(dirname(__FILE__));
- }
+ // Check only for CAS classes
if (substr($class, 0, 4) !== 'CAS_') {
return false;
}
+ // Setup the include path if it's not already set from a previous call
+ if (empty($include_path)) {
+ $include_path = array(dirname(dirname(__FILE__)), dirname(dirname(__FILE__)) . '/../test/' );
+ }
+
// Declare local variable to store the expected full path to the file
- $file_path = $include_path . '/' . str_replace('_', '/', $class) . '.php';
- $fp = @fopen($file_path, 'r', true);
- if ($fp) {
- fclose($fp);
- include $file_path;
- if (!class_exists($class, false) && !interface_exists($class, false)) {
- die(
- new Exception(
- 'Class ' . $class . ' was not present in ' .
- $file_path .
- ' [CAS_autoload]'
- )
- );
+ foreach ($include_path as $path) {
+ $file_path = $path . '/' . str_replace('_', '/', $class) . '.php';
+ $fp = @fopen($file_path, 'r', true);
+ if ($fp) {
+ fclose($fp);
+ include $file_path;
+ if (!class_exists($class, false) && !interface_exists($class, false)) {
+ die(
+ new Exception(
+ 'Class ' . $class . ' was not present in ' .
+ $file_path .
+ ' [CAS_autoload]'
+ )
+ );
+ }
+ return true;
}
- return true;
}
$e = new Exception(
'Class ' . $class . ' could not be loaded from ' .
$file_path . ', file does not exist (Path="'
- . $include_path .'") [CAS_autoload]'
+ . implode(':', $include_path) .'") [CAS_autoload]'
);
$trace = $e->getTrace();
if (isset($trace[2]) && isset($trace[2]['function'])
@@ -71,9 +75,13 @@ function CAS_autoload($class)
// set up __autoload
if (function_exists('spl_autoload_register')) {
- if (!(spl_autoload_functions()) || !in_array('CAS_autoload', spl_autoload_functions())) {
+ if (!(spl_autoload_functions())
+ || !in_array('CAS_autoload', spl_autoload_functions())
+ ) {
spl_autoload_register('CAS_autoload');
- if (function_exists('__autoload') && !in_array('__autoload', spl_autoload_functions())) {
+ if (function_exists('__autoload')
+ && !in_array('__autoload', spl_autoload_functions())
+ ) {
// __autoload() was being used, but now would be ignored, add
// it to the autoload stack
spl_autoload_register('__autoload');
diff --git a/lib/CAS/Client.php b/lib/CAS/Client.php
index d7bf1e11f1..662a0a111d 100755
--- a/lib/CAS/Client.php
+++ b/lib/CAS/Client.php
@@ -131,9 +131,11 @@ public function printHTMLFooter()
$lang = $this->getLangObj();
$this->_htmlFilterOutput(
empty($this->_output_footer)?
- ('
phpCAS __PHPCAS_VERSION__ '
- .$lang->getUsingServer()
- .' __SERVER_BASE_URL__ (CAS __CAS_VERSION__)