PageRenderTime 134ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/auth/cas/CAS/CAS/Client.php

https://bitbucket.org/moodle/moodle
PHP | 4004 lines | 2354 code | 286 blank | 1364 comment | 321 complexity | 5cc3f5381cafb2017c80b3d587410957 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  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. * PHP Version 5
  20. *
  21. * @file CAS/Client.php
  22. * @category Authentication
  23. * @package PhpCAS
  24. * @author Pascal Aubry <pascal.aubry@univ-rennes1.fr>
  25. * @author Olivier Berger <olivier.berger@it-sudparis.eu>
  26. * @author Brett Bieber <brett.bieber@gmail.com>
  27. * @author Joachim Fritschi <jfritschi@freenet.de>
  28. * @author Adam Franco <afranco@middlebury.edu>
  29. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  30. * @link https://wiki.jasig.org/display/CASC/phpCAS
  31. */
  32. /**
  33. * The CAS_Client class is a client interface that provides CAS authentication
  34. * to PHP applications.
  35. *
  36. * @class CAS_Client
  37. * @category Authentication
  38. * @package PhpCAS
  39. * @author Pascal Aubry <pascal.aubry@univ-rennes1.fr>
  40. * @author Olivier Berger <olivier.berger@it-sudparis.eu>
  41. * @author Brett Bieber <brett.bieber@gmail.com>
  42. * @author Joachim Fritschi <jfritschi@freenet.de>
  43. * @author Adam Franco <afranco@middlebury.edu>
  44. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  45. * @link https://wiki.jasig.org/display/CASC/phpCAS
  46. *
  47. */
  48. class CAS_Client
  49. {
  50. // ########################################################################
  51. // HTML OUTPUT
  52. // ########################################################################
  53. /**
  54. * @addtogroup internalOutput
  55. * @{
  56. */
  57. /**
  58. * This method filters a string by replacing special tokens by appropriate values
  59. * and prints it. The corresponding tokens are taken into account:
  60. * - __CAS_VERSION__
  61. * - __PHPCAS_VERSION__
  62. * - __SERVER_BASE_URL__
  63. *
  64. * Used by CAS_Client::PrintHTMLHeader() and CAS_Client::printHTMLFooter().
  65. *
  66. * @param string $str the string to filter and output
  67. *
  68. * @return void
  69. */
  70. private function _htmlFilterOutput($str)
  71. {
  72. $str = str_replace('__CAS_VERSION__', $this->getServerVersion(), $str);
  73. $str = str_replace('__PHPCAS_VERSION__', phpCAS::getVersion(), $str);
  74. $str = str_replace('__SERVER_BASE_URL__', $this->_getServerBaseURL(), $str);
  75. echo $str;
  76. }
  77. /**
  78. * A string used to print the header of HTML pages. Written by
  79. * CAS_Client::setHTMLHeader(), read by CAS_Client::printHTMLHeader().
  80. *
  81. * @hideinitializer
  82. * @see CAS_Client::setHTMLHeader, CAS_Client::printHTMLHeader()
  83. */
  84. private $_output_header = '';
  85. /**
  86. * This method prints the header of the HTML output (after filtering). If
  87. * CAS_Client::setHTMLHeader() was not used, a default header is output.
  88. *
  89. * @param string $title the title of the page
  90. *
  91. * @return void
  92. * @see _htmlFilterOutput()
  93. */
  94. public function printHTMLHeader($title)
  95. {
  96. $this->_htmlFilterOutput(
  97. str_replace(
  98. '__TITLE__', $title,
  99. (empty($this->_output_header)
  100. ? '<html><head><title>__TITLE__</title></head><body><h1>__TITLE__</h1>'
  101. : $this->_output_header)
  102. )
  103. );
  104. }
  105. /**
  106. * A string used to print the footer of HTML pages. Written by
  107. * CAS_Client::setHTMLFooter(), read by printHTMLFooter().
  108. *
  109. * @hideinitializer
  110. * @see CAS_Client::setHTMLFooter, CAS_Client::printHTMLFooter()
  111. */
  112. private $_output_footer = '';
  113. /**
  114. * This method prints the footer of the HTML output (after filtering). If
  115. * CAS_Client::setHTMLFooter() was not used, a default footer is output.
  116. *
  117. * @return void
  118. * @see _htmlFilterOutput()
  119. */
  120. public function printHTMLFooter()
  121. {
  122. $lang = $this->getLangObj();
  123. $this->_htmlFilterOutput(
  124. empty($this->_output_footer)?
  125. (phpCAS::getVerbose())?
  126. '<hr><address>phpCAS __PHPCAS_VERSION__ '
  127. .$lang->getUsingServer()
  128. .' <a href="__SERVER_BASE_URL__">__SERVER_BASE_URL__</a> (CAS __CAS_VERSION__)</a></address></body></html>'
  129. :'</body></html>'
  130. :$this->_output_footer
  131. );
  132. }
  133. /**
  134. * This method set the HTML header used for all outputs.
  135. *
  136. * @param string $header the HTML header.
  137. *
  138. * @return void
  139. */
  140. public function setHTMLHeader($header)
  141. {
  142. // Argument Validation
  143. if (gettype($header) != 'string')
  144. throw new CAS_TypeMismatchException($header, '$header', 'string');
  145. $this->_output_header = $header;
  146. }
  147. /**
  148. * This method set the HTML footer used for all outputs.
  149. *
  150. * @param string $footer the HTML footer.
  151. *
  152. * @return void
  153. */
  154. public function setHTMLFooter($footer)
  155. {
  156. // Argument Validation
  157. if (gettype($footer) != 'string')
  158. throw new CAS_TypeMismatchException($footer, '$footer', 'string');
  159. $this->_output_footer = $footer;
  160. }
  161. /** @} */
  162. // ########################################################################
  163. // INTERNATIONALIZATION
  164. // ########################################################################
  165. /**
  166. * @addtogroup internalLang
  167. * @{
  168. */
  169. /**
  170. * A string corresponding to the language used by phpCAS. Written by
  171. * CAS_Client::setLang(), read by CAS_Client::getLang().
  172. * @note debugging information is always in english (debug purposes only).
  173. */
  174. private $_lang = PHPCAS_LANG_DEFAULT;
  175. /**
  176. * This method is used to set the language used by phpCAS.
  177. *
  178. * @param string $lang representing the language.
  179. *
  180. * @return void
  181. */
  182. public function setLang($lang)
  183. {
  184. // Argument Validation
  185. if (gettype($lang) != 'string')
  186. throw new CAS_TypeMismatchException($lang, '$lang', 'string');
  187. phpCAS::traceBegin();
  188. $obj = new $lang();
  189. if (!($obj instanceof CAS_Languages_LanguageInterface)) {
  190. throw new CAS_InvalidArgumentException(
  191. '$className must implement the CAS_Languages_LanguageInterface'
  192. );
  193. }
  194. $this->_lang = $lang;
  195. phpCAS::traceEnd();
  196. }
  197. /**
  198. * Create the language
  199. *
  200. * @return CAS_Languages_LanguageInterface object implementing the class
  201. */
  202. public function getLangObj()
  203. {
  204. $classname = $this->_lang;
  205. return new $classname();
  206. }
  207. /** @} */
  208. // ########################################################################
  209. // CAS SERVER CONFIG
  210. // ########################################################################
  211. /**
  212. * @addtogroup internalConfig
  213. * @{
  214. */
  215. /**
  216. * a record to store information about the CAS server.
  217. * - $_server['version']: the version of the CAS server
  218. * - $_server['hostname']: the hostname of the CAS server
  219. * - $_server['port']: the port the CAS server is running on
  220. * - $_server['uri']: the base URI the CAS server is responding on
  221. * - $_server['base_url']: the base URL of the CAS server
  222. * - $_server['login_url']: the login URL of the CAS server
  223. * - $_server['service_validate_url']: the service validating URL of the
  224. * CAS server
  225. * - $_server['proxy_url']: the proxy URL of the CAS server
  226. * - $_server['proxy_validate_url']: the proxy validating URL of the CAS server
  227. * - $_server['logout_url']: the logout URL of the CAS server
  228. *
  229. * $_server['version'], $_server['hostname'], $_server['port'] and
  230. * $_server['uri'] are written by CAS_Client::CAS_Client(), read by
  231. * CAS_Client::getServerVersion(), CAS_Client::_getServerHostname(),
  232. * CAS_Client::_getServerPort() and CAS_Client::_getServerURI().
  233. *
  234. * The other fields are written and read by CAS_Client::_getServerBaseURL(),
  235. * CAS_Client::getServerLoginURL(), CAS_Client::getServerServiceValidateURL(),
  236. * CAS_Client::getServerProxyValidateURL() and CAS_Client::getServerLogoutURL().
  237. *
  238. * @hideinitializer
  239. */
  240. private $_server = array(
  241. 'version' => '',
  242. 'hostname' => 'none',
  243. 'port' => -1,
  244. 'uri' => 'none');
  245. /**
  246. * This method is used to retrieve the version of the CAS server.
  247. *
  248. * @return string the version of the CAS server.
  249. */
  250. public function getServerVersion()
  251. {
  252. return $this->_server['version'];
  253. }
  254. /**
  255. * This method is used to retrieve the hostname of the CAS server.
  256. *
  257. * @return string the hostname of the CAS server.
  258. */
  259. private function _getServerHostname()
  260. {
  261. return $this->_server['hostname'];
  262. }
  263. /**
  264. * This method is used to retrieve the port of the CAS server.
  265. *
  266. * @return int the port of the CAS server.
  267. */
  268. private function _getServerPort()
  269. {
  270. return $this->_server['port'];
  271. }
  272. /**
  273. * This method is used to retrieve the URI of the CAS server.
  274. *
  275. * @return string a URI.
  276. */
  277. private function _getServerURI()
  278. {
  279. return $this->_server['uri'];
  280. }
  281. /**
  282. * This method is used to retrieve the base URL of the CAS server.
  283. *
  284. * @return string a URL.
  285. */
  286. private function _getServerBaseURL()
  287. {
  288. // the URL is build only when needed
  289. if ( empty($this->_server['base_url']) ) {
  290. $this->_server['base_url'] = 'https://' . $this->_getServerHostname();
  291. if ($this->_getServerPort()!=443) {
  292. $this->_server['base_url'] .= ':'
  293. .$this->_getServerPort();
  294. }
  295. $this->_server['base_url'] .= $this->_getServerURI();
  296. }
  297. return $this->_server['base_url'];
  298. }
  299. /**
  300. * This method is used to retrieve the login URL of the CAS server.
  301. *
  302. * @param bool $gateway true to check authentication, false to force it
  303. * @param bool $renew true to force the authentication with the CAS server
  304. *
  305. * @return string a URL.
  306. * @note It is recommended that CAS implementations ignore the "gateway"
  307. * parameter if "renew" is set
  308. */
  309. public function getServerLoginURL($gateway=false,$renew=false)
  310. {
  311. phpCAS::traceBegin();
  312. // the URL is build only when needed
  313. if ( empty($this->_server['login_url']) ) {
  314. $this->_server['login_url'] = $this->_buildQueryUrl($this->_getServerBaseURL().'login','service='.urlencode($this->getURL()));
  315. }
  316. $url = $this->_server['login_url'];
  317. if ($renew) {
  318. // It is recommended that when the "renew" parameter is set, its
  319. // value be "true"
  320. $url = $this->_buildQueryUrl($url, 'renew=true');
  321. } elseif ($gateway) {
  322. // It is recommended that when the "gateway" parameter is set, its
  323. // value be "true"
  324. $url = $this->_buildQueryUrl($url, 'gateway=true');
  325. }
  326. phpCAS::traceEnd($url);
  327. return $url;
  328. }
  329. /**
  330. * This method sets the login URL of the CAS server.
  331. *
  332. * @param string $url the login URL
  333. *
  334. * @return string login url
  335. */
  336. public function setServerLoginURL($url)
  337. {
  338. // Argument Validation
  339. if (gettype($url) != 'string')
  340. throw new CAS_TypeMismatchException($url, '$url', 'string');
  341. return $this->_server['login_url'] = $url;
  342. }
  343. /**
  344. * This method sets the serviceValidate URL of the CAS server.
  345. *
  346. * @param string $url the serviceValidate URL
  347. *
  348. * @return string serviceValidate URL
  349. */
  350. public function setServerServiceValidateURL($url)
  351. {
  352. // Argument Validation
  353. if (gettype($url) != 'string')
  354. throw new CAS_TypeMismatchException($url, '$url', 'string');
  355. return $this->_server['service_validate_url'] = $url;
  356. }
  357. /**
  358. * This method sets the proxyValidate URL of the CAS server.
  359. *
  360. * @param string $url the proxyValidate URL
  361. *
  362. * @return string proxyValidate URL
  363. */
  364. public function setServerProxyValidateURL($url)
  365. {
  366. // Argument Validation
  367. if (gettype($url) != 'string')
  368. throw new CAS_TypeMismatchException($url, '$url', 'string');
  369. return $this->_server['proxy_validate_url'] = $url;
  370. }
  371. /**
  372. * This method sets the samlValidate URL of the CAS server.
  373. *
  374. * @param string $url the samlValidate URL
  375. *
  376. * @return string samlValidate URL
  377. */
  378. public function setServerSamlValidateURL($url)
  379. {
  380. // Argument Validation
  381. if (gettype($url) != 'string')
  382. throw new CAS_TypeMismatchException($url, '$url', 'string');
  383. return $this->_server['saml_validate_url'] = $url;
  384. }
  385. /**
  386. * This method is used to retrieve the service validating URL of the CAS server.
  387. *
  388. * @return string serviceValidate URL.
  389. */
  390. public function getServerServiceValidateURL()
  391. {
  392. phpCAS::traceBegin();
  393. // the URL is build only when needed
  394. if ( empty($this->_server['service_validate_url']) ) {
  395. switch ($this->getServerVersion()) {
  396. case CAS_VERSION_1_0:
  397. $this->_server['service_validate_url'] = $this->_getServerBaseURL()
  398. .'validate';
  399. break;
  400. case CAS_VERSION_2_0:
  401. $this->_server['service_validate_url'] = $this->_getServerBaseURL()
  402. .'serviceValidate';
  403. break;
  404. case CAS_VERSION_3_0:
  405. $this->_server['service_validate_url'] = $this->_getServerBaseURL()
  406. .'p3/serviceValidate';
  407. break;
  408. }
  409. }
  410. $url = $this->_buildQueryUrl(
  411. $this->_server['service_validate_url'],
  412. 'service='.urlencode($this->getURL())
  413. );
  414. phpCAS::traceEnd($url);
  415. return $url;
  416. }
  417. /**
  418. * This method is used to retrieve the SAML validating URL of the CAS server.
  419. *
  420. * @return string samlValidate URL.
  421. */
  422. public function getServerSamlValidateURL()
  423. {
  424. phpCAS::traceBegin();
  425. // the URL is build only when needed
  426. if ( empty($this->_server['saml_validate_url']) ) {
  427. switch ($this->getServerVersion()) {
  428. case SAML_VERSION_1_1:
  429. $this->_server['saml_validate_url'] = $this->_getServerBaseURL().'samlValidate';
  430. break;
  431. }
  432. }
  433. $url = $this->_buildQueryUrl(
  434. $this->_server['saml_validate_url'],
  435. 'TARGET='.urlencode($this->getURL())
  436. );
  437. phpCAS::traceEnd($url);
  438. return $url;
  439. }
  440. /**
  441. * This method is used to retrieve the proxy validating URL of the CAS server.
  442. *
  443. * @return string proxyValidate URL.
  444. */
  445. public function getServerProxyValidateURL()
  446. {
  447. phpCAS::traceBegin();
  448. // the URL is build only when needed
  449. if ( empty($this->_server['proxy_validate_url']) ) {
  450. switch ($this->getServerVersion()) {
  451. case CAS_VERSION_1_0:
  452. $this->_server['proxy_validate_url'] = '';
  453. break;
  454. case CAS_VERSION_2_0:
  455. $this->_server['proxy_validate_url'] = $this->_getServerBaseURL().'proxyValidate';
  456. break;
  457. case CAS_VERSION_3_0:
  458. $this->_server['proxy_validate_url'] = $this->_getServerBaseURL().'p3/proxyValidate';
  459. break;
  460. }
  461. }
  462. $url = $this->_buildQueryUrl(
  463. $this->_server['proxy_validate_url'],
  464. 'service='.urlencode($this->getURL())
  465. );
  466. phpCAS::traceEnd($url);
  467. return $url;
  468. }
  469. /**
  470. * This method is used to retrieve the proxy URL of the CAS server.
  471. *
  472. * @return string proxy URL.
  473. */
  474. public function getServerProxyURL()
  475. {
  476. // the URL is build only when needed
  477. if ( empty($this->_server['proxy_url']) ) {
  478. switch ($this->getServerVersion()) {
  479. case CAS_VERSION_1_0:
  480. $this->_server['proxy_url'] = '';
  481. break;
  482. case CAS_VERSION_2_0:
  483. case CAS_VERSION_3_0:
  484. $this->_server['proxy_url'] = $this->_getServerBaseURL().'proxy';
  485. break;
  486. }
  487. }
  488. return $this->_server['proxy_url'];
  489. }
  490. /**
  491. * This method is used to retrieve the logout URL of the CAS server.
  492. *
  493. * @return string logout URL.
  494. */
  495. public function getServerLogoutURL()
  496. {
  497. // the URL is build only when needed
  498. if ( empty($this->_server['logout_url']) ) {
  499. $this->_server['logout_url'] = $this->_getServerBaseURL().'logout';
  500. }
  501. return $this->_server['logout_url'];
  502. }
  503. /**
  504. * This method sets the logout URL of the CAS server.
  505. *
  506. * @param string $url the logout URL
  507. *
  508. * @return string logout url
  509. */
  510. public function setServerLogoutURL($url)
  511. {
  512. // Argument Validation
  513. if (gettype($url) != 'string')
  514. throw new CAS_TypeMismatchException($url, '$url', 'string');
  515. return $this->_server['logout_url'] = $url;
  516. }
  517. /**
  518. * An array to store extra curl options.
  519. */
  520. private $_curl_options = array();
  521. /**
  522. * This method is used to set additional user curl options.
  523. *
  524. * @param string $key name of the curl option
  525. * @param string $value value of the curl option
  526. *
  527. * @return void
  528. */
  529. public function setExtraCurlOption($key, $value)
  530. {
  531. $this->_curl_options[$key] = $value;
  532. }
  533. /** @} */
  534. // ########################################################################
  535. // Change the internal behaviour of phpcas
  536. // ########################################################################
  537. /**
  538. * @addtogroup internalBehave
  539. * @{
  540. */
  541. /**
  542. * The class to instantiate for making web requests in readUrl().
  543. * The class specified must implement the CAS_Request_RequestInterface.
  544. * By default CAS_Request_CurlRequest is used, but this may be overridden to
  545. * supply alternate request mechanisms for testing.
  546. */
  547. private $_requestImplementation = 'CAS_Request_CurlRequest';
  548. /**
  549. * Override the default implementation used to make web requests in readUrl().
  550. * This class must implement the CAS_Request_RequestInterface.
  551. *
  552. * @param string $className name of the RequestImplementation class
  553. *
  554. * @return void
  555. */
  556. public function setRequestImplementation ($className)
  557. {
  558. $obj = new $className;
  559. if (!($obj instanceof CAS_Request_RequestInterface)) {
  560. throw new CAS_InvalidArgumentException(
  561. '$className must implement the CAS_Request_RequestInterface'
  562. );
  563. }
  564. $this->_requestImplementation = $className;
  565. }
  566. /**
  567. * @var boolean $_clearTicketsFromUrl; If true, phpCAS will clear session
  568. * tickets from the URL after a successful authentication.
  569. */
  570. private $_clearTicketsFromUrl = true;
  571. /**
  572. * Configure the client to not send redirect headers and call exit() on
  573. * authentication success. The normal redirect is used to remove the service
  574. * ticket from the client's URL, but for running unit tests we need to
  575. * continue without exiting.
  576. *
  577. * Needed for testing authentication
  578. *
  579. * @return void
  580. */
  581. public function setNoClearTicketsFromUrl ()
  582. {
  583. $this->_clearTicketsFromUrl = false;
  584. }
  585. /**
  586. * @var callback $_attributeParserCallbackFunction;
  587. */
  588. private $_casAttributeParserCallbackFunction = null;
  589. /**
  590. * @var array $_attributeParserCallbackArgs;
  591. */
  592. private $_casAttributeParserCallbackArgs = array();
  593. /**
  594. * Set a callback function to be run when parsing CAS attributes
  595. *
  596. * The callback function will be passed a XMLNode as its first parameter,
  597. * followed by any $additionalArgs you pass.
  598. *
  599. * @param string $function callback function to call
  600. * @param array $additionalArgs optional array of arguments
  601. *
  602. * @return void
  603. */
  604. public function setCasAttributeParserCallback($function, array $additionalArgs = array())
  605. {
  606. $this->_casAttributeParserCallbackFunction = $function;
  607. $this->_casAttributeParserCallbackArgs = $additionalArgs;
  608. }
  609. /** @var callable $_postAuthenticateCallbackFunction;
  610. */
  611. private $_postAuthenticateCallbackFunction = null;
  612. /**
  613. * @var array $_postAuthenticateCallbackArgs;
  614. */
  615. private $_postAuthenticateCallbackArgs = array();
  616. /**
  617. * Set a callback function to be run when a user authenticates.
  618. *
  619. * The callback function will be passed a $logoutTicket as its first parameter,
  620. * followed by any $additionalArgs you pass. The $logoutTicket parameter is an
  621. * opaque string that can be used to map a session-id to the logout request
  622. * in order to support single-signout in applications that manage their own
  623. * sessions (rather than letting phpCAS start the session).
  624. *
  625. * phpCAS::forceAuthentication() will always exit and forward client unless
  626. * they are already authenticated. To perform an action at the moment the user
  627. * logs in (such as registering an account, performing logging, etc), register
  628. * a callback function here.
  629. *
  630. * @param callable $function callback function to call
  631. * @param array $additionalArgs optional array of arguments
  632. *
  633. * @return void
  634. */
  635. public function setPostAuthenticateCallback ($function, array $additionalArgs = array())
  636. {
  637. $this->_postAuthenticateCallbackFunction = $function;
  638. $this->_postAuthenticateCallbackArgs = $additionalArgs;
  639. }
  640. /**
  641. * @var callable $_signoutCallbackFunction;
  642. */
  643. private $_signoutCallbackFunction = null;
  644. /**
  645. * @var array $_signoutCallbackArgs;
  646. */
  647. private $_signoutCallbackArgs = array();
  648. /**
  649. * Set a callback function to be run when a single-signout request is received.
  650. *
  651. * The callback function will be passed a $logoutTicket as its first parameter,
  652. * followed by any $additionalArgs you pass. The $logoutTicket parameter is an
  653. * opaque string that can be used to map a session-id to the logout request in
  654. * order to support single-signout in applications that manage their own sessions
  655. * (rather than letting phpCAS start and destroy the session).
  656. *
  657. * @param callable $function callback function to call
  658. * @param array $additionalArgs optional array of arguments
  659. *
  660. * @return void
  661. */
  662. public function setSingleSignoutCallback ($function, array $additionalArgs = array())
  663. {
  664. $this->_signoutCallbackFunction = $function;
  665. $this->_signoutCallbackArgs = $additionalArgs;
  666. }
  667. // ########################################################################
  668. // Methods for supplying code-flow feedback to integrators.
  669. // ########################################################################
  670. /**
  671. * Ensure that this is actually a proxy object or fail with an exception
  672. *
  673. * @throws CAS_OutOfSequenceBeforeProxyException
  674. *
  675. * @return void
  676. */
  677. public function ensureIsProxy()
  678. {
  679. if (!$this->isProxy()) {
  680. throw new CAS_OutOfSequenceBeforeProxyException();
  681. }
  682. }
  683. /**
  684. * Mark the caller of authentication. This will help client integraters determine
  685. * problems with their code flow if they call a function such as getUser() before
  686. * authentication has occurred.
  687. *
  688. * @param bool $auth True if authentication was successful, false otherwise.
  689. *
  690. * @return null
  691. */
  692. public function markAuthenticationCall ($auth)
  693. {
  694. // store where the authentication has been checked and the result
  695. $dbg = debug_backtrace();
  696. $this->_authentication_caller = array (
  697. 'file' => $dbg[1]['file'],
  698. 'line' => $dbg[1]['line'],
  699. 'method' => $dbg[1]['class'] . '::' . $dbg[1]['function'],
  700. 'result' => (boolean)$auth
  701. );
  702. }
  703. private $_authentication_caller;
  704. /**
  705. * Answer true if authentication has been checked.
  706. *
  707. * @return bool
  708. */
  709. public function wasAuthenticationCalled ()
  710. {
  711. return !empty($this->_authentication_caller);
  712. }
  713. /**
  714. * Ensure that authentication was checked. Terminate with exception if no
  715. * authentication was performed
  716. *
  717. * @throws CAS_OutOfSequenceBeforeAuthenticationCallException
  718. *
  719. * @return void
  720. */
  721. private function _ensureAuthenticationCalled()
  722. {
  723. if (!$this->wasAuthenticationCalled()) {
  724. throw new CAS_OutOfSequenceBeforeAuthenticationCallException();
  725. }
  726. }
  727. /**
  728. * Answer the result of the authentication call.
  729. *
  730. * Throws a CAS_OutOfSequenceException if wasAuthenticationCalled() is false
  731. * and markAuthenticationCall() didn't happen.
  732. *
  733. * @return bool
  734. */
  735. public function wasAuthenticationCallSuccessful ()
  736. {
  737. $this->_ensureAuthenticationCalled();
  738. return $this->_authentication_caller['result'];
  739. }
  740. /**
  741. * Ensure that authentication was checked. Terminate with exception if no
  742. * authentication was performed
  743. *
  744. * @throws CAS_OutOfSequenceException
  745. *
  746. * @return void
  747. */
  748. public function ensureAuthenticationCallSuccessful()
  749. {
  750. $this->_ensureAuthenticationCalled();
  751. if (!$this->_authentication_caller['result']) {
  752. throw new CAS_OutOfSequenceException(
  753. 'authentication was checked (by '
  754. . $this->getAuthenticationCallerMethod()
  755. . '() at ' . $this->getAuthenticationCallerFile()
  756. . ':' . $this->getAuthenticationCallerLine()
  757. . ') but the method returned false'
  758. );
  759. }
  760. }
  761. /**
  762. * Answer information about the authentication caller.
  763. *
  764. * Throws a CAS_OutOfSequenceException if wasAuthenticationCalled() is false
  765. * and markAuthenticationCall() didn't happen.
  766. *
  767. * @return string the file that called authentication
  768. */
  769. public function getAuthenticationCallerFile ()
  770. {
  771. $this->_ensureAuthenticationCalled();
  772. return $this->_authentication_caller['file'];
  773. }
  774. /**
  775. * Answer information about the authentication caller.
  776. *
  777. * Throws a CAS_OutOfSequenceException if wasAuthenticationCalled() is false
  778. * and markAuthenticationCall() didn't happen.
  779. *
  780. * @return int the line that called authentication
  781. */
  782. public function getAuthenticationCallerLine ()
  783. {
  784. $this->_ensureAuthenticationCalled();
  785. return $this->_authentication_caller['line'];
  786. }
  787. /**
  788. * Answer information about the authentication caller.
  789. *
  790. * Throws a CAS_OutOfSequenceException if wasAuthenticationCalled() is false
  791. * and markAuthenticationCall() didn't happen.
  792. *
  793. * @return string the method that called authentication
  794. */
  795. public function getAuthenticationCallerMethod ()
  796. {
  797. $this->_ensureAuthenticationCalled();
  798. return $this->_authentication_caller['method'];
  799. }
  800. /** @} */
  801. // ########################################################################
  802. // CONSTRUCTOR
  803. // ########################################################################
  804. /**
  805. * @addtogroup internalConfig
  806. * @{
  807. */
  808. /**
  809. * CAS_Client constructor.
  810. *
  811. * @param string $server_version the version of the CAS server
  812. * @param bool $proxy true if the CAS client is a CAS proxy
  813. * @param string $server_hostname the hostname of the CAS server
  814. * @param int $server_port the port the CAS server is running on
  815. * @param string $server_uri the URI the CAS server is responding on
  816. * @param bool $changeSessionID Allow phpCAS to change the session_id
  817. * (Single Sign Out/handleLogoutRequests
  818. * is based on that change)
  819. *
  820. * @return self a newly created CAS_Client object
  821. */
  822. public function __construct(
  823. $server_version,
  824. $proxy,
  825. $server_hostname,
  826. $server_port,
  827. $server_uri,
  828. $changeSessionID = true
  829. ) {
  830. // Argument validation
  831. if (gettype($server_version) != 'string')
  832. throw new CAS_TypeMismatchException($server_version, '$server_version', 'string');
  833. if (gettype($proxy) != 'boolean')
  834. throw new CAS_TypeMismatchException($proxy, '$proxy', 'boolean');
  835. if (gettype($server_hostname) != 'string')
  836. throw new CAS_TypeMismatchException($server_hostname, '$server_hostname', 'string');
  837. if (gettype($server_port) != 'integer')
  838. throw new CAS_TypeMismatchException($server_port, '$server_port', 'integer');
  839. if (gettype($server_uri) != 'string')
  840. throw new CAS_TypeMismatchException($server_uri, '$server_uri', 'string');
  841. if (gettype($changeSessionID) != 'boolean')
  842. throw new CAS_TypeMismatchException($changeSessionID, '$changeSessionID', 'boolean');
  843. phpCAS::traceBegin();
  844. // true : allow to change the session_id(), false session_id won't be
  845. // change and logout won't be handle because of that
  846. $this->_setChangeSessionID($changeSessionID);
  847. // skip Session Handling for logout requests and if don't want it'
  848. if (session_id()=="" && !$this->_isLogoutRequest()) {
  849. session_start();
  850. phpCAS :: trace("Starting a new session " . session_id());
  851. }
  852. // Only for debug purposes
  853. if ($this->isSessionAuthenticated()){
  854. phpCAS :: trace("Session is authenticated as: " . $_SESSION['phpCAS']['user']);
  855. } else {
  856. phpCAS :: trace("Session is not authenticated");
  857. }
  858. // are we in proxy mode ?
  859. $this->_proxy = $proxy;
  860. // Make cookie handling available.
  861. if ($this->isProxy()) {
  862. if (!isset($_SESSION['phpCAS'])) {
  863. $_SESSION['phpCAS'] = array();
  864. }
  865. if (!isset($_SESSION['phpCAS']['service_cookies'])) {
  866. $_SESSION['phpCAS']['service_cookies'] = array();
  867. }
  868. $this->_serviceCookieJar = new CAS_CookieJar(
  869. $_SESSION['phpCAS']['service_cookies']
  870. );
  871. }
  872. // check version
  873. $supportedProtocols = phpCAS::getSupportedProtocols();
  874. if (isset($supportedProtocols[$server_version]) === false) {
  875. phpCAS::error(
  876. 'this version of CAS (`'.$server_version
  877. .'\') is not supported by phpCAS '.phpCAS::getVersion()
  878. );
  879. }
  880. if ($server_version === CAS_VERSION_1_0 && $this->isProxy()) {
  881. phpCAS::error(
  882. 'CAS proxies are not supported in CAS '.$server_version
  883. );
  884. }
  885. $this->_server['version'] = $server_version;
  886. // check hostname
  887. if ( empty($server_hostname)
  888. || !preg_match('/[\.\d\-a-z]*/', $server_hostname)
  889. ) {
  890. phpCAS::error('bad CAS server hostname (`'.$server_hostname.'\')');
  891. }
  892. $this->_server['hostname'] = $server_hostname;
  893. // check port
  894. if ( $server_port == 0
  895. || !is_int($server_port)
  896. ) {
  897. phpCAS::error('bad CAS server port (`'.$server_hostname.'\')');
  898. }
  899. $this->_server['port'] = $server_port;
  900. // check URI
  901. if ( !preg_match('/[\.\d\-_a-z\/]*/', $server_uri) ) {
  902. phpCAS::error('bad CAS server URI (`'.$server_uri.'\')');
  903. }
  904. // add leading and trailing `/' and remove doubles
  905. if(strstr($server_uri, '?') === false) $server_uri .= '/';
  906. $server_uri = preg_replace('/\/\//', '/', '/'.$server_uri);
  907. $this->_server['uri'] = $server_uri;
  908. // set to callback mode if PgtIou and PgtId CGI GET parameters are provided
  909. if ( $this->isProxy() ) {
  910. if(!empty($_GET['pgtIou'])&&!empty($_GET['pgtId'])) {
  911. $this->_setCallbackMode(true);
  912. $this->_setCallbackModeUsingPost(false);
  913. } elseif (!empty($_POST['pgtIou'])&&!empty($_POST['pgtId'])) {
  914. $this->_setCallbackMode(true);
  915. $this->_setCallbackModeUsingPost(true);
  916. } else {
  917. $this->_setCallbackMode(false);
  918. $this->_setCallbackModeUsingPost(false);
  919. }
  920. }
  921. if ( $this->_isCallbackMode() ) {
  922. //callback mode: check that phpCAS is secured
  923. if ( !$this->_isHttps() ) {
  924. phpCAS::error(
  925. 'CAS proxies must be secured to use phpCAS; PGT\'s will not be received from the CAS server'
  926. );
  927. }
  928. } else {
  929. //normal mode: get ticket and remove it from CGI parameters for
  930. // developers
  931. $ticket = (isset($_GET['ticket']) ? $_GET['ticket'] : null);
  932. if (preg_match('/^[SP]T-/', $ticket) ) {
  933. phpCAS::trace('Ticket \''.$ticket.'\' found');
  934. $this->setTicket($ticket);
  935. unset($_GET['ticket']);
  936. } else if ( !empty($ticket) ) {
  937. //ill-formed ticket, halt
  938. phpCAS::error(
  939. 'ill-formed ticket found in the URL (ticket=`'
  940. .htmlentities($ticket).'\')'
  941. );
  942. }
  943. }
  944. phpCAS::traceEnd();
  945. }
  946. /** @} */
  947. // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  948. // XX XX
  949. // XX Session Handling XX
  950. // XX XX
  951. // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  952. /**
  953. * @addtogroup internalConfig
  954. * @{
  955. */
  956. /**
  957. * @var bool A variable to whether phpcas will use its own session handling. Default = true
  958. * @hideinitializer
  959. */
  960. private $_change_session_id = true;
  961. /**
  962. * Set a parameter whether to allow phpCAS to change session_id
  963. *
  964. * @param bool $allowed allow phpCAS to change session_id
  965. *
  966. * @return void
  967. */
  968. private function _setChangeSessionID($allowed)
  969. {
  970. $this->_change_session_id = $allowed;
  971. }
  972. /**
  973. * Get whether phpCAS is allowed to change session_id
  974. *
  975. * @return bool
  976. */
  977. public function getChangeSessionID()
  978. {
  979. return $this->_change_session_id;
  980. }
  981. /** @} */
  982. // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  983. // XX XX
  984. // XX AUTHENTICATION XX
  985. // XX XX
  986. // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  987. /**
  988. * @addtogroup internalAuthentication
  989. * @{
  990. */
  991. /**
  992. * The Authenticated user. Written by CAS_Client::_setUser(), read by
  993. * CAS_Client::getUser().
  994. *
  995. * @hideinitializer
  996. */
  997. private $_user = '';
  998. /**
  999. * This method sets the CAS user's login name.
  1000. *
  1001. * @param string $user the login name of the authenticated user.
  1002. *
  1003. * @return void
  1004. */
  1005. private function _setUser($user)
  1006. {
  1007. $this->_user = $user;
  1008. }
  1009. /**
  1010. * This method returns the CAS user's login name.
  1011. *
  1012. * @return string the login name of the authenticated user
  1013. *
  1014. * @warning should be called only after CAS_Client::forceAuthentication() or
  1015. * CAS_Client::isAuthenticated(), otherwise halt with an error.
  1016. */
  1017. public function getUser()
  1018. {
  1019. // Sequence validation
  1020. $this->ensureAuthenticationCallSuccessful();
  1021. return $this->_getUser();
  1022. }
  1023. /**
  1024. * This method returns the CAS user's login name.
  1025. *
  1026. * @return string the login name of the authenticated user
  1027. *
  1028. * @warning should be called only after CAS_Client::forceAuthentication() or
  1029. * CAS_Client::isAuthenticated(), otherwise halt with an error.
  1030. */
  1031. private function _getUser()
  1032. {
  1033. // This is likely a duplicate check that could be removed....
  1034. if ( empty($this->_user) ) {
  1035. phpCAS::error(
  1036. 'this method should be used only after '.__CLASS__
  1037. .'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()'
  1038. );
  1039. }
  1040. return $this->_user;
  1041. }
  1042. /**
  1043. * The Authenticated users attributes. Written by
  1044. * CAS_Client::setAttributes(), read by CAS_Client::getAttributes().
  1045. * @attention client applications should use phpCAS::getAttributes().
  1046. *
  1047. * @hideinitializer
  1048. */
  1049. private $_attributes = array();
  1050. /**
  1051. * Set an array of attributes
  1052. *
  1053. * @param array $attributes a key value array of attributes
  1054. *
  1055. * @return void
  1056. */
  1057. public function setAttributes($attributes)
  1058. {
  1059. $this->_attributes = $attributes;
  1060. }
  1061. /**
  1062. * Get an key values arry of attributes
  1063. *
  1064. * @return array of attributes
  1065. */
  1066. public function getAttributes()
  1067. {
  1068. // Sequence validation
  1069. $this->ensureAuthenticationCallSuccessful();
  1070. // This is likely a duplicate check that could be removed....
  1071. if ( empty($this->_user) ) {
  1072. // if no user is set, there shouldn't be any attributes also...
  1073. phpCAS::error(
  1074. 'this method should be used only after '.__CLASS__
  1075. .'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()'
  1076. );
  1077. }
  1078. return $this->_attributes;
  1079. }
  1080. /**
  1081. * Check whether attributes are available
  1082. *
  1083. * @return bool attributes available
  1084. */
  1085. public function hasAttributes()
  1086. {
  1087. // Sequence validation
  1088. $this->ensureAuthenticationCallSuccessful();
  1089. return !empty($this->_attributes);
  1090. }
  1091. /**
  1092. * Check whether a specific attribute with a name is available
  1093. *
  1094. * @param string $key name of attribute
  1095. *
  1096. * @return bool is attribute available
  1097. */
  1098. public function hasAttribute($key)
  1099. {
  1100. // Sequence validation
  1101. $this->ensureAuthenticationCallSuccessful();
  1102. return $this->_hasAttribute($key);
  1103. }
  1104. /**
  1105. * Check whether a specific attribute with a name is available
  1106. *
  1107. * @param string $key name of attribute
  1108. *
  1109. * @return bool is attribute available
  1110. */
  1111. private function _hasAttribute($key)
  1112. {
  1113. return (is_array($this->_attributes)
  1114. && array_key_exists($key, $this->_attributes));
  1115. }
  1116. /**
  1117. * Get a specific attribute by name
  1118. *
  1119. * @param string $key name of attribute
  1120. *
  1121. * @return string attribute values
  1122. */
  1123. public function getAttribute($key)
  1124. {
  1125. // Sequence validation
  1126. $this->ensureAuthenticationCallSuccessful();
  1127. if ($this->_hasAttribute($key)) {
  1128. return $this->_attributes[$key];
  1129. }
  1130. }
  1131. /**
  1132. * This method is called to renew the authentication of the user
  1133. * If the user is authenticated, renew the connection
  1134. * If not, redirect to CAS
  1135. *
  1136. * @return bool true when the user is authenticated; otherwise halt.
  1137. */
  1138. public function renewAuthentication()
  1139. {
  1140. phpCAS::traceBegin();
  1141. // Either way, the user is authenticated by CAS
  1142. if (isset( $_SESSION['phpCAS']['auth_checked'])) {
  1143. unset($_SESSION['phpCAS']['auth_checked']);
  1144. }
  1145. if ( $this->isAuthenticated(true) ) {
  1146. phpCAS::trace('user already authenticated');
  1147. $res = true;
  1148. } else {
  1149. $this->redirectToCas(false, true);
  1150. // never reached
  1151. $res = false;
  1152. }
  1153. phpCAS::traceEnd();
  1154. return $res;
  1155. }
  1156. /**
  1157. * This method is called to be sure that the user is authenticated. When not
  1158. * authenticated, halt by redirecting to the CAS server; otherwise return true.
  1159. *
  1160. * @return bool true when the user is authenticated; otherwise halt.
  1161. */
  1162. public function forceAuthentication()
  1163. {
  1164. phpCAS::traceBegin();
  1165. if ( $this->isAuthenticated() ) {
  1166. // the user is authenticated, nothing to be done.
  1167. phpCAS::trace('no need to authenticate');
  1168. $res = true;
  1169. } else {
  1170. // the user is not authenticated, redirect to the CAS server
  1171. if (isset($_SESSION['phpCAS']['auth_checked'])) {
  1172. unset($_SESSION['phpCAS']['auth_checked']);
  1173. }
  1174. $this->redirectToCas(false/* no gateway */);
  1175. // never reached
  1176. $res = false;
  1177. }
  1178. phpCAS::traceEnd($res);
  1179. return $res;
  1180. }
  1181. /**
  1182. * An integer that gives the number of times authentication will be cached
  1183. * before rechecked.
  1184. *
  1185. * @hideinitializer
  1186. */
  1187. private $_cache_times_for_auth_recheck = 0;
  1188. /**
  1189. * Set the number of times authentication will be cached before rechecked.
  1190. *
  1191. * @param int $n number of times to wait for a recheck
  1192. *
  1193. * @return void
  1194. */
  1195. public function setCacheTimesForAuthRecheck($n)
  1196. {
  1197. if (gettype($n) != 'integer')
  1198. throw new CAS_TypeMismatchException($n, '$n', 'string');
  1199. $this->_cache_times_for_auth_recheck = $n;
  1200. }
  1201. /**
  1202. * This method is called to check whether the user is authenticated or not.
  1203. *
  1204. * @return bool true when the user is authenticated, false when a previous
  1205. * gateway login failed or the function will not return if the user is
  1206. * redirected to the cas server for a gateway login attempt
  1207. */
  1208. public function checkAuthentication()
  1209. {
  1210. phpCAS::traceBegin();
  1211. if ( $this->isAuthenticated() ) {
  1212. phpCAS::trace('user is authenticated');
  1213. /* The 'auth_checked' variable is removed just in case it's set. */
  1214. unset($_SESSION['phpCAS']['auth_checked']);
  1215. $res = true;
  1216. } else if (isset($_SESSION['phpCAS']['auth_checked'])) {
  1217. // the previous request has redirected the client to the CAS server
  1218. // with gateway=true
  1219. unset($_SESSION['phpCAS']['auth_checked']);
  1220. $res = false;
  1221. } else {
  1222. // avoid a check against CAS on every request
  1223. if (!isset($_SESSION['phpCAS']['unauth_count'])) {
  1224. $_SESSION['phpCAS']['unauth_count'] = -2; // uninitialized
  1225. }
  1226. if (($_SESSION['phpCAS']['unauth_count'] != -2
  1227. && $this->_cache_times_for_auth_recheck == -1)
  1228. || ($_SESSION['phpCAS']['unauth_count'] >= 0
  1229. && $_SESSION['phpCAS']['unauth_count'] < $this->_cache_times_for_auth_recheck)
  1230. ) {
  1231. $res = false;
  1232. if ($this->_cache_times_for_auth_recheck != -1) {
  1233. $_SESSION['phpCAS']['unauth_count']++;
  1234. phpCAS::trace(
  1235. 'user is not authenticated (cached for '
  1236. .$_SESSION['phpCAS']['unauth_count'].' times of '
  1237. .$this->_cache_times_for_auth_recheck.')'
  1238. );
  1239. } else {
  1240. phpCAS::trace(
  1241. 'user is not authenticated (cached for until login pressed)'
  1242. );
  1243. }
  1244. } else {
  1245. $_SESSION['phpCAS']['unauth_count'] = 0;
  1246. $_SESSION['phpCAS']['auth_checked'] = true;
  1247. phpCAS::trace('user is not authenticated (cache reset)');
  1248. $this->redirectToCas(true/* gateway */);
  1249. // never reached
  1250. $res = false;
  1251. }
  1252. }
  1253. phpCAS::traceEnd($res);
  1254. return $res;
  1255. }
  1256. /**
  1257. * This method is called to check if the user is authenticated (previously or by
  1258. * tickets given in the URL).
  1259. *
  1260. * @param bool $renew true to force the authentication with the CAS server
  1261. *
  1262. * @return bool true when the user is authenticated. Also may redirect to the
  1263. * same URL without the ticket.
  1264. */
  1265. public function isAuthenticated($renew=false)
  1266. {
  1267. phpCAS::traceBegin();
  1268. $res = false;
  1269. $validate_url = '';
  1270. if ( $this->_wasPreviouslyAuthenticated() ) {
  1271. if ($this->hasTicket()) {
  1272. // User has a additional ticket but was already authenticated
  1273. phpCAS::trace(
  1274. 'ticket was present and will be discarded, use renewAuthenticate()'
  1275. );
  1276. if ($this->_clearTicketsFromUrl) {
  1277. phpCAS::trace("Prepare redirect to : ".$this->getURL());
  1278. session_write_close();
  1279. header('Location: '.$this->getURL());
  1280. flush();
  1281. phpCAS::traceExit();
  1282. throw new CAS_GracefullTerminationException();
  1283. } else {
  1284. phpCAS::trace(
  1285. 'Already authenticated, but skipping ticket clearing since setNoClearTicketsFromUrl() was used.'
  1286. );
  1287. $res = true;
  1288. }
  1289. } else {
  1290. // the user has already (previously during the session) been
  1291. // authenticated, nothing to be done.
  1292. phpCAS::trace(
  1293. 'user was already authenticated, no need to look for tickets'
  1294. );
  1295. $res = true;
  1296. }
  1297. // Mark the auth-check as complete to allow post-authentication
  1298. // callbacks to make use of phpCAS::getUser() and similar methods
  1299. $this->markAuthenticationCall($res);
  1300. } else {
  1301. if ($this->hasTicket()) {
  1302. switch ($this->getServerVersion()) {
  1303. case CAS_VERSION_1_0:
  1304. // if a Service Ticket was given, validate it
  1305. phpCAS::trace(
  1306. 'CAS 1.0 ticket `'.$this->getTicket().'\' is present'
  1307. );
  1308. $this->validateCAS10(
  1309. $validate_url, $text_response, $tree_response, $renew
  1310. ); // if it fails, it halts
  1311. phpCAS::trace(
  1312. 'CAS 1.0 ticket `'.$this->getTicket().'\' was validated'
  1313. );
  1314. $_SESSION['phpCAS']['user'] = $this->_getUser();
  1315. $res = true;
  1316. $logoutTicket = $this->getTicket();
  1317. break;
  1318. case CAS_VERSION_2_0:
  1319. case CAS_VERSION_3_0:
  1320. // if a Proxy Ticket was given, validate it
  1321. phpCAS::trace(
  1322. 'CAS '.$this->getServerVersion().' ticket `'.$this->getTicket().'\' is present'
  1323. );
  1324. $this->validateCAS20(
  1325. $validate_url, $text_response, $tree_response, $renew
  1326. ); // note: if it fails, it halts
  1327. phpCAS::trace(
  1328. 'CAS '.$this->getServerVersion().' ticket `'.$this->getTicket().'\' was validated'
  1329. );
  1330. if ( $this->isProxy() ) {
  1331. $this->_validatePGT(
  1332. $validate_url, $text_response, $tree_response
  1333. ); // idem
  1334. phpCAS::trace('PGT `'.$this->_getPGT().'\' was validated');
  1335. $_SESSION['phpCAS']['pgt'] = $this->_getPGT();
  1336. }
  1337. $_SESSION['phpCAS']['user'] = $this->_getUser();
  1338. if (!empty($this->_attributes)) {
  1339. $_SESSION['phpCAS']['attributes'] = $this->_attributes;
  1340. }
  1341. $proxies = $this->getProxies();
  1342. if (!empty($proxies)) {
  1343. $_SESSION['phpCAS']['proxies'] = $this->getProxies();
  1344. }
  1345. $res = true;
  1346. $logoutTicket = $this->getTicket();
  1347. break;
  1348. case SAML_VERSION_1_1:
  1349. // if we have a SAML ticket, validate it.
  1350. phpCAS::trace(
  1351. 'SAML 1.1 ticket `'.$this->getTicket().'\' is present'
  1352. );
  1353. $this->validateSA(
  1354. $validate_url, $text_response, $tree_response, $renew
  1355. ); // if it fails, it halts
  1356. phpCAS::trace(
  1357. 'SAML 1.1 ticket `'.$this->getTicket().'\' was validated'
  1358. );
  1359. $_SESSION['phpCAS']['user'] = $this->_getUser();

Large files files are truncated, but you can click here to view the full file