AuthenticationException.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/AuthenticationException.php
  22. * @category Authentication
  23. * @package PhpCAS
  24. * @author Joachim Fritschi <jfritschi@freenet.de>
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  26. * @link https://wiki.jasig.org/display/CASC/phpCAS
  27. */
  28. /**
  29. * This interface defines methods that allow proxy-authenticated service handlers
  30. * to interact with phpCAS.
  31. *
  32. * Proxy service handlers must implement this interface as well as call
  33. * phpCAS::initializeProxiedService($this) at some point in their implementation.
  34. *
  35. * While not required, proxy-authenticated service handlers are encouraged to
  36. * implement the CAS_ProxiedService_Testable interface to facilitate unit testing.
  37. *
  38. * @class CAS_AuthenticationException
  39. * @category Authentication
  40. * @package PhpCAS
  41. * @author Joachim Fritschi <jfritschi@freenet.de>
  42. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  43. * @link https://wiki.jasig.org/display/CASC/phpCAS
  44. */
  45. class CAS_AuthenticationException
  46. extends RuntimeException
  47. implements CAS_Exception
  48. {
  49. /**
  50. * This method is used to print the HTML output when the user was not
  51. * authenticated.
  52. *
  53. * @param CAS_Client $client phpcas client
  54. * @param string $failure the failure that occured
  55. * @param string $cas_url the URL the CAS server was asked for
  56. * @param bool $no_response the response from the CAS server (other
  57. * parameters are ignored if TRUE)
  58. * @param bool $bad_response bad response from the CAS server ($err_code
  59. * and $err_msg ignored if TRUE)
  60. * @param string $cas_response the response of the CAS server
  61. * @param int $err_code the error code given by the CAS server
  62. * @param string $err_msg the error message given by the CAS server
  63. */
  64. public function __construct($client,$failure,$cas_url,$no_response,
  65. $bad_response=false,$cas_response='',$err_code=-1,$err_msg=''
  66. ) {
  67. $messages = array();
  68. phpCAS::traceBegin();
  69. $lang = $client->getLangObj();
  70. $client->printHTMLHeader($lang->getAuthenticationFailed());
  71. printf(
  72. $lang->getYouWereNotAuthenticated(),
  73. htmlentities($client->getURL()),
  74. isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN']:''
  75. );
  76. phpCAS::trace($messages[] = 'CAS URL: '.$cas_url);
  77. phpCAS::trace($messages[] = 'Authentication failure: '.$failure);
  78. if ( $no_response ) {
  79. phpCAS::trace($messages[] = 'Reason: no response from the CAS server');
  80. } else {
  81. if ( $bad_response ) {
  82. phpCAS::trace($messages[] = 'Reason: bad response from the CAS server');
  83. } else {
  84. switch ($client->getServerVersion()) {
  85. case CAS_VERSION_1_0:
  86. phpCAS::trace($messages[] = 'Reason: CAS error');
  87. break;
  88. case CAS_VERSION_2_0:
  89. case CAS_VERSION_3_0:
  90. if ( $err_code === -1 ) {
  91. phpCAS::trace($messages[] = 'Reason: no CAS error');
  92. } else {
  93. phpCAS::trace($messages[] = 'Reason: ['.$err_code.'] CAS error: '.$err_msg);
  94. }
  95. break;
  96. }
  97. }
  98. phpCAS::trace($messages[] = 'CAS response: '.$cas_response);
  99. }
  100. $client->printHTMLFooter();
  101. phpCAS::traceExit();
  102. parent::__construct(implode("\n", $messages));
  103. }
  104. }
  105. ?>