MDL-46766 auth_cas: Upgrading to phpCAS 1.3.3

This commit is contained in:
Eric Merrill 2014-08-11 13:28:13 -04:00 committed by Damyon Wiese
parent d9ff93e36e
commit 97531d3929
25 changed files with 1399 additions and 661 deletions

View File

@ -63,7 +63,7 @@ if (!defined('E_USER_DEPRECATED')) {
/**
* phpCAS version. accessible for the user by phpCAS::getVersion().
*/
define('PHPCAS_VERSION', '1.3.2');
define('PHPCAS_VERSION', '1.3.3');
/**
* @addtogroup public
@ -78,6 +78,10 @@ define("CAS_VERSION_1_0", '1.0');
* CAS version 2.0
*/
define("CAS_VERSION_2_0", '2.0');
/**
* CAS version 3.0
*/
define("CAS_VERSION_3_0", '3.0');
// ------------------------------------------------------------------------
// SAML defines
@ -318,18 +322,6 @@ class phpCAS
if (is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
}
if (gettype($server_version) != 'string') {
phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
}
if (gettype($server_hostname) != 'string') {
phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
}
if (gettype($server_port) != 'integer') {
phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
}
if (gettype($server_uri) != 'string') {
phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
}
// store where the initializer is called from
$dbg = debug_backtrace();
@ -341,10 +333,14 @@ class phpCAS
);
// initialize the object $_PHPCAS_CLIENT
self::$_PHPCAS_CLIENT = new CAS_Client(
$server_version, false, $server_hostname, $server_port, $server_uri,
$changeSessionID
);
try {
self::$_PHPCAS_CLIENT = new CAS_Client(
$server_version, false, $server_hostname, $server_port, $server_uri,
$changeSessionID
);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
}
@ -370,18 +366,6 @@ class phpCAS
if (is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
}
if (gettype($server_version) != 'string') {
phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
}
if (gettype($server_hostname) != 'string') {
phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
}
if (gettype($server_port) != 'integer') {
phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
}
if (gettype($server_uri) != 'string') {
phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
}
// store where the initialzer is called from
$dbg = debug_backtrace();
@ -393,10 +377,14 @@ class phpCAS
);
// 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();
}
@ -636,13 +624,13 @@ class phpCAS
*/
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()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setLang($lang);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($lang) != 'string') {
phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
}
self::$_PHPCAS_CLIENT->setLang($lang);
}
/** @} */
@ -682,13 +670,13 @@ class phpCAS
*/
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()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setHTMLHeader($header);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($header) != 'string') {
phpCAS :: error('type mismatched for parameter $header (should be `string\')');
}
self::$_PHPCAS_CLIENT->setHTMLHeader($header);
}
/**
@ -700,13 +688,13 @@ class phpCAS
*/
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()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($footer) != 'string') {
phpCAS :: error('type mismatched for parameter $footer (should be `string\')');
}
self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
}
/** @} */
@ -729,19 +717,13 @@ class phpCAS
public static function setPGTStorage($storage)
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setPGTStorage($storage);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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\')');
}
self::$_PHPCAS_CLIENT->setPGTStorage($storage);
phpCAS :: traceEnd();
}
@ -766,25 +748,13 @@ class phpCAS
$password='', $table='', $driver_options=null
) {
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
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());
}
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\')');
}
self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
phpCAS :: traceEnd();
}
@ -799,19 +769,13 @@ class phpCAS
public static function setPGTStorageFile($path = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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\')');
}
self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
phpCAS :: traceEnd();
}
/** @} */
@ -836,23 +800,13 @@ class phpCAS
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;
@ -872,20 +826,13 @@ class phpCAS
*/
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());
}
}
/**
@ -906,23 +853,13 @@ class phpCAS
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;
@ -950,28 +887,14 @@ class phpCAS
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;
}
@ -998,13 +921,13 @@ class phpCAS
*/
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()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($n) != 'integer') {
phpCAS :: error('type mismatched for parameter $n (should be `integer\')');
}
self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
}
/**
@ -1028,9 +951,7 @@ class phpCAS
*/
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);
}
@ -1051,9 +972,7 @@ class phpCAS
*/
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);
}
@ -1071,9 +990,7 @@ class phpCAS
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();
@ -1094,16 +1011,13 @@ class phpCAS
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 {
@ -1122,9 +1036,8 @@ class phpCAS
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
@ -1143,9 +1056,7 @@ class phpCAS
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();
@ -1166,9 +1077,8 @@ class phpCAS
*/
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());
}
@ -1176,65 +1086,56 @@ class phpCAS
* 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()');
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->getUser();
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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');
}
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()');
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->getAttributes();
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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');
}
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()');
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->hasAttributes();
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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');
}
return self::$_PHPCAS_CLIENT->hasAttributes();
}
/**
@ -1243,21 +1144,18 @@ class phpCAS
* @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()');
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->hasAttribute($key);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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');
}
return self::$_PHPCAS_CLIENT->hasAttribute($key);
}
/**
@ -1266,21 +1164,18 @@ class phpCAS
* @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()');
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->getAttribute($key);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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');
}
return self::$_PHPCAS_CLIENT->getAttribute($key);
}
/**
@ -1293,9 +1188,8 @@ class phpCAS
*/
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));
}
@ -1307,9 +1201,8 @@ class phpCAS
*/
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();
}
@ -1324,13 +1217,14 @@ class phpCAS
public static function setServerLoginURL($url = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerLoginURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($url) != 'string') {
phpCAS :: error('type mismatched for parameter $url (should be `string`)');
}
self::$_PHPCAS_CLIENT->setServerLoginURL($url);
phpCAS :: traceEnd();
}
@ -1345,13 +1239,14 @@ class phpCAS
public static function setServerServiceValidateURL($url = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($url) != 'string') {
phpCAS :: error('type mismatched for parameter $url (should be `string`)');
}
self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
phpCAS :: traceEnd();
}
@ -1366,13 +1261,14 @@ class phpCAS
public static function setServerProxyValidateURL($url = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($url) != 'string') {
phpCAS :: error('type mismatched for parameter $url (should be `string`)');
}
self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
phpCAS :: traceEnd();
}
@ -1386,13 +1282,14 @@ class phpCAS
public static function setServerSamlValidateURL($url = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($url) != 'string') {
phpCAS :: error('type mismatched for parameter $url (should be`string\')');
}
self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
phpCAS :: traceEnd();
}
@ -1404,9 +1301,8 @@ class phpCAS
*/
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();
}
@ -1421,17 +1317,14 @@ class phpCAS
public static function setServerLogoutURL($url = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error(
'this method should only be called after' . __CLASS__ . '::client()'
);
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($url) != 'string') {
phpCAS :: error(
'type mismatched for parameter $url (should be `string`)'
);
}
self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
phpCAS :: traceEnd();
}
@ -1446,9 +1339,8 @@ class phpCAS
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)) {
@ -1480,9 +1372,8 @@ class phpCAS
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\')');
}
@ -1532,9 +1423,8 @@ class phpCAS
{
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\')');
}
@ -1563,16 +1453,14 @@ class phpCAS
public static function setFixedCallbackURL($url = '')
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setCallbackURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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\')');
}
self::$_PHPCAS_CLIENT->setCallbackURL($url);
phpCAS :: traceEnd();
}
@ -1587,13 +1475,14 @@ class phpCAS
public static function setFixedServiceURL($url)
{
phpCAS :: traceBegin();
if (!is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($url) != 'string') {
phpCAS :: error('type mismatched for parameter $url (should be `string\')');
}
self::$_PHPCAS_CLIENT->setURL($url);
phpCAS :: traceEnd();
}
@ -1604,9 +1493,7 @@ class phpCAS
*/
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());
}
@ -1621,13 +1508,13 @@ class phpCAS
*/
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()');
phpCAS::_validateProxyExists();
try {
return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
if (gettype($target_service) != 'string') {
phpCAS :: error('type mismatched for parameter $target_service(should be `string\')');
}
return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
}
/**
@ -1642,16 +1529,14 @@ class phpCAS
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()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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\')');
}
self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
phpCAS :: traceEnd();
}
@ -1663,9 +1548,8 @@ class phpCAS
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();
@ -1684,9 +1568,8 @@ class phpCAS
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();
}
@ -1705,9 +1588,8 @@ class phpCAS
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();
}
@ -1751,11 +1633,11 @@ class phpCAS
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();
@ -1772,9 +1654,7 @@ class phpCAS
*/
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());
}
@ -1795,13 +1675,14 @@ class phpCAS
{
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()');
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
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\')');
}
self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
phpCAS::traceEnd();
}
@ -1816,14 +1697,45 @@ class phpCAS
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();
}
}
}
// ########################################################################
// DOCUMENTATION
// ########################################################################

