PageRenderTime 59ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/auth/cas/CAS/CAS.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 1980 lines | 847 code | 179 blank | 954 comment | 195 complexity | c88fc046446b19acf7bebde15bb59150 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. /**
  3. * Licensed to Jasig under one or more contributor license
  4. * agreements. See the NOTICE file distributed with this work for
  5. * additional information regarding copyright ownership.
  6. *
  7. * Jasig licenses this file to you under the Apache License,
  8. * Version 2.0 (the "License"); you may not use this file except in
  9. * compliance with the License. You may obtain a copy of the License at:
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. *
  20. *
  21. * Interface class of the phpCAS library
  22. * PHP Version 5
  23. *
  24. * @file CAS/CAS.php
  25. * @category Authentication
  26. * @package PhpCAS
  27. * @author Pascal Aubry <pascal.aubry@univ-rennes1.fr>
  28. * @author Olivier Berger <olivier.berger@it-sudparis.eu>
  29. * @author Brett Bieber <brett.bieber@gmail.com>
  30. * @author Joachim Fritschi <jfritschi@freenet.de>
  31. * @author Adam Franco <afranco@middlebury.edu>
  32. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  33. * @link https://wiki.jasig.org/display/CASC/phpCAS
  34. * @ingroup public
  35. */
  36. //
  37. // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI']
  38. // in IIS
  39. //
  40. if (php_sapi_name() != 'cli') {
  41. if (!isset($_SERVER['REQUEST_URI'])) {
  42. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
  43. }
  44. }
  45. // Add a E_USER_DEPRECATED for php versions <= 5.2
  46. if (!defined('E_USER_DEPRECATED')) {
  47. define('E_USER_DEPRECATED', E_USER_NOTICE);
  48. }
  49. // ########################################################################
  50. // CONSTANTS
  51. // ########################################################################
  52. // ------------------------------------------------------------------------
  53. // CAS VERSIONS
  54. // ------------------------------------------------------------------------
  55. /**
  56. * phpCAS version. accessible for the user by phpCAS::getVersion().
  57. */
  58. define('PHPCAS_VERSION', '1.3.2');
  59. /**
  60. * @addtogroup public
  61. * @{
  62. */
  63. /**
  64. * CAS version 1.0
  65. */
  66. define("CAS_VERSION_1_0", '1.0');
  67. /*!
  68. * CAS version 2.0
  69. */
  70. define("CAS_VERSION_2_0", '2.0');
  71. // ------------------------------------------------------------------------
  72. // SAML defines
  73. // ------------------------------------------------------------------------
  74. /**
  75. * SAML protocol
  76. */
  77. define("SAML_VERSION_1_1", 'S1');
  78. /**
  79. * XML header for SAML POST
  80. */
  81. define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
  82. /**
  83. * SOAP envelope for SAML POST
  84. */
  85. define("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
  86. /**
  87. * SOAP body for SAML POST
  88. */
  89. define("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
  90. /**
  91. * SAMLP request
  92. */
  93. define("SAMLP_REQUEST", '<samlp:Request xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" MajorVersion="1" MinorVersion="1" RequestID="_192.168.16.51.1024506224022" IssueInstant="2002-06-19T17:03:44.022Z">');
  94. define("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
  95. /**
  96. * SAMLP artifact tag (for the ticket)
  97. */
  98. define("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
  99. /**
  100. * SAMLP close
  101. */
  102. define("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
  103. /**
  104. * SOAP body close
  105. */
  106. define("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
  107. /**
  108. * SOAP envelope close
  109. */
  110. define("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
  111. /**
  112. * SAML Attributes
  113. */
  114. define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
  115. /** @} */
  116. /**
  117. * @addtogroup publicPGTStorage
  118. * @{
  119. */
  120. // ------------------------------------------------------------------------
  121. // FILE PGT STORAGE
  122. // ------------------------------------------------------------------------
  123. /**
  124. * Default path used when storing PGT's to file
  125. */
  126. define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH", session_save_path());
  127. /** @} */
  128. // ------------------------------------------------------------------------
  129. // SERVICE ACCESS ERRORS
  130. // ------------------------------------------------------------------------
  131. /**
  132. * @addtogroup publicServices
  133. * @{
  134. */
  135. /**
  136. * phpCAS::service() error code on success
  137. */
  138. define("PHPCAS_SERVICE_OK", 0);
  139. /**
  140. * phpCAS::service() error code when the PT could not retrieve because
  141. * the CAS server did not respond.
  142. */
  143. define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
  144. /**
  145. * phpCAS::service() error code when the PT could not retrieve because
  146. * the response of the CAS server was ill-formed.
  147. */
  148. define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
  149. /**
  150. * phpCAS::service() error code when the PT could not retrieve because
  151. * the CAS server did not want to.
  152. */
  153. define("PHPCAS_SERVICE_PT_FAILURE", 3);
  154. /**
  155. * phpCAS::service() error code when the service was not available.
  156. */
  157. define("PHPCAS_SERVICE_NOT_AVAILABLE", 4);
  158. // ------------------------------------------------------------------------
  159. // SERVICE TYPES
  160. // ------------------------------------------------------------------------
  161. /**
  162. * phpCAS::getProxiedService() type for HTTP GET
  163. */
  164. define("PHPCAS_PROXIED_SERVICE_HTTP_GET", 'CAS_ProxiedService_Http_Get');
  165. /**
  166. * phpCAS::getProxiedService() type for HTTP POST
  167. */
  168. define("PHPCAS_PROXIED_SERVICE_HTTP_POST", 'CAS_ProxiedService_Http_Post');
  169. /**
  170. * phpCAS::getProxiedService() type for IMAP
  171. */
  172. define("PHPCAS_PROXIED_SERVICE_IMAP", 'CAS_ProxiedService_Imap');
  173. /** @} */
  174. // ------------------------------------------------------------------------
  175. // LANGUAGES
  176. // ------------------------------------------------------------------------
  177. /**
  178. * @addtogroup publicLang
  179. * @{
  180. */
  181. define("PHPCAS_LANG_ENGLISH", 'CAS_Languages_English');
  182. define("PHPCAS_LANG_FRENCH", 'CAS_Languages_French');
  183. define("PHPCAS_LANG_GREEK", 'CAS_Languages_Greek');
  184. define("PHPCAS_LANG_GERMAN", 'CAS_Languages_German');
  185. define("PHPCAS_LANG_JAPANESE", 'CAS_Languages_Japanese');
  186. define("PHPCAS_LANG_SPANISH", 'CAS_Languages_Spanish');
  187. define("PHPCAS_LANG_CATALAN", 'CAS_Languages_Catalan');
  188. /** @} */
  189. /**
  190. * @addtogroup internalLang
  191. * @{
  192. */
  193. /**
  194. * phpCAS default language (when phpCAS::setLang() is not used)
  195. */
  196. define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
  197. /** @} */
  198. // ------------------------------------------------------------------------
  199. // DEBUG
  200. // ------------------------------------------------------------------------
  201. /**
  202. * @addtogroup publicDebug
  203. * @{
  204. */
  205. /**
  206. * The default directory for the debug file under Unix.
  207. */
  208. define('DEFAULT_DEBUG_DIR', '/tmp/');
  209. /** @} */
  210. // include the class autoloader
  211. require_once dirname(__FILE__) . '/CAS/Autoload.php';
  212. /**
  213. * The phpCAS class is a simple container for the phpCAS library. It provides CAS
  214. * authentication for web applications written in PHP.
  215. *
  216. * @ingroup public
  217. * @class phpCAS
  218. * @category Authentication
  219. * @package PhpCAS
  220. * @author Pascal Aubry <pascal.aubry@univ-rennes1.fr>
  221. * @author Olivier Berger <olivier.berger@it-sudparis.eu>
  222. * @author Brett Bieber <brett.bieber@gmail.com>
  223. * @author Joachim Fritschi <jfritschi@freenet.de>
  224. * @author Adam Franco <afranco@middlebury.edu>
  225. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  226. * @link https://wiki.jasig.org/display/CASC/phpCAS
  227. */
  228. class phpCAS
  229. {
  230. /**
  231. * This variable is used by the interface class phpCAS.
  232. *
  233. * @hideinitializer
  234. */
  235. private static $_PHPCAS_CLIENT;
  236. /**
  237. * This variable is used to store where the initializer is called from
  238. * (to print a comprehensive error in case of multiple calls).
  239. *
  240. * @hideinitializer
  241. */
  242. private static $_PHPCAS_INIT_CALL;
  243. /**
  244. * This variable is used to store phpCAS debug mode.
  245. *
  246. * @hideinitializer
  247. */
  248. private static $_PHPCAS_DEBUG;
  249. // ########################################################################
  250. // INITIALIZATION
  251. // ########################################################################
  252. /**
  253. * @addtogroup publicInit
  254. * @{
  255. */
  256. /**
  257. * phpCAS client initializer.
  258. *
  259. * @param string $server_version the version of the CAS server
  260. * @param string $server_hostname the hostname of the CAS server
  261. * @param string $server_port the port the CAS server is running on
  262. * @param string $server_uri the URI the CAS server is responding on
  263. * @param bool $changeSessionID Allow phpCAS to change the session_id (Single
  264. * Sign Out/handleLogoutRequests is based on that change)
  265. *
  266. * @return a newly created CAS_Client object
  267. * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be
  268. * called, only once, and before all other methods (except phpCAS::getVersion()
  269. * and phpCAS::setDebug()).
  270. */
  271. public static function client($server_version, $server_hostname,
  272. $server_port, $server_uri, $changeSessionID = true
  273. ) {
  274. phpCAS :: traceBegin();
  275. if (is_object(self::$_PHPCAS_CLIENT)) {
  276. phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
  277. }
  278. if (gettype($server_version) != 'string') {
  279. phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
  280. }
  281. if (gettype($server_hostname) != 'string') {
  282. phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
  283. }
  284. if (gettype($server_port) != 'integer') {
  285. phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
  286. }
  287. if (gettype($server_uri) != 'string') {
  288. phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
  289. }
  290. // store where the initializer is called from
  291. $dbg = debug_backtrace();
  292. self::$_PHPCAS_INIT_CALL = array (
  293. 'done' => true,
  294. 'file' => $dbg[0]['file'],
  295. 'line' => $dbg[0]['line'],
  296. 'method' => __CLASS__ . '::' . __FUNCTION__
  297. );
  298. // initialize the object $_PHPCAS_CLIENT
  299. self::$_PHPCAS_CLIENT = new CAS_Client(
  300. $server_version, false, $server_hostname, $server_port, $server_uri,
  301. $changeSessionID
  302. );
  303. phpCAS :: traceEnd();
  304. }
  305. /**
  306. * phpCAS proxy initializer.
  307. *
  308. * @param string $server_version the version of the CAS server
  309. * @param string $server_hostname the hostname of the CAS server
  310. * @param string $server_port the port the CAS server is running on
  311. * @param string $server_uri the URI the CAS server is responding on
  312. * @param bool $changeSessionID Allow phpCAS to change the session_id (Single
  313. * Sign Out/handleLogoutRequests is based on that change)
  314. *
  315. * @return a newly created CAS_Client object
  316. * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be
  317. * called, only once, and before all other methods (except phpCAS::getVersion()
  318. * and phpCAS::setDebug()).
  319. */
  320. public static function proxy($server_version, $server_hostname,
  321. $server_port, $server_uri, $changeSessionID = true
  322. ) {
  323. phpCAS :: traceBegin();
  324. if (is_object(self::$_PHPCAS_CLIENT)) {
  325. phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
  326. }
  327. if (gettype($server_version) != 'string') {
  328. phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
  329. }
  330. if (gettype($server_hostname) != 'string') {
  331. phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
  332. }
  333. if (gettype($server_port) != 'integer') {
  334. phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
  335. }
  336. if (gettype($server_uri) != 'string') {
  337. phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
  338. }
  339. // store where the initialzer is called from
  340. $dbg = debug_backtrace();
  341. self::$_PHPCAS_INIT_CALL = array (
  342. 'done' => true,
  343. 'file' => $dbg[0]['file'],
  344. 'line' => $dbg[0]['line'],
  345. 'method' => __CLASS__ . '::' . __FUNCTION__
  346. );
  347. // initialize the object $_PHPCAS_CLIENT
  348. self::$_PHPCAS_CLIENT = new CAS_Client(
  349. $server_version, true, $server_hostname, $server_port, $server_uri,
  350. $changeSessionID
  351. );
  352. phpCAS :: traceEnd();
  353. }
  354. /** @} */
  355. // ########################################################################
  356. // DEBUGGING
  357. // ########################################################################
  358. /**
  359. * @addtogroup publicDebug
  360. * @{
  361. */
  362. /**
  363. * Set/unset debug mode
  364. *
  365. * @param string $filename the name of the file used for logging, or false
  366. * to stop debugging.
  367. *
  368. * @return void
  369. */
  370. public static function setDebug($filename = '')
  371. {
  372. if ($filename != false && gettype($filename) != 'string') {
  373. phpCAS :: error('type mismatched for parameter $dbg (should be false or the name of the log file)');
  374. }
  375. if ($filename === false) {
  376. self::$_PHPCAS_DEBUG['filename'] = false;
  377. } else {
  378. if (empty ($filename)) {
  379. if (preg_match('/^Win.*/', getenv('OS'))) {
  380. if (isset ($_ENV['TMP'])) {
  381. $debugDir = $_ENV['TMP'] . '/';
  382. } else {
  383. $debugDir = '';
  384. }
  385. } else {
  386. $debugDir = DEFAULT_DEBUG_DIR;
  387. }
  388. $filename = $debugDir . 'phpCAS.log';
  389. }
  390. if (empty (self::$_PHPCAS_DEBUG['unique_id'])) {
  391. self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
  392. }
  393. self::$_PHPCAS_DEBUG['filename'] = $filename;
  394. self::$_PHPCAS_DEBUG['indent'] = 0;
  395. phpCAS :: trace('START phpCAS-' . PHPCAS_VERSION . ' ******************');
  396. }
  397. }
  398. /**
  399. * Logs a string in debug mode.
  400. *
  401. * @param string $str the string to write
  402. *
  403. * @return void
  404. * @private
  405. */
  406. public static function log($str)
  407. {
  408. $indent_str = ".";
  409. if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
  410. // Check if file exists and modifiy file permissions to be only
  411. // readable by the webserver
  412. if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
  413. touch(self::$_PHPCAS_DEBUG['filename']);
  414. // Chmod will fail on windows
  415. @chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
  416. }
  417. for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
  418. $indent_str .= '| ';
  419. }
  420. // allow for multiline output with proper identing. Usefull for
  421. // dumping cas answers etc.
  422. $str2 = str_replace("\n", "\n" . self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
  423. error_log(self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
  424. }
  425. }
  426. /**
  427. * This method is used by interface methods to print an error and where the
  428. * function was originally called from.
  429. *
  430. * @param string $msg the message to print
  431. *
  432. * @return void
  433. * @private
  434. */
  435. public static function error($msg)
  436. {
  437. $dbg = debug_backtrace();
  438. $function = '?';
  439. $file = '?';
  440. $line = '?';
  441. if (is_array($dbg)) {
  442. for ($i = 1; $i < sizeof($dbg); $i++) {
  443. if (is_array($dbg[$i]) && isset($dbg[$i]['class']) ) {
  444. if ($dbg[$i]['class'] == __CLASS__) {
  445. $function = $dbg[$i]['function'];
  446. $file = $dbg[$i]['file'];
  447. $line = $dbg[$i]['line'];
  448. }
  449. }
  450. }
  451. }
  452. echo "<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>" . __CLASS__ . "::" . $function . '(): ' . htmlentities($msg) . "</b></font> in <b>" . $file . "</b> on line <b>" . $line . "</b><br />\n";
  453. phpCAS :: trace($msg);
  454. phpCAS :: traceEnd();
  455. throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
  456. }
  457. /**
  458. * This method is used to log something in debug mode.
  459. *
  460. * @param string $str string to log
  461. *
  462. * @return void
  463. */
  464. public static function trace($str)
  465. {
  466. $dbg = debug_backtrace();
  467. phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
  468. }
  469. /**
  470. * This method is used to indicate the start of the execution of a function in debug mode.
  471. *
  472. * @return void
  473. */
  474. public static function traceBegin()
  475. {
  476. $dbg = debug_backtrace();
  477. $str = '=> ';
  478. if (!empty ($dbg[1]['class'])) {
  479. $str .= $dbg[1]['class'] . '::';
  480. }
  481. $str .= $dbg[1]['function'] . '(';
  482. if (is_array($dbg[1]['args'])) {
  483. foreach ($dbg[1]['args'] as $index => $arg) {
  484. if ($index != 0) {
  485. $str .= ', ';
  486. }
  487. if (is_object($arg)) {
  488. $str .= get_class($arg);
  489. } else {
  490. $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
  491. }
  492. }
  493. }
  494. if (isset($dbg[1]['file'])) {
  495. $file = basename($dbg[1]['file']);
  496. } else {
  497. $file = 'unknown_file';
  498. }
  499. if (isset($dbg[1]['line'])) {
  500. $line = $dbg[1]['line'];
  501. } else {
  502. $line = 'unknown_line';
  503. }
  504. $str .= ') [' . $file . ':' . $line . ']';
  505. phpCAS :: log($str);
  506. if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
  507. self::$_PHPCAS_DEBUG['indent'] = 0;
  508. } else {
  509. self::$_PHPCAS_DEBUG['indent']++;
  510. }
  511. }
  512. /**
  513. * This method is used to indicate the end of the execution of a function in
  514. * debug mode.
  515. *
  516. * @param string $res the result of the function
  517. *
  518. * @return void
  519. */
  520. public static function traceEnd($res = '')
  521. {
  522. if (empty(self::$_PHPCAS_DEBUG['indent'])) {
  523. self::$_PHPCAS_DEBUG['indent'] = 0;
  524. } else {
  525. self::$_PHPCAS_DEBUG['indent']--;
  526. }
  527. $dbg = debug_backtrace();
  528. $str = '';
  529. if (is_object($res)) {
  530. $str .= '<= ' . get_class($res);
  531. } else {
  532. $str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
  533. }
  534. phpCAS :: log($str);
  535. }
  536. /**
  537. * This method is used to indicate the end of the execution of the program
  538. *
  539. * @return void
  540. */
  541. public static function traceExit()
  542. {
  543. phpCAS :: log('exit()');
  544. while (self::$_PHPCAS_DEBUG['indent'] > 0) {
  545. phpCAS :: log('-');
  546. self::$_PHPCAS_DEBUG['indent']--;
  547. }
  548. }
  549. /** @} */
  550. // ########################################################################
  551. // INTERNATIONALIZATION
  552. // ########################################################################
  553. /**
  554. * @addtogroup publicLang
  555. * @{
  556. */
  557. /**
  558. * This method is used to set the language used by phpCAS.
  559. *
  560. * @param string $lang string representing the language.
  561. *
  562. * @return void
  563. *
  564. * @sa PHPCAS_LANG_FRENCH, PHPCAS_LANG_ENGLISH
  565. * @note Can be called only once.
  566. */
  567. public static function setLang($lang)
  568. {
  569. if (!is_object(self::$_PHPCAS_CLIENT)) {
  570. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  571. }
  572. if (gettype($lang) != 'string') {
  573. phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
  574. }
  575. self::$_PHPCAS_CLIENT->setLang($lang);
  576. }
  577. /** @} */
  578. // ########################################################################
  579. // VERSION
  580. // ########################################################################
  581. /**
  582. * @addtogroup public
  583. * @{
  584. */
  585. /**
  586. * This method returns the phpCAS version.
  587. *
  588. * @return the phpCAS version.
  589. */
  590. public static function getVersion()
  591. {
  592. return PHPCAS_VERSION;
  593. }
  594. /** @} */
  595. // ########################################################################
  596. // HTML OUTPUT
  597. // ########################################################################
  598. /**
  599. * @addtogroup publicOutput
  600. * @{
  601. */
  602. /**
  603. * This method sets the HTML header used for all outputs.
  604. *
  605. * @param string $header the HTML header.
  606. *
  607. * @return void
  608. */
  609. public static function setHTMLHeader($header)
  610. {
  611. if (!is_object(self::$_PHPCAS_CLIENT)) {
  612. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  613. }
  614. if (gettype($header) != 'string') {
  615. phpCAS :: error('type mismatched for parameter $header (should be `string\')');
  616. }
  617. self::$_PHPCAS_CLIENT->setHTMLHeader($header);
  618. }
  619. /**
  620. * This method sets the HTML footer used for all outputs.
  621. *
  622. * @param string $footer the HTML footer.
  623. *
  624. * @return void
  625. */
  626. public static function setHTMLFooter($footer)
  627. {
  628. if (!is_object(self::$_PHPCAS_CLIENT)) {
  629. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  630. }
  631. if (gettype($footer) != 'string') {
  632. phpCAS :: error('type mismatched for parameter $footer (should be `string\')');
  633. }
  634. self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
  635. }
  636. /** @} */
  637. // ########################################################################
  638. // PGT STORAGE
  639. // ########################################################################
  640. /**
  641. * @addtogroup publicPGTStorage
  642. * @{
  643. */
  644. /**
  645. * This method can be used to set a custom PGT storage object.
  646. *
  647. * @param CAS_PGTStorage $storage a PGT storage object that inherits from the
  648. * CAS_PGTStorage class
  649. *
  650. * @return void
  651. */
  652. public static function setPGTStorage($storage)
  653. {
  654. phpCAS :: traceBegin();
  655. if (!is_object(self::$_PHPCAS_CLIENT)) {
  656. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  657. }
  658. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  659. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  660. }
  661. if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  662. phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
  663. }
  664. if ( !($storage instanceof CAS_PGTStorage) ) {
  665. phpCAS :: error('type mismatched for parameter $storage (should be a CAS_PGTStorage `object\')');
  666. }
  667. self::$_PHPCAS_CLIENT->setPGTStorage($storage);
  668. phpCAS :: traceEnd();
  669. }
  670. /**
  671. * This method is used to tell phpCAS to store the response of the
  672. * CAS server to PGT requests in a database.
  673. *
  674. * @param string $dsn_or_pdo a dsn string to use for creating a PDO
  675. * object or a PDO object
  676. * @param string $username the username to use when connecting to the
  677. * database
  678. * @param string $password the password to use when connecting to the
  679. * database
  680. * @param string $table the table to use for storing and retrieving
  681. * PGT's
  682. * @param string $driver_options any driver options to use when connecting
  683. * to the database
  684. *
  685. * @return void
  686. */
  687. public static function setPGTStorageDb($dsn_or_pdo, $username='',
  688. $password='', $table='', $driver_options=null
  689. ) {
  690. phpCAS :: traceBegin();
  691. if (!is_object(self::$_PHPCAS_CLIENT)) {
  692. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  693. }
  694. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  695. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  696. }
  697. if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  698. phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
  699. }
  700. if (gettype($username) != 'string') {
  701. phpCAS :: error('type mismatched for parameter $username (should be `string\')');
  702. }
  703. if (gettype($password) != 'string') {
  704. phpCAS :: error('type mismatched for parameter $password (should be `string\')');
  705. }
  706. if (gettype($table) != 'string') {
  707. phpCAS :: error('type mismatched for parameter $table (should be `string\')');
  708. }
  709. self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
  710. phpCAS :: traceEnd();
  711. }
  712. /**
  713. * This method is used to tell phpCAS to store the response of the
  714. * CAS server to PGT requests onto the filesystem.
  715. *
  716. * @param string $path the path where the PGT's should be stored
  717. *
  718. * @return void
  719. */
  720. public static function setPGTStorageFile($path = '')
  721. {
  722. phpCAS :: traceBegin();
  723. if (!is_object(self::$_PHPCAS_CLIENT)) {
  724. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  725. }
  726. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  727. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  728. }
  729. if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  730. phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
  731. }
  732. if (gettype($path) != 'string') {
  733. phpCAS :: error('type mismatched for parameter $path (should be `string\')');
  734. }
  735. self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
  736. phpCAS :: traceEnd();
  737. }
  738. /** @} */
  739. // ########################################################################
  740. // ACCESS TO EXTERNAL SERVICES
  741. // ########################################################################
  742. /**
  743. * @addtogroup publicServices
  744. * @{
  745. */
  746. /**
  747. * Answer a proxy-authenticated service handler.
  748. *
  749. * @param string $type The service type. One of
  750. * PHPCAS_PROXIED_SERVICE_HTTP_GET; PHPCAS_PROXIED_SERVICE_HTTP_POST;
  751. * PHPCAS_PROXIED_SERVICE_IMAP
  752. *
  753. * @return CAS_ProxiedService
  754. * @throws InvalidArgumentException If the service type is unknown.
  755. */
  756. public static function getProxiedService ($type)
  757. {
  758. phpCAS :: traceBegin();
  759. if (!is_object(self::$_PHPCAS_CLIENT)) {
  760. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  761. }
  762. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  763. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  764. }
  765. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  766. 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()');
  767. }
  768. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  769. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  770. }
  771. if (gettype($type) != 'string') {
  772. phpCAS :: error('type mismatched for parameter $type (should be `string\')');
  773. }
  774. $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
  775. phpCAS :: traceEnd();
  776. return $res;
  777. }
  778. /**
  779. * Initialize a proxied-service handler with the proxy-ticket it should use.
  780. *
  781. * @param CAS_ProxiedService $proxiedService Proxied Service Handler
  782. *
  783. * @return void
  784. * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
  785. * The code of the Exception will be one of:
  786. * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
  787. * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
  788. * PHPCAS_SERVICE_PT_FAILURE
  789. */
  790. public static function initializeProxiedService (CAS_ProxiedService $proxiedService)
  791. {
  792. if (!is_object(self::$_PHPCAS_CLIENT)) {
  793. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  794. }
  795. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  796. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  797. }
  798. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  799. 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()');
  800. }
  801. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  802. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  803. }
  804. self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
  805. }
  806. /**
  807. * This method is used to access an HTTP[S] service.
  808. *
  809. * @param string $url the service to access.
  810. * @param string &$err_code an error code Possible values are
  811. * PHPCAS_SERVICE_OK (on success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE,
  812. * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE, PHPCAS_SERVICE_PT_FAILURE,
  813. * PHPCAS_SERVICE_NOT_AVAILABLE.
  814. * @param string &$output the output of the service (also used to give an
  815. * error message on failure).
  816. *
  817. * @return bool true on success, false otherwise (in this later case,
  818. * $err_code gives the reason why it failed and $output contains an error
  819. * message).
  820. */
  821. public static function serviceWeb($url, & $err_code, & $output)
  822. {
  823. phpCAS :: traceBegin();
  824. if (!is_object(self::$_PHPCAS_CLIENT)) {
  825. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  826. }
  827. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  828. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  829. }
  830. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  831. 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()');
  832. }
  833. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  834. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  835. }
  836. if (gettype($url) != 'string') {
  837. phpCAS :: error('type mismatched for parameter $url (should be `string\')');
  838. }
  839. $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
  840. phpCAS :: traceEnd($res);
  841. return $res;
  842. }
  843. /**
  844. * This method is used to access an IMAP/POP3/NNTP service.
  845. *
  846. * @param string $url a string giving the URL of the service,
  847. * including the mailing box for IMAP URLs, as accepted by imap_open().
  848. * @param string $service a string giving for CAS retrieve Proxy ticket
  849. * @param string $flags options given to imap_open().
  850. * @param string &$err_code an error code Possible values are
  851. * PHPCAS_SERVICE_OK (on success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE,
  852. * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE, PHPCAS_SERVICE_PT_FAILURE,
  853. * PHPCAS_SERVICE_NOT_AVAILABLE.
  854. * @param string &$err_msg an error message on failure
  855. * @param string &$pt the Proxy Ticket (PT) retrieved from the CAS
  856. * server to access the URL on success, false on error).
  857. *
  858. * @return object IMAP stream on success, false otherwise (in this later
  859. * case, $err_code gives the reason why it failed and $err_msg contains an
  860. * error message).
  861. */
  862. public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
  863. {
  864. phpCAS :: traceBegin();
  865. if (!is_object(self::$_PHPCAS_CLIENT)) {
  866. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  867. }
  868. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  869. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  870. }
  871. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  872. 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()');
  873. }
  874. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  875. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  876. }
  877. if (gettype($url) != 'string') {
  878. phpCAS :: error('type mismatched for parameter $url (should be `string\')');
  879. }
  880. if (gettype($flags) != 'integer') {
  881. phpCAS :: error('type mismatched for parameter $flags (should be `integer\')');
  882. }
  883. $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
  884. phpCAS :: traceEnd($res);
  885. return $res;
  886. }
  887. /** @} */
  888. // ########################################################################
  889. // AUTHENTICATION
  890. // ########################################################################
  891. /**
  892. * @addtogroup publicAuth
  893. * @{
  894. */
  895. /**
  896. * Set the times authentication will be cached before really accessing the
  897. * CAS server in gateway mode:
  898. * - -1: check only once, and then never again (until you pree login)
  899. * - 0: always check
  900. * - n: check every "n" time
  901. *
  902. * @param int $n an integer.
  903. *
  904. * @return void
  905. */
  906. public static function setCacheTimesForAuthRecheck($n)
  907. {
  908. if (!is_object(self::$_PHPCAS_CLIENT)) {
  909. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  910. }
  911. if (gettype($n) != 'integer') {
  912. phpCAS :: error('type mismatched for parameter $n (should be `integer\')');
  913. }
  914. self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
  915. }
  916. /**
  917. * Set a callback function to be run when a user authenticates.
  918. *
  919. * The callback function will be passed a $logoutTicket as its first
  920. * parameter, followed by any $additionalArgs you pass. The $logoutTicket
  921. * parameter is an opaque string that can be used to map the session-id to
  922. * logout request in order to support single-signout in applications that
  923. * manage their own sessions (rather than letting phpCAS start the session).
  924. *
  925. * phpCAS::forceAuthentication() will always exit and forward client unless
  926. * they are already authenticated. To perform an action at the moment the user
  927. * logs in (such as registering an account, performing logging, etc), register
  928. * a callback function here.
  929. *
  930. * @param string $function Callback function
  931. * @param array $additionalArgs optional array of arguments
  932. *
  933. * @return void
  934. */
  935. public static function setPostAuthenticateCallback ($function, array $additionalArgs = array())
  936. {
  937. if (!is_object(self::$_PHPCAS_CLIENT)) {
  938. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  939. }
  940. self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
  941. }
  942. /**
  943. * Set a callback function to be run when a single-signout request is
  944. * received. The callback function will be passed a $logoutTicket as its
  945. * first parameter, followed by any $additionalArgs you pass. The
  946. * $logoutTicket parameter is an opaque string that can be used to map a
  947. * session-id to the logout request in order to support single-signout in
  948. * applications that manage their own sessions (rather than letting phpCAS
  949. * start and destroy the session).
  950. *
  951. * @param string $function Callback function
  952. * @param array $additionalArgs optional array of arguments
  953. *
  954. * @return void
  955. */
  956. public static function setSingleSignoutCallback ($function, array $additionalArgs = array())
  957. {
  958. if (!is_object(self::$_PHPCAS_CLIENT)) {
  959. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  960. }
  961. self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
  962. }
  963. /**
  964. * This method is called to check if the user is already authenticated
  965. * locally or has a global cas session. A already existing cas session is
  966. * determined by a cas gateway call.(cas login call without any interactive
  967. * prompt)
  968. *
  969. * @return true when the user is authenticated, false when a previous
  970. * gateway login failed or the function will not return if the user is
  971. * redirected to the cas server for a gateway login attempt
  972. */
  973. public static function checkAuthentication()
  974. {
  975. phpCAS :: traceBegin();
  976. if (!is_object(self::$_PHPCAS_CLIENT)) {
  977. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  978. }
  979. $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
  980. // store where the authentication has been checked and the result
  981. self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
  982. phpCAS :: traceEnd($auth);
  983. return $auth;
  984. }
  985. /**
  986. * This method is called to force authentication if the user was not already
  987. * authenticated. If the user is not authenticated, halt by redirecting to
  988. * the CAS server.
  989. *
  990. * @return bool Authentication
  991. */
  992. public static function forceAuthentication()
  993. {
  994. phpCAS :: traceBegin();
  995. if (!is_object(self::$_PHPCAS_CLIENT)) {
  996. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  997. }
  998. $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
  999. // store where the authentication has been checked and the result
  1000. self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
  1001. /* if (!$auth) {
  1002. phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
  1003. self::$_PHPCAS_CLIENT->forceAuthentication();
  1004. } else {
  1005. phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
  1006. }*/
  1007. phpCAS :: traceEnd();
  1008. return $auth;
  1009. }
  1010. /**
  1011. * This method is called to renew the authentication.
  1012. *
  1013. * @return void
  1014. **/
  1015. public static function renewAuthentication()
  1016. {
  1017. phpCAS :: traceBegin();
  1018. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1019. phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1020. }
  1021. $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
  1022. // store where the authentication has been checked and the result
  1023. self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
  1024. //self::$_PHPCAS_CLIENT->renewAuthentication();
  1025. phpCAS :: traceEnd();
  1026. }
  1027. /**
  1028. * This method is called to check if the user is authenticated (previously or by
  1029. * tickets given in the URL).
  1030. *
  1031. * @return true when the user is authenticated.
  1032. */
  1033. public static function isAuthenticated()
  1034. {
  1035. phpCAS :: traceBegin();
  1036. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1037. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1038. }
  1039. // call the isAuthenticated method of the $_PHPCAS_CLIENT object
  1040. $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
  1041. // store where the authentication has been checked and the result
  1042. self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
  1043. phpCAS :: traceEnd($auth);
  1044. return $auth;
  1045. }
  1046. /**
  1047. * Checks whether authenticated based on $_SESSION. Useful to avoid
  1048. * server calls.
  1049. *
  1050. * @return bool true if authenticated, false otherwise.
  1051. * @since 0.4.22 by Brendan Arnold
  1052. */
  1053. public static function isSessionAuthenticated()
  1054. {
  1055. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1056. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1057. }
  1058. return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
  1059. }
  1060. /**
  1061. * This method returns the CAS user's login name.
  1062. *
  1063. * @return string the login name of the authenticated user
  1064. * @warning should not be called only after phpCAS::forceAuthentication()
  1065. * or phpCAS::checkAuthentication().
  1066. * */
  1067. public static function getUser()
  1068. {
  1069. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1070. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1071. }
  1072. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  1073. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
  1074. }
  1075. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  1076. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  1077. }
  1078. return self::$_PHPCAS_CLIENT->getUser();
  1079. }
  1080. /**
  1081. * Answer attributes about the authenticated user.
  1082. *
  1083. * @warning should not be called only after phpCAS::forceAuthentication()
  1084. * or phpCAS::checkAuthentication().
  1085. *
  1086. * @return array
  1087. */
  1088. public static function getAttributes()
  1089. {
  1090. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1091. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1092. }
  1093. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  1094. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
  1095. }
  1096. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  1097. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  1098. }
  1099. return self::$_PHPCAS_CLIENT->getAttributes();
  1100. }
  1101. /**
  1102. * Answer true if there are attributes for the authenticated user.
  1103. *
  1104. * @warning should not be called only after phpCAS::forceAuthentication()
  1105. * or phpCAS::checkAuthentication().
  1106. *
  1107. * @return bool
  1108. */
  1109. public static function hasAttributes()
  1110. {
  1111. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1112. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1113. }
  1114. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  1115. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
  1116. }
  1117. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  1118. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  1119. }
  1120. return self::$_PHPCAS_CLIENT->hasAttributes();
  1121. }
  1122. /**
  1123. * Answer true if an attribute exists for the authenticated user.
  1124. *
  1125. * @param string $key attribute name
  1126. *
  1127. * @return bool
  1128. * @warning should not be called only after phpCAS::forceAuthentication()
  1129. * or phpCAS::checkAuthentication().
  1130. */
  1131. public static function hasAttribute($key)
  1132. {
  1133. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1134. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1135. }
  1136. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  1137. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
  1138. }
  1139. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  1140. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  1141. }
  1142. return self::$_PHPCAS_CLIENT->hasAttribute($key);
  1143. }
  1144. /**
  1145. * Answer an attribute for the authenticated user.
  1146. *
  1147. * @param string $key attribute name
  1148. *
  1149. * @return mixed string for a single value or an array if multiple values exist.
  1150. * @warning should not be called only after phpCAS::forceAuthentication()
  1151. * or phpCAS::checkAuthentication().
  1152. */
  1153. public static function getAttribute($key)
  1154. {
  1155. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1156. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1157. }
  1158. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
  1159. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
  1160. }
  1161. if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
  1162. phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
  1163. }
  1164. return self::$_PHPCAS_CLIENT->getAttribute($key);
  1165. }
  1166. /**
  1167. * Handle logout requests.
  1168. *
  1169. * @param bool $check_client additional safety check
  1170. * @param array $allowed_clients array of allowed clients
  1171. *
  1172. * @return void
  1173. */
  1174. public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
  1175. {
  1176. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1177. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1178. }
  1179. return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
  1180. }
  1181. /**
  1182. * This method returns the URL to be used to login.
  1183. * or phpCAS::isAuthenticated().
  1184. *
  1185. * @return the login name of the authenticated user
  1186. */
  1187. public static function getServerLoginURL()
  1188. {
  1189. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1190. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1191. }
  1192. return self::$_PHPCAS_CLIENT->getServerLoginURL();
  1193. }
  1194. /**
  1195. * Set the login URL of the CAS server.
  1196. *
  1197. * @param string $url the login URL
  1198. *
  1199. * @return void
  1200. * @since 0.4.21 by Wyman Chan
  1201. */
  1202. public static function setServerLoginURL($url = '')
  1203. {
  1204. phpCAS :: traceBegin();
  1205. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1206. phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
  1207. }
  1208. if (gettype($url) != 'string') {
  1209. phpCAS :: error('type mismatched for parameter $url (should be `string`)');
  1210. }
  1211. self::$_PHPCAS_CLIENT->setServerLoginURL($url);
  1212. phpCAS :: traceEnd();
  1213. }
  1214. /**
  1215. * Set the serviceValidate URL of the CAS server.
  1216. * Used only in CAS 1.0 validations
  1217. *
  1218. * @param string $url the serviceValidate URL
  1219. *
  1220. * @return void
  1221. */
  1222. public static function setServerServiceValidateURL($url = '')
  1223. {
  1224. phpCAS :: traceBegin();
  1225. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1226. phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
  1227. }
  1228. if (gettype($url) != 'string') {
  1229. phpCAS :: error('type mismatched for parameter $url (should be `string`)');
  1230. }
  1231. self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
  1232. phpCAS :: traceEnd();
  1233. }
  1234. /**
  1235. * Set the proxyValidate URL of the CAS server.
  1236. * Used for all CAS 2.0 validations
  1237. *
  1238. * @param string $url the proxyValidate URL
  1239. *
  1240. * @return void
  1241. */
  1242. public static function setServerProxyValidateURL($url = '')
  1243. {
  1244. phpCAS :: traceBegin();
  1245. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1246. phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
  1247. }
  1248. if (gettype($url) != 'string') {
  1249. phpCAS :: error('type mismatched for parameter $url (should be `string`)');
  1250. }
  1251. self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
  1252. phpCAS :: traceEnd();
  1253. }
  1254. /**
  1255. * Set the samlValidate URL of the CAS server.
  1256. *
  1257. * @param string $url the samlValidate URL
  1258. *
  1259. * @return void
  1260. */
  1261. public static function setServerSamlValidateURL($url = '')
  1262. {
  1263. phpCAS :: traceBegin();
  1264. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1265. phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
  1266. }
  1267. if (gettype($url) != 'string') {
  1268. phpCAS :: error('type mismatched for parameter $url (should be`string\')');
  1269. }
  1270. self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
  1271. phpCAS :: traceEnd();
  1272. }
  1273. /**
  1274. * This method returns the URL to be used to login.
  1275. * or phpCAS::isAuthenticated().
  1276. *
  1277. * @return the login name of the authenticated user
  1278. */
  1279. public static function getServerLogoutURL()
  1280. {
  1281. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1282. phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
  1283. }
  1284. return self::$_PHPCAS_CLIENT->getServerLogoutURL();
  1285. }
  1286. /**
  1287. * Set the logout URL of the CAS server.
  1288. *
  1289. * @param string $url the logout URL
  1290. *
  1291. * @return void
  1292. * @since 0.4.21 by Wyman Chan
  1293. */
  1294. public static function setServerLogoutURL($url = '')
  1295. {
  1296. phpCAS :: traceBegin();
  1297. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1298. phpCAS :: error(
  1299. 'this method should only be called after' . __CLASS__ . '::client()'
  1300. );
  1301. }
  1302. if (gettype($url) != 'string') {
  1303. phpCAS :: error(
  1304. 'type mismatched for parameter $url (should be `string`)'
  1305. );
  1306. }
  1307. self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
  1308. phpCAS :: traceEnd();
  1309. }
  1310. /**
  1311. * This method is used to logout from CAS.
  1312. *
  1313. * @param string $params an array that contains the optional url and
  1314. * service parameters that will be passed to the CAS server
  1315. *
  1316. * @return void
  1317. */
  1318. public static function logout($params = "")
  1319. {
  1320. phpCAS :: traceBegin();
  1321. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1322. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1323. }
  1324. $parsedParams = array ();
  1325. if ($params != "") {
  1326. if (is_string($params)) {
  1327. phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
  1328. }
  1329. if (!is_array($params)) {
  1330. phpCAS :: error('type mismatched for parameter $params (should be `array\')');
  1331. }
  1332. foreach ($params as $key => $value) {
  1333. if ($key != "service" && $key != "url") {
  1334. phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
  1335. }
  1336. $parsedParams[$key] = $value;
  1337. }
  1338. }
  1339. self::$_PHPCAS_CLIENT->logout($parsedParams);
  1340. // never reached
  1341. phpCAS :: traceEnd();
  1342. }
  1343. /**
  1344. * This method is used to logout from CAS. Halts by redirecting to the CAS
  1345. * server.
  1346. *
  1347. * @param service $service a URL that will be transmitted to the CAS server
  1348. *
  1349. * @return void
  1350. */
  1351. public static function logoutWithRedirectService($service)
  1352. {
  1353. phpCAS :: traceBegin();
  1354. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1355. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1356. }
  1357. if (!is_string($service)) {
  1358. phpCAS :: error('type mismatched for parameter $service (should be `string\')');
  1359. }
  1360. self::$_PHPCAS_CLIENT->logout(array ( "service" => $service ));
  1361. // never reached
  1362. phpCAS :: traceEnd();
  1363. }
  1364. /**
  1365. * This method is used to logout from CAS. Halts by redirecting to the CAS
  1366. * server.
  1367. *
  1368. * @param string $url a URL that will be transmitted to the CAS server
  1369. *
  1370. * @return void
  1371. * @deprecated The url parameter has been removed from the CAS server as of
  1372. * version 3.3.5.1
  1373. */
  1374. public static function logoutWithUrl($url)
  1375. {
  1376. trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
  1377. phpCAS :: traceBegin();
  1378. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1379. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1380. }
  1381. if (!is_string($url)) {
  1382. phpCAS :: error('type mismatched for parameter $url (should be `string\')');
  1383. }
  1384. self::$_PHPCAS_CLIENT->logout(array ( "url" => $url ));
  1385. // never reached
  1386. phpCAS :: traceEnd();
  1387. }
  1388. /**
  1389. * This method is used to logout from CAS. Halts by redirecting to the CAS
  1390. * server.
  1391. *
  1392. * @param string $service a URL that will be transmitted to the CAS server
  1393. * @param string $url a URL that will be transmitted to the CAS server
  1394. *
  1395. * @return void
  1396. *
  1397. * @deprecated The url parameter has been removed from the CAS server as of
  1398. * version 3.3.5.1
  1399. */
  1400. public static function logoutWithRedirectServiceAndUrl($service, $url)
  1401. {
  1402. trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
  1403. phpCAS :: traceBegin();
  1404. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1405. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1406. }
  1407. if (!is_string($service)) {
  1408. phpCAS :: error('type mismatched for parameter $service (should be `string\')');
  1409. }
  1410. if (!is_string($url)) {
  1411. phpCAS :: error('type mismatched for parameter $url (should be `string\')');
  1412. }
  1413. self::$_PHPCAS_CLIENT->logout(
  1414. array (
  1415. "service" => $service,
  1416. "url" => $url
  1417. )
  1418. );
  1419. // never reached
  1420. phpCAS :: traceEnd();
  1421. }
  1422. /**
  1423. * Set the fixed URL that will be used by the CAS server to transmit the
  1424. * PGT. When this method is not called, a phpCAS script uses its own URL
  1425. * for the callback.
  1426. *
  1427. * @param string $url the URL
  1428. *
  1429. * @return void
  1430. */
  1431. public static function setFixedCallbackURL($url = '')
  1432. {
  1433. phpCAS :: traceBegin();
  1434. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1435. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  1436. }
  1437. if (!self::$_PHPCAS_CLIENT->isProxy()) {
  1438. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  1439. }
  1440. if (gettype($url) != 'string') {
  1441. phpCAS :: error('type mismatched for parameter $url (should be `string\')');
  1442. }
  1443. self::$_PHPCAS_CLIENT->setCallbackURL($url);
  1444. phpCAS :: traceEnd();
  1445. }
  1446. /**
  1447. * Set the fixed URL that will be set as the CAS service parameter. When this
  1448. * method is not called, a phpCAS script uses its own URL.
  1449. *
  1450. * @param string $url the URL
  1451. *
  1452. * @return void
  1453. */
  1454. public static function setFixedServiceURL($url)
  1455. {
  1456. phpCAS :: traceBegin();
  1457. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1458. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  1459. }
  1460. if (gettype($url) != 'string') {
  1461. phpCAS :: error('type mismatched for parameter $url (should be `string\')');
  1462. }
  1463. self::$_PHPCAS_CLIENT->setURL($url);
  1464. phpCAS :: traceEnd();
  1465. }
  1466. /**
  1467. * Get the URL that is set as the CAS service parameter.
  1468. *
  1469. * @return string Service Url
  1470. */
  1471. public static function getServiceURL()
  1472. {
  1473. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1474. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  1475. }
  1476. return (self::$_PHPCAS_CLIENT->getURL());
  1477. }
  1478. /**
  1479. * Retrieve a Proxy Ticket from the CAS server.
  1480. *
  1481. * @param string $target_service Url string of service to proxy
  1482. * @param string &$err_code error code
  1483. * @param string &$err_msg error message
  1484. *
  1485. * @return string Proxy Ticket
  1486. */
  1487. public static function retrievePT($target_service, & $err_code, & $err_msg)
  1488. {
  1489. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1490. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
  1491. }
  1492. if (gettype($target_service) != 'string') {
  1493. phpCAS :: error('type mismatched for parameter $target_service(should be `string\')');
  1494. }
  1495. return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
  1496. }
  1497. /**
  1498. * Set the certificate of the CAS server CA and if the CN should be properly
  1499. * verified.
  1500. *
  1501. * @param string $cert CA certificate file name
  1502. * @param bool $validate_cn Validate CN in certificate (default true)
  1503. *
  1504. * @return void
  1505. */
  1506. public static function setCasServerCACert($cert, $validate_cn = true)
  1507. {
  1508. phpCAS :: traceBegin();
  1509. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1510. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1511. }
  1512. if (gettype($cert) != 'string') {
  1513. phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
  1514. }
  1515. if (gettype($validate_cn) != 'boolean') {
  1516. phpCAS :: error('type mismatched for parameter $validate_cn (should be `boolean\')');
  1517. }
  1518. self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
  1519. phpCAS :: traceEnd();
  1520. }
  1521. /**
  1522. * Set no SSL validation for the CAS server.
  1523. *
  1524. * @return void
  1525. */
  1526. public static function setNoCasServerValidation()
  1527. {
  1528. phpCAS :: traceBegin();
  1529. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1530. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1531. }
  1532. phpCAS :: trace('You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
  1533. self::$_PHPCAS_CLIENT->setNoCasServerValidation();
  1534. phpCAS :: traceEnd();
  1535. }
  1536. /**
  1537. * Disable the removal of a CAS-Ticket from the URL when authenticating
  1538. * DISABLING POSES A SECURITY RISK:
  1539. * We normally remove the ticket by an additional redirect as a security
  1540. * precaution to prevent a ticket in the HTTP_REFERRER or be carried over in
  1541. * the URL parameter
  1542. *
  1543. * @return void
  1544. */
  1545. public static function setNoClearTicketsFromUrl()
  1546. {
  1547. phpCAS :: traceBegin();
  1548. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1549. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1550. }
  1551. self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
  1552. phpCAS :: traceEnd();
  1553. }
  1554. /** @} */
  1555. /**
  1556. * Change CURL options.
  1557. * CURL is used to connect through HTTPS to CAS server
  1558. *
  1559. * @param string $key the option key
  1560. * @param string $value the value to set
  1561. *
  1562. * @return void
  1563. */
  1564. public static function setExtraCurlOption($key, $value)
  1565. {
  1566. phpCAS :: traceBegin();
  1567. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1568. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1569. }
  1570. self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
  1571. phpCAS :: traceEnd();
  1572. }
  1573. /**
  1574. * If you want your service to be proxied you have to enable it (default
  1575. * disabled) and define an accepable list of proxies that are allowed to
  1576. * proxy your service.
  1577. *
  1578. * Add each allowed proxy definition object. For the normal CAS_ProxyChain
  1579. * class, the constructor takes an array of proxies to match. The list is in
  1580. * reverse just as seen from the service. Proxies have to be defined in reverse
  1581. * from the service to the user. If a user hits service A and gets proxied via
  1582. * B to service C the list of acceptable on C would be array(B,A). The definition
  1583. * of an individual proxy can be either a string or a regexp (preg_match is used)
  1584. * that will be matched against the proxy list supplied by the cas server
  1585. * when validating the proxy tickets. The strings are compared starting from
  1586. * the beginning and must fully match with the proxies in the list.
  1587. * Example:
  1588. * phpCAS::allowProxyChain(new CAS_ProxyChain(array(
  1589. * 'https://app.example.com/'
  1590. * )));
  1591. * phpCAS::allowProxyChain(new CAS_ProxyChain(array(
  1592. * '/^https:\/\/app[0-9]\.example\.com\/rest\//',
  1593. * 'http://client.example.com/'
  1594. * )));
  1595. *
  1596. * For quick testing or in certain production screnarios you might want to
  1597. * allow allow any other valid service to proxy your service. To do so, add
  1598. * the "Any" chain:
  1599. * phpcas::allowProxyChain(new CAS_ProxyChain_Any);
  1600. * THIS SETTING IS HOWEVER NOT RECOMMENDED FOR PRODUCTION AND HAS SECURITY
  1601. * IMPLICATIONS: YOU ARE ALLOWING ANY SERVICE TO ACT ON BEHALF OF A USER
  1602. * ON THIS SERVICE.
  1603. *
  1604. * @param CAS_ProxyChain_Interface $proxy_chain A proxy-chain that will be
  1605. * matched against the proxies requesting access
  1606. *
  1607. * @return void
  1608. */
  1609. public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
  1610. {
  1611. phpCAS :: traceBegin();
  1612. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1613. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1614. }
  1615. if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0) {
  1616. phpCAS :: error('this method can only be used with the cas 2.0 protool');
  1617. }
  1618. self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
  1619. phpCAS :: traceEnd();
  1620. }
  1621. /**
  1622. * Answer an array of proxies that are sitting in front of this application.
  1623. * This method will only return a non-empty array if we have received and
  1624. * validated a Proxy Ticket.
  1625. *
  1626. * @return array
  1627. * @access public
  1628. * @since 6/25/09
  1629. */
  1630. public static function getProxies ()
  1631. {
  1632. if ( !is_object(self::$_PHPCAS_CLIENT) ) {
  1633. phpCAS::error('this method should only be called after '.__CLASS__.'::client()');
  1634. }
  1635. return(self::$_PHPCAS_CLIENT->getProxies());
  1636. }
  1637. // ########################################################################
  1638. // PGTIOU/PGTID and logoutRequest rebroadcasting
  1639. // ########################################################################
  1640. /**
  1641. * Add a pgtIou/pgtId and logoutRequest rebroadcast node.
  1642. *
  1643. * @param string $rebroadcastNodeUrl The rebroadcast node URL. Can be
  1644. * hostname or IP.
  1645. *
  1646. * @return void
  1647. */
  1648. public static function addRebroadcastNode($rebroadcastNodeUrl)
  1649. {
  1650. phpCAS::traceBegin();
  1651. phpCAS::log('rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
  1652. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1653. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1654. }
  1655. if ( !(bool)preg_match("/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i", $rebroadcastNodeUrl)) {
  1656. phpCAS::error('type mismatched for parameter $rebroadcastNodeUrl (should be `url\')');
  1657. }
  1658. self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
  1659. phpCAS::traceEnd();
  1660. }
  1661. /**
  1662. * This method is used to add header parameters when rebroadcasting
  1663. * pgtIou/pgtId or logoutRequest.
  1664. *
  1665. * @param String $header Header to send when rebroadcasting.
  1666. *
  1667. * @return void
  1668. */
  1669. public static function addRebroadcastHeader($header)
  1670. {
  1671. phpCAS :: traceBegin();
  1672. if (!is_object(self::$_PHPCAS_CLIENT)) {
  1673. phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
  1674. }
  1675. self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
  1676. phpCAS :: traceEnd();
  1677. }
  1678. }
  1679. // ########################################################################
  1680. // DOCUMENTATION
  1681. // ########################################################################
  1682. // ########################################################################
  1683. // MAIN PAGE
  1684. /**
  1685. * @mainpage
  1686. *
  1687. * The following pages only show the source documentation.
  1688. *
  1689. */
  1690. // ########################################################################
  1691. // MODULES DEFINITION
  1692. /** @defgroup public User interface */
  1693. /** @defgroup publicInit Initialization
  1694. * @ingroup public */
  1695. /** @defgroup publicAuth Authentication
  1696. * @ingroup public */
  1697. /** @defgroup publicServices Access to external services
  1698. * @ingroup public */
  1699. /** @defgroup publicConfig Configuration
  1700. * @ingroup public */
  1701. /** @defgroup publicLang Internationalization
  1702. * @ingroup publicConfig */
  1703. /** @defgroup publicOutput HTML output
  1704. * @ingroup publicConfig */
  1705. /** @defgroup publicPGTStorage PGT storage
  1706. * @ingroup publicConfig */
  1707. /** @defgroup publicDebug Debugging
  1708. * @ingroup public */
  1709. /** @defgroup internal Implementation */
  1710. /** @defgroup internalAuthentication Authentication
  1711. * @ingroup internal */
  1712. /** @defgroup internalBasic CAS Basic client features (CAS 1.0, Service Tickets)
  1713. * @ingroup internal */
  1714. /** @defgroup internalProxy CAS Proxy features (CAS 2.0, Proxy Granting Tickets)
  1715. * @ingroup internal */
  1716. /** @defgroup internalSAML CAS SAML features (SAML 1.1)
  1717. * @ingroup internal */
  1718. /** @defgroup internalPGTStorage PGT storage
  1719. * @ingroup internalProxy */
  1720. /** @defgroup internalPGTStorageDb PGT storage in a database
  1721. * @ingroup internalPGTStorage */
  1722. /** @defgroup internalPGTStorageFile PGT storage on the filesystem
  1723. * @ingroup internalPGTStorage */
  1724. /** @defgroup internalCallback Callback from the CAS server
  1725. * @ingroup internalProxy */
  1726. /** @defgroup internalProxyServices Proxy other services
  1727. * @ingroup internalProxy */
  1728. /** @defgroup internalService CAS client features (CAS 2.0, Proxied service)
  1729. * @ingroup internal */
  1730. /** @defgroup internalConfig Configuration
  1731. * @ingroup internal */
  1732. /** @defgroup internalBehave Internal behaviour of phpCAS
  1733. * @ingroup internalConfig */
  1734. /** @defgroup internalOutput HTML output
  1735. * @ingroup internalConfig */
  1736. /** @defgroup internalLang Internationalization
  1737. * @ingroup internalConfig
  1738. *
  1739. * To add a new language:
  1740. * - 1. define a new constant PHPCAS_LANG_XXXXXX in CAS/CAS.php
  1741. * - 2. copy any file from CAS/languages to CAS/languages/XXXXXX.php
  1742. * - 3. Make the translations
  1743. */
  1744. /** @defgroup internalDebug Debugging
  1745. * @ingroup internal */
  1746. /** @defgroup internalMisc Miscellaneous
  1747. * @ingroup internal */
  1748. // ########################################################################
  1749. // EXAMPLES
  1750. /**
  1751. * @example example_simple.php
  1752. */
  1753. /**
  1754. * @example example_service.php
  1755. */
  1756. /**
  1757. * @example example_service_that_proxies.php
  1758. */
  1759. /**
  1760. * @example example_service_POST.php
  1761. */
  1762. /**
  1763. * @example example_proxy_serviceWeb.php
  1764. */
  1765. /**
  1766. * @example example_proxy_serviceWeb_chaining.php
  1767. */
  1768. /**
  1769. * @example example_proxy_POST.php
  1770. */
  1771. /**
  1772. * @example example_proxy_GET.php
  1773. */
  1774. /**
  1775. * @example example_lang.php
  1776. */
  1777. /**
  1778. * @example example_html.php
  1779. */
  1780. /**
  1781. * @example example_pgt_storage_file.php
  1782. */
  1783. /**
  1784. * @example example_pgt_storage_db.php
  1785. */
  1786. /**
  1787. * @example example_gateway.php
  1788. */
  1789. /**
  1790. * @example example_logout.php
  1791. */
  1792. /**
  1793. * @example example_rebroadcast.php
  1794. */
  1795. /**
  1796. * @example example_custom_urls.php
  1797. */
  1798. /**
  1799. * @example example_advanced_saml11.php
  1800. */
  1801. ?>