View File

@ -74,7 +74,7 @@ implements CAS_Exception
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);
@ -89,6 +89,7 @@ implements CAS_Exception
phpCAS::trace('Reason: CAS error');
break;
case CAS_VERSION_2_0:
case CAS_VERSION_3_0:
if ( empty($err_code) ) {
phpCAS::trace('Reason: no CAS error');
} else {

View File

@ -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;
}
// Declare local variable to store the expected full path to the file
$file_path = $include_path . '/' . str_replace('_', '/', $class) . '.php';
// 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/' );
}
$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]'
)
);
// Declare local variable to store the expected full path to the file
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');

File diff suppressed because it is too large Load Diff

View File

@ -161,7 +161,9 @@ class CAS_CookieJar
protected function parseCookieHeader ($line, $defaultDomain)
{
if (!$defaultDomain) {
throw new CAS_InvalidArgumentException('$defaultDomain was not provided.');
throw new CAS_InvalidArgumentException(
'$defaultDomain was not provided.'
);
}
// Set our default values
@ -315,10 +317,14 @@ class CAS_CookieJar
protected function cookieMatchesTarget ($cookie, $target)
{
if (!is_array($target)) {
throw new CAS_InvalidArgumentException('$target must be an array of URL attributes as generated by parse_url().');
throw new CAS_InvalidArgumentException(
'$target must be an array of URL attributes as generated by parse_url().'
);
}
if (!isset($target['host'])) {
throw new CAS_InvalidArgumentException('$target must be an array of URL attributes as generated by parse_url().');
throw new CAS_InvalidArgumentException(
'$target must be an array of URL attributes as generated by parse_url().'
);
}
// Verify that the scheme matches
@ -352,15 +358,17 @@ class CAS_CookieJar
}
}
} else {
// If the cookie host doesn't begin with '.', the host must case-insensitive
// match exactly
// If the cookie host doesn't begin with '.',
// the host must case-insensitive match exactly
if (strcasecmp($target['host'], $cookie['domain']) !== 0) {
return false;
}
}
// Verify that the port matches
if (isset($cookie['ports']) && !in_array($target['port'], $cookie['ports'])) {
if (isset($cookie['ports'])
&& !in_array($target['port'], $cookie['ports'])
) {
return false;
}

View File

@ -99,7 +99,7 @@ class CAS_Languages_German implements CAS_Languages_LanguageInterface
*/
public function getYouWereNotAuthenticated()
{
return '<p>Sie wurden nicht angemeldet.</p><p>Um es erneut zu versuchen klicken Sie <a href="%s">hier</a>.</p><p>Wenn das Problem bestehen bleibt, kontkatieren Sie den <a href="mailto:%s">Administrator</a> dieser Seite.</p>';
return '<p>Sie wurden nicht angemeldet.</p><p>Um es erneut zu versuchen klicken Sie <a href="%s">hier</a>.</p><p>Wenn das Problem bestehen bleibt, kontaktieren Sie den <a href="mailto:%s">Administrator</a> dieser Seite.</p>';
}
/**
@ -113,4 +113,4 @@ class CAS_Languages_German implements CAS_Languages_LanguageInterface
}
}
?>
?>

View File

@ -0,0 +1,56 @@
<?php
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* PHP Version 5
*
* @file CAS/OutOfSequenceBeforeAuthenticationCallException.php
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
/**
* This class defines Exceptions that should be thrown when the sequence of
* operations is invalid. In this case it should be thrown when an
* authentication call has not yet happened.
*
* @class CAS_OutOfSequenceBeforeAuthenticationCallException
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class CAS_OutOfSequenceBeforeAuthenticationCallException
extends CAS_OutOfSequenceException
implements CAS_Exception
{
/**
* Return standard error meessage
*
* @return void
*/
public function __construct ()
{
parent::__construct('An authentication call hasn\'t happened yet.');
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* PHP Version 5
*
* @file CAS/OutOfSequenceBeforeClientException.php
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
/**
* This class defines Exceptions that should be thrown when the sequence of
* operations is invalid. In this case it should be thrown when the client() or
* proxy() call has not yet happened and no client or proxy object exists.
*
* @class CAS_OutOfSequenceBeforeClientException
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class CAS_OutOfSequenceBeforeClientException
extends CAS_OutOfSequenceException
implements CAS_Exception
{
/**
* Return standard error message
*
* @return void
*/
public function __construct ()
{
parent::__construct(
'this method cannot be called before phpCAS::client() or phpCAS::proxy()'
);
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* PHP Version 5
*
* @file CAS/OutOfSequenceBeforeProxyException.php
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
/**
* This class defines Exceptions that should be thrown when the sequence of
* operations is invalid. In this case it should be thrown when the proxy() call
* has not yet happened and no proxy object exists.
*
* @class CAS_OutOfSequenceBeforeProxyException
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class CAS_OutOfSequenceBeforeProxyException
extends CAS_OutOfSequenceException
implements CAS_Exception
{
/**
* Return standard error message
*
* @return void
*/
public function __construct ()
{
parent::__construct(
'this method cannot be called before phpCAS::proxy()'
);
}
}

View File

@ -68,7 +68,9 @@ abstract class CAS_PGTStorage_AbstractStorage
{
phpCAS::traceBegin();
if ( !$cas_parent->isProxy() ) {
phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy');
phpCAS::error(
'defining PGT storage makes no sense when not using a CAS proxy'
);
}
phpCAS::traceEnd();
}

View File

@ -135,8 +135,10 @@ class CAS_PGTStorage_Db extends CAS_PGTStorage_AbstractStorage
* @param string $driver_options any driver options to use when
* connecting to the database
*/
public function __construct($cas_parent, $dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
{
public function __construct(
$cas_parent, $dsn_or_pdo, $username='', $password='', $table='',
$driver_options=null
) {
phpCAS::traceBegin();
// call the ancestor's constructor
parent::__construct($cas_parent);
@ -188,7 +190,10 @@ class CAS_PGTStorage_Db extends CAS_PGTStorage_AbstractStorage
// create the PDO object if it doesn't exist already
if (!($this->_pdo instanceof PDO)) {
try {
$this->_pdo = new PDO($this->_dsn, $this->_username, $this->_password, $this->_driver_options);
$this->_pdo = new PDO(
$this->_dsn, $this->_username, $this->_password,
$this->_driver_options
);
}
catch(PDOException $e) {
phpCAS::error('Database connection error: ' . $e->getMessage());
@ -247,23 +252,28 @@ class CAS_PGTStorage_Db extends CAS_PGTStorage_AbstractStorage
*/
protected function createTableSql()
{
return 'CREATE TABLE ' . $this->_getTable() . ' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)';
return 'CREATE TABLE ' . $this->_getTable()
. ' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)';
}
/**
* This method returns the query used to store a pgt
*
* @return the store PGT SQL, :pgt and :pgt_iou are the bind params contained in the query
* @return the store PGT SQL, :pgt and :pgt_iou are the bind params contained
* in the query
*/
protected function storePgtSql()
{
return 'INSERT INTO ' . $this->_getTable() . ' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)';
return 'INSERT INTO ' . $this->_getTable()
. ' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)';
}
/**
* This method returns the query used to retrieve a pgt. the first column of the first row should contain the pgt
* This method returns the query used to retrieve a pgt. the first column
* of the first row should contain the pgt
*
* @return the retrieve PGT SQL, :pgt_iou is the only bind param contained in the query
* @return the retrieve PGT SQL, :pgt_iou is the only bind param contained
* in the query
*/
protected function retrievePgtSql()
{
@ -273,7 +283,8 @@ class CAS_PGTStorage_Db extends CAS_PGTStorage_AbstractStorage
/**
* This method returns the query used to delete a pgt.
*
* @return the delete PGT SQL, :pgt_iou is the only bind param contained in the query
* @return the delete PGT SQL, :pgt_iou is the only bind param contained in
* the query
*/
protected function deletePgtSql()
{

View File

@ -55,15 +55,20 @@ implements CAS_ProxiedService, CAS_ProxiedService_Testable
*
* @return void
* @throws InvalidArgumentException If the $proxyTicket is invalid.
* @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
* @throws CAS_OutOfSequenceException If called after a proxy ticket has
* already been initialized/set.
*/
public function setProxyTicket ($proxyTicket)
{
if (empty($proxyTicket)) {
throw new CAS_InvalidArgumentException("Trying to initialize with an empty proxy ticket.");
throw new CAS_InvalidArgumentException(
'Trying to initialize with an empty proxy ticket.'
);
}
if (!empty($this->_proxyTicket)) {
throw new CAS_OutOfSequenceException('Already initialized, cannot change the proxy ticket.');
throw new CAS_OutOfSequenceException(
'Already initialized, cannot change the proxy ticket.'
);
}
$this->_proxyTicket = $proxyTicket;
}
@ -78,7 +83,9 @@ implements CAS_ProxiedService, CAS_ProxiedService_Testable
protected function getProxyTicket ()
{
if (empty($this->_proxyTicket)) {
throw new CAS_OutOfSequenceException('No proxy ticket yet. Call $this->initializeProxyTicket() to aquire the proxy ticket.');
throw new CAS_OutOfSequenceException(
'No proxy ticket yet. Call $this->initializeProxyTicket() to aquire the proxy ticket.'
);
}
return $this->_proxyTicket;
@ -105,7 +112,9 @@ implements CAS_ProxiedService, CAS_ProxiedService_Testable
public function setCasClient (CAS_Client $casClient)
{
if (!empty($this->_proxyTicket)) {
throw new CAS_OutOfSequenceException('Already initialized, cannot change the CAS_Client.');
throw new CAS_OutOfSequenceException(
'Already initialized, cannot change the CAS_Client.'
);
}
$this->_casClient = $casClient;
@ -124,7 +133,9 @@ implements CAS_ProxiedService, CAS_ProxiedService_Testable
protected function initializeProxyTicket()
{
if (!empty($this->_proxyTicket)) {
throw new CAS_OutOfSequenceException('Already initialized, cannot initialize again.');
throw new CAS_OutOfSequenceException(
'Already initialized, cannot initialize again.'
);
}
// Allow usage of a particular CAS_Client for unit testing.
if (empty($this->_casClient)) {

View File

@ -38,9 +38,8 @@
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
abstract class CAS_ProxiedService_Http_Abstract
extends CAS_ProxiedService_Abstract
implements CAS_ProxiedService_Http
abstract class CAS_ProxiedService_Http_Abstract extends
CAS_ProxiedService_Abstract implements CAS_ProxiedService_Http
{
/**
* The HTTP request mechanism talking to the target service.
@ -64,8 +63,9 @@ implements CAS_ProxiedService_Http
*
* @return void
*/
public function __construct (CAS_Request_RequestInterface $requestHandler, CAS_CookieJar $cookieJar)
{
public function __construct(CAS_Request_RequestInterface $requestHandler,
CAS_CookieJar $cookieJar
) {
$this->requestHandler = $requestHandler;
$this->_cookieJar = $cookieJar;
}
@ -82,10 +82,12 @@ implements CAS_ProxiedService_Http
* @return string
* @throws Exception If no service url is available.
*/
public function getServiceUrl ()
public function getServiceUrl()
{
if (empty($this->_url)) {
throw new CAS_ProxiedService_Exception('No URL set via '.get_class($this).'->setUrl($url).');
throw new CAS_ProxiedService_Exception(
'No URL set via ' . get_class($this) . '->setUrl($url).'
);
}
return $this->_url;
@ -93,7 +95,7 @@ implements CAS_ProxiedService_Http
/*********************************************************
* Configure the Request
*********************************************************/
*********************************************************/
/**
* Set the URL of the Request
@ -103,10 +105,12 @@ implements CAS_ProxiedService_Http
* @return void
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
*/
public function setUrl ($url)
public function setUrl($url)
{
if ($this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot set the URL, request already sent.');
throw new CAS_OutOfSequenceException(
'Cannot set the URL, request already sent.'
);
}
if (!is_string($url)) {
throw new CAS_InvalidArgumentException('$url must be a string.');
@ -117,7 +121,7 @@ implements CAS_ProxiedService_Http
/*********************************************************
* 2. Send the Request
*********************************************************/
*********************************************************/
/**
* Perform the request.
@ -132,10 +136,12 @@ implements CAS_ProxiedService_Http
* @throws CAS_ProxiedService_Exception If there is a failure sending the
* request to the target service.
*/
public function send ()
public function send()
{
if ($this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot send, request already sent.');
throw new CAS_OutOfSequenceException(
'Cannot send, request already sent.'
);
}
phpCAS::traceBegin();
@ -144,9 +150,9 @@ implements CAS_ProxiedService_Http
$this->initializeProxyTicket();
$url = $this->getServiceUrl();
if (strstr($url, '?') === false) {
$url = $url.'?ticket='.$this->getProxyTicket();
$url = $url . '?ticket=' . $this->getProxyTicket();
} else {
$url = $url.'&ticket='.$this->getProxyTicket();
$url = $url . '&ticket=' . $this->getProxyTicket();
}
try {
@ -199,7 +205,7 @@ implements CAS_ProxiedService_Http
* @throws CAS_ProxiedService_Exception If there is a failure sending the
* request to the target service.
*/
protected function makeRequest ($url)
protected function makeRequest($url)
{
// Verify that we are not in a redirect loop
$this->_numRequests++;
@ -220,9 +226,10 @@ implements CAS_ProxiedService_Http
$this->populateRequest($request);
// Perform the request.
phpCAS::trace('Performing proxied service request to \''.$url.'\'');
phpCAS::trace('Performing proxied service request to \'' . $url . '\'');
if (!$request->send()) {
$message = 'Could not perform proxied service request to URL`'.$url.'\'. '.$request->getErrorMessage();
$message = 'Could not perform proxied service request to URL`'
. $url . '\'. ' . $request->getErrorMessage();
phpCAS::trace($message);
throw new CAS_ProxiedService_Exception($message);
}
@ -231,8 +238,9 @@ implements CAS_ProxiedService_Http
$this->_cookieJar->storeCookies($url, $request->getResponseHeaders());
// Follow any redirects
if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())) {
phpCAS :: trace('Found redirect:'.$redirectUrl);
if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())
) {
phpCAS::trace('Found redirect:' . $redirectUrl);
$this->makeRequest($redirectUrl);
} else {
@ -249,7 +257,9 @@ implements CAS_ProxiedService_Http
*
* @return void
*/
abstract protected function populateRequest (CAS_Request_RequestInterface $request);
abstract protected function populateRequest(
CAS_Request_RequestInterface $request
);
/**
* Answer a redirect URL if a redirect header is found, otherwise null.
@ -258,11 +268,12 @@ implements CAS_ProxiedService_Http
*
* @return string or null
*/
protected function getRedirectUrl (array $responseHeaders)
protected function getRedirectUrl(array $responseHeaders)
{
// Check for the redirect after authentication
foreach ($responseHeaders as $header) {
if (preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/', $header, $matches)) {
if ( preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/', $header, $matches)
) {
return trim(array_pop($matches));
}
}
@ -271,14 +282,14 @@ implements CAS_ProxiedService_Http
/*********************************************************
* 3. Access the response
*********************************************************/
*********************************************************/
/**
* Answer true if our request has been sent yet.
*
* @return bool
*/
protected function hasBeenSent ()
protected function hasBeenSent()
{
return ($this->_numRequests > 0);
}
@ -289,10 +300,12 @@ implements CAS_ProxiedService_Http
* @return array An array of header strings.
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
*/
public function getResponseHeaders ()
public function getResponseHeaders()
{
if (!$this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
throw new CAS_OutOfSequenceException(
'Cannot access response, request not sent yet.'
);
}
return $this->_responseHeaders;
@ -304,10 +317,12 @@ implements CAS_ProxiedService_Http
* @return int
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
*/
public function getResponseStatusCode ()
public function getResponseStatusCode()
{
if (!$this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
throw new CAS_OutOfSequenceException(
'Cannot access response, request not sent yet.'
);
}
return $this->_responseStatusCode;
@ -319,10 +334,12 @@ implements CAS_ProxiedService_Http
* @return string
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
*/
public function getResponseBody ()
public function getResponseBody()
{
if (!$this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
throw new CAS_OutOfSequenceException(
'Cannot access response, request not sent yet.'
);
}
return $this->_responseBody;
@ -334,7 +351,7 @@ implements CAS_ProxiedService_Http
*
* @return array An array containing cookies. E.g. array('name' => 'val');
*/
public function getCookies ()
public function getCookies()
{
return $this->_cookieJar->getCookies($this->getServiceUrl());
}

View File

@ -32,30 +32,31 @@
*
* Usage Example:
*
* try {
* $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
* $service->setUrl('http://www.example.com/path/');
* $service->send();
* if ($service->getResponseStatusCode() == 200)
* return $service->getResponseBody();
* else
* // The service responded with an error code 404, 500, etc.
* throw new Exception('The service responded with an error.');
* try {
* $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
* $service->setUrl('http://www.example.com/path/');
* $service->send();
* if ($service->getResponseStatusCode() == 200)
* return $service->getResponseBody();
* else
* // The service responded with an error code 404, 500, etc.
* throw new Exception('The service responded with an error.');
*
* } catch (CAS_ProxyTicketException $e) {
* if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE)
* return "Your login has timed out. You need to log in again.";
* else
* // Other proxy ticket errors are from bad request format (shouldn't happen)
* // or CAS server failure (unlikely) so lets just stop if we hit those.
* throw $e;
* } catch (CAS_ProxiedService_Exception $e) {
* // Something prevented the service request from being sent or received.
* // We didn't even get a valid error response (404, 500, etc), so this
* // might be caused by a network error or a DNS resolution failure.
* // We could handle it in some way, but for now we will just stop.
* throw $e;
* }
* } catch (CAS_ProxyTicketException $e) {
* if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE)
* return "Your login has timed out. You need to log in again.";
* else
* // Other proxy ticket errors are from bad request format
* // (shouldn't happen) or CAS server failure (unlikely)
* // so lets just stop if we hit those.
* throw $e;
* } catch (CAS_ProxiedService_Exception $e) {
* // Something prevented the service request from being sent or received.
* // We didn't even get a valid error response (404, 500, etc), so this
* // might be caused by a network error or a DNS resolution failure.
* // We could handle it in some way, but for now we will just stop.
* throw $e;
* }
*
* @class CAS_ProxiedService_Http_Get
* @category Authentication

View File

@ -32,32 +32,33 @@
*
* Usage Example:
*
* try {
* $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_POST);
* $service->setUrl('http://www.example.com/path/');
* $service->setContentType('text/xml');
* $service->setBody(''<?xml version="1.0"?'.'><methodCall><methodName>example.search</methodName></methodCall>');
* $service->send();
* if ($service->getResponseStatusCode() == 200)
* return $service->getResponseBody();
* else
* // The service responded with an error code 404, 500, etc.
* throw new Exception('The service responded with an error.');
* try {
* $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_POST);
* $service->setUrl('http://www.example.com/path/');
* $service->setContentType('text/xml');
* $service->setBody('<?xml version="1.0"?'.'><methodCall><methodName>example.search</methodName></methodCall>');
* $service->send();
* if ($service->getResponseStatusCode() == 200)
* return $service->getResponseBody();
* else
* // The service responded with an error code 404, 500, etc.
* throw new Exception('The service responded with an error.');
*
* } catch (CAS_ProxyTicketException $e) {
* if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE)
* return "Your login has timed out. You need to log in again.";
* else
* // Other proxy ticket errors are from bad request format (shouldn't happen)
* // or CAS server failure (unlikely) so lets just stop if we hit those.
* throw $e;
* } catch (CAS_ProxiedService_Exception $e) {
* // Something prevented the service request from being sent or received.
* // We didn't even get a valid error response (404, 500, etc), so this
* // might be caused by a network error or a DNS resolution failure.
* // We could handle it in some way, but for now we will just stop.
* throw $e;
* }
* } catch (CAS_ProxyTicketException $e) {
* if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE)
* return "Your login has timed out. You need to log in again.";
* else
* // Other proxy ticket errors are from bad request format
* // (shouldn't happen) or CAS server failure (unlikely) so lets just
* // stop if we hit those.
* throw $e;
* } catch (CAS_ProxiedService_Exception $e) {
* // Something prevented the service request from being sent or received.
* // We didn't even get a valid error response (404, 500, etc), so this
* // might be caused by a network error or a DNS resolution failure.
* // We could handle it in some way, but for now we will just stop.
* throw $e;
* }
*
* @class CAS_ProxiedService_Http_Post
* @category Authentication
@ -95,7 +96,9 @@ extends CAS_ProxiedService_Http_Abstract
public function setContentType ($contentType)
{
if ($this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot set the content type, request already sent.');
throw new CAS_OutOfSequenceException(
'Cannot set the content type, request already sent.'
);
}
$this->_contentType = $contentType;
@ -112,7 +115,9 @@ extends CAS_ProxiedService_Http_Abstract
public function setBody ($body)
{
if ($this->hasBeenSent()) {
throw new CAS_OutOfSequenceException('Cannot set the body, request already sent.');
throw new CAS_OutOfSequenceException(
'Cannot set the body, request already sent.'
);
}
$this->_body = $body;
@ -128,7 +133,10 @@ extends CAS_ProxiedService_Http_Abstract
protected function populateRequest (CAS_Request_RequestInterface $request)
{
if (empty($this->_contentType) && !empty($this->_body)) {
throw new CAS_ProxiedService_Exception("If you pass a POST body, you must specify a content type via ".get_class($this).'->setContentType($contentType).');
throw new CAS_ProxiedService_Exception(
"If you pass a POST body, you must specify a content type via "
.get_class($this).'->setContentType($contentType).'
);
}
$request->makePost();

View File

@ -79,7 +79,9 @@ extends CAS_ProxiedService_Abstract
public function getServiceUrl ()
{
if (empty($this->_url)) {
throw new CAS_ProxiedService_Exception('No URL set via '.get_class($this).'->getServiceUrl($url).');
throw new CAS_ProxiedService_Exception(
'No URL set via '.get_class($this).'->getServiceUrl($url).'
);
}
return $this->_url;
@ -100,7 +102,9 @@ extends CAS_ProxiedService_Abstract
public function setServiceUrl ($url)
{
if ($this->hasBeenOpened()) {
throw new CAS_OutOfSequenceException('Cannot set the URL, stream already opened.');
throw new CAS_OutOfSequenceException(
'Cannot set the URL, stream already opened.'
);
}
if (!is_string($url) || !strlen($url)) {
throw new CAS_InvalidArgumentException('Invalid url.');
@ -127,7 +131,9 @@ extends CAS_ProxiedService_Abstract
public function setMailbox ($mailbox)
{
if ($this->hasBeenOpened()) {
throw new CAS_OutOfSequenceException('Cannot set the mailbox, stream already opened.');
throw new CAS_OutOfSequenceException(
'Cannot set the mailbox, stream already opened.'
);
}
if (!is_string($mailbox) || !strlen($mailbox)) {
throw new CAS_InvalidArgumentException('Invalid mailbox.');
@ -155,7 +161,9 @@ extends CAS_ProxiedService_Abstract
public function setOptions ($options)
{
if ($this->hasBeenOpened()) {
throw new CAS_OutOfSequenceException('Cannot set options, stream already opened.');
throw new CAS_OutOfSequenceException(
'Cannot set options, stream already opened.'
);
}
if (!is_int($options)) {
throw new CAS_InvalidArgumentException('Invalid options.');
@ -178,14 +186,19 @@ extends CAS_ProxiedService_Abstract
* PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
* PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
* PHPCAS_SERVICE_PT_FAILURE
* @throws CAS_ProxiedService_Exception If there is a failure sending the request to the target service. */
* @throws CAS_ProxiedService_Exception If there is a failure sending the
* request to the target service.
*/
public function open ()
{
if ($this->hasBeenOpened()) {
throw new CAS_OutOfSequenceException('Stream already opened.');
}
if (empty($this->_mailbox)) {
throw new CAS_ProxiedService_Exception('You must specify a mailbox via '.get_class($this).'->setMailbox($mailbox)');
throw new CAS_ProxiedService_Exception(
'You must specify a mailbox via '.get_class($this)
.'->setMailbox($mailbox)'
);
}
phpCAS::traceBegin();
@ -193,13 +206,16 @@ extends CAS_ProxiedService_Abstract
// Get our proxy ticket and append it to our URL.
$this->initializeProxyTicket();
phpCAS::trace('opening IMAP mailbox `'.$this->_mailbox.'\'...');
$this->_stream = @imap_open($this->_mailbox, $this->_username, $this->getProxyTicket(), $this->_options);
$this->_stream = @imap_open(
$this->_mailbox, $this->_username, $this->getProxyTicket(),
$this->_options
);
if ($this->_stream) {
phpCAS::trace('ok');
} else {
phpCAS::trace('could not open mailbox');
// @todo add localization integration.
$message = 'IMAP Error: '.$url.' '. var_export(imap_errors(), true);
$message = 'IMAP Error: '.$this->_url.' '. var_export(imap_errors(), true);
phpCAS::trace($message);
throw new CAS_ProxiedService_Exception($message);
}
@ -236,7 +252,9 @@ extends CAS_ProxiedService_Abstract
public function getStream ()
{
if (!$this->hasBeenOpened()) {
throw new CAS_OutOfSequenceException('Cannot access stream, not opened yet.');
throw new CAS_OutOfSequenceException(
'Cannot access stream, not opened yet.'
);
}
return $this->_stream;
}
@ -252,7 +270,9 @@ extends CAS_ProxiedService_Abstract
public function getImapProxyTicket ()
{
if (!$this->hasBeenOpened()) {
throw new CAS_OutOfSequenceException('Cannot access errors, stream not opened yet.');
throw new CAS_OutOfSequenceException(
'Cannot access errors, stream not opened yet.'
);
}
return $this->getProxyTicket();
}

View File

@ -31,8 +31,9 @@
* This interface defines methods that allow proxy-authenticated service handlers
* to be tested in unit tests.
*
* Classes implementing this interface SHOULD store the CAS_Client passed and initialize
* themselves with that client rather than via the static phpCAS method. For example:
* Classes implementing this interface SHOULD store the CAS_Client passed and
* initialize themselves with that client rather than via the static phpCAS
* method. For example:
*
* / **
* * Fetch our proxy ticket.
@ -65,7 +66,8 @@ interface CAS_ProxiedService_Testable
* @param CAS_Client $casClient Cas client object
*
* @return void
* @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
* @throws CAS_OutOfSequenceException If called after a proxy ticket has
* already been initialized/set.
*/
public function setCasClient (CAS_Client $casClient);

View File

@ -59,7 +59,8 @@ implements CAS_ProxyChain_Interface
*/
public function __construct(array $chain)
{
$this->chain = array_values($chain); // Ensure that we have an indexed array
// Ensure that we have an indexed array
$this->chain = array_values($chain);
}
/**
@ -78,17 +79,25 @@ implements CAS_ProxyChain_Interface
$proxy_url = $list[$i];
if (preg_match('/^\/.*\/[ixASUXu]*$/s', $search)) {
if (preg_match($search, $proxy_url)) {
phpCAS::trace("Found regexp " . $search . " matching " . $proxy_url);
phpCAS::trace(
"Found regexp " . $search . " matching " . $proxy_url
);
} else {
phpCAS::trace("No regexp match " . $search . " != " . $proxy_url);
phpCAS::trace(
"No regexp match " . $search . " != " . $proxy_url
);
$mismatch = true;
break;
}
} else {
if (strncasecmp($search, $proxy_url, strlen($search)) == 0) {
phpCAS::trace("Found string " . $search . " matching " . $proxy_url);
phpCAS::trace(
"Found string " . $search . " matching " . $proxy_url
);
} else {
phpCAS::trace("No match " . $search . " != " . $proxy_url);
phpCAS::trace(
"No match " . $search . " != " . $proxy_url
);
$mismatch = true;
break;
}

View File

@ -60,7 +60,10 @@ implements CAS_Exception
PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,
);
if (!in_array($code, $ptCodes)) {
trigger_error('Invalid code '.$code.' passed. Must be one of PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, or PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE.');
trigger_error(
'Invalid code '.$code
.' passed. Must be one of PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, or PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE.'
);
}
parent::__construct($message, $code);

View File

@ -68,7 +68,9 @@ implements CAS_Request_RequestInterface
public function setUrl ($url)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->url = $url;
@ -86,7 +88,9 @@ implements CAS_Request_RequestInterface
public function addCookie ($name, $value)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->cookies[$name] = $value;
@ -105,7 +109,9 @@ implements CAS_Request_RequestInterface
public function addCookies (array $cookies)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->cookies = array_merge($this->cookies, $cookies);
@ -122,7 +128,9 @@ implements CAS_Request_RequestInterface
public function addHeader ($header)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->headers[] = $header;
@ -139,7 +147,9 @@ implements CAS_Request_RequestInterface
public function addHeaders (array $headers)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->headers = array_merge($this->headers, $headers);
@ -154,7 +164,9 @@ implements CAS_Request_RequestInterface
public function makePost ()
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->isPost = true;
@ -171,10 +183,14 @@ implements CAS_Request_RequestInterface
public function setPostBody ($body)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
if (!$this->isPost) {
throw new CAS_OutOfSequenceException('Cannot add a POST body to a GET request, use makePost() first.');
throw new CAS_OutOfSequenceException(
'Cannot add a POST body to a GET request, use makePost() first.'
);
}
$this->postBody = $body;
@ -192,7 +208,9 @@ implements CAS_Request_RequestInterface
public function setSslCaCert ($caCertPath,$validate_cn=true)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->caCertPath = $caCertPath;
$this->validateCN = $validate_cn;
@ -211,10 +229,14 @@ implements CAS_Request_RequestInterface
public function send ()
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot send again.');
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot send again.'
);
}
if (is_null($this->url) || !$this->url) {
throw new CAS_OutOfSequenceException('A url must be specified via setUrl() before the request can be sent.');
throw new CAS_OutOfSequenceException(
'A url must be specified via setUrl() before the request can be sent.'
);
}
$this->_sent = true;
return $this->sendRequest();
@ -288,7 +310,9 @@ implements CAS_Request_RequestInterface
public function getResponseHeaders ()
{
if (!$this->_sent) {
throw new CAS_OutOfSequenceException('Request has not been sent yet. Cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot '.__METHOD__
);
}
return $this->_responseHeaders;
}
@ -302,11 +326,19 @@ implements CAS_Request_RequestInterface
public function getResponseStatusCode ()
{
if (!$this->_sent) {
throw new CAS_OutOfSequenceException('Request has not been sent yet. Cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot '.__METHOD__
);
}
if (!preg_match('/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/', $this->_responseHeaders[0], $matches)) {
throw new CAS_Request_Exception("Bad response, no status code was found in the first line.");
if (!preg_match(
'/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/',
$this->_responseHeaders[0], $matches
)
) {
throw new CAS_Request_Exception(
'Bad response, no status code was found in the first line.'
);
}
return intval($matches[1]);
@ -321,7 +353,9 @@ implements CAS_Request_RequestInterface
public function getResponseBody ()
{
if (!$this->_sent) {
throw new CAS_OutOfSequenceException('Request has not been sent yet. Cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot '.__METHOD__
);
}
return $this->_responseBody;
@ -336,7 +370,9 @@ implements CAS_Request_RequestInterface
public function getErrorMessage ()
{
if (!$this->_sent) {
throw new CAS_OutOfSequenceException('Request has not been sent yet. Cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot '.__METHOD__
);
}
return $this->_errorMessage;
}

View File

@ -64,10 +64,14 @@ implements CAS_Request_MultiRequestInterface
public function addRequest (CAS_Request_RequestInterface $request)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
if (!$request instanceof CAS_Request_CurlRequest) {
throw new CAS_InvalidArgumentException('As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.');
throw new CAS_InvalidArgumentException(
'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.'
);
}
$this->_requests[] = $request;
@ -81,7 +85,9 @@ implements CAS_Request_MultiRequestInterface
public function getNumRequests()
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot '.__METHOD__);
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
return count($this->_requests);
}
@ -100,10 +106,14 @@ implements CAS_Request_MultiRequestInterface
public function send ()
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException('Request has already been sent cannot send again.');
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot send again.'
);
}
if (!count($this->_requests)) {
throw new CAS_OutOfSequenceException('At least one request must be added via addRequest() before the multi-request can be sent.');
throw new CAS_OutOfSequenceException(
'At least one request must be added via addRequest() before the multi-request can be sent.'
);
}
$this->_sent = true;

View File

@ -75,7 +75,9 @@ implements CAS_Request_RequestInterface
$buf = curl_exec($ch);
if ( $buf === false ) {
phpCAS::trace('curl_exec() failed');
$this->storeErrorMessage('CURL error #'.curl_errno($ch).': '.curl_error($ch));
$this->storeErrorMessage(
'CURL error #'.curl_errno($ch).': '.curl_error($ch)
);
$res = false;
} else {
$this->storeResponseBody($buf);
@ -120,7 +122,7 @@ implements CAS_Request_RequestInterface
if ($this->validateCN) {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
} else {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath);

View File

@ -0,0 +1,70 @@
<?php
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP Version 5
*
* @file CAS/InvalidArgumentException.php
* @category Authentication
* @package PhpCAS
* @author Adam Franco <afranco@middlebury.edu>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
/**
* Exception that denotes invalid arguments were passed.
*
* @class CAS_InvalidArgumentException
* @category Authentication
* @package PhpCAS
* @author Adam Franco <afranco@middlebury.edu>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class CAS_TypeMismatchException
extends CAS_InvalidArgumentException
{
/**
* Constructor, provides a nice message.
*
* @param mixed $argument Argument
* @param string $argumentName Argument Name
* @param string $type Type
* @param string $message Error Message
* @param integer $code Code
*
* @return void
*/
public function __construct (
$argument, $argumentName, $type, $message = '', $code = 0
) {
if (is_object($argument)) {
$foundType = get_class($argument).' object';
} else {
$foundType = gettype($argument);
}
parent::__construct(
'type mismatched for parameter '
. $argumentName . ' (should be \'' . $type .' \'), '
. $foundType . ' given. ' . $message, $code
);
}
}
?>

View File

@ -1,5 +1,5 @@
Description of phpCAS 1.3.2 library import
Description of phpCAS 1.3.3 library import
* downloaded from http://downloads.jasig.org/cas-clients/php/current/
iarenaza
merrill

View File

@ -4,7 +4,7 @@
<location>CAS</location>
<name>CAS</name>
<license>BSD</license>
<version>1.3.2</version>
<version>1.3.3</version>
<licenseversion></licenseversion>
</library>
</libraries>