|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Licensed to Jasig under one or more contributor license |
| 5 | + * agreements. See the NOTICE file distributed with this work for |
| 6 | + * additional information regarding copyright ownership. |
| 7 | + * |
| 8 | + * Jasig licenses this file to you under the Apache License, |
| 9 | + * Version 2.0 (the "License"); you may not use this file except in |
| 10 | + * compliance with the License. You may obtain a copy of the License at: |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + * |
| 20 | + * PHP Version 5 |
| 21 | + * |
| 22 | + * @file CAS/AuthenticationException.php |
| 23 | + * @category Authentication |
| 24 | + * @package PhpCAS |
| 25 | + * @author Joachim Fritschi <[email protected]> |
| 26 | + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 27 | + * @link https://wiki.jasig.org/display/CASC/phpCAS |
| 28 | + */ |
| 29 | + |
| 30 | +/** |
| 31 | + * This interface defines methods that allow proxy-authenticated service handlers |
| 32 | + * to interact with phpCAS. |
| 33 | + * |
| 34 | + * Proxy service handlers must implement this interface as well as call |
| 35 | + * phpCAS::initializeProxiedService($this) at some point in their implementation. |
| 36 | + * |
| 37 | + * While not required, proxy-authenticated service handlers are encouraged to |
| 38 | + * implement the CAS_ProxiedService_Testable interface to facilitate unit testing. |
| 39 | + * |
| 40 | + * @class CAS_AuthenticationException |
| 41 | + * @category Authentication |
| 42 | + * @package PhpCAS |
| 43 | + * @author Joachim Fritschi <[email protected]> |
| 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_AuthenticationException |
| 49 | +extends RuntimeException |
| 50 | +implements CAS_Exception |
| 51 | +{ |
| 52 | + |
| 53 | + /** |
| 54 | + * This method is used to print the HTML output when the user was not |
| 55 | + * authenticated. |
| 56 | + * |
| 57 | + * @param CAS_Client $client phpcas client |
| 58 | + * @param string $failure the failure that occured |
| 59 | + * @param string $cas_url the URL the CAS server was asked for |
| 60 | + * @param bool $no_response the response from the CAS server (other |
| 61 | + * parameters are ignored if TRUE) |
| 62 | + * @param bool $bad_response bad response from the CAS server ($err_code |
| 63 | + * and $err_msg ignored if TRUE) |
| 64 | + * @param string $cas_response the response of the CAS server |
| 65 | + * @param int $err_code the error code given by the CAS server |
| 66 | + * @param string $err_msg the error message given by the CAS server |
| 67 | + */ |
| 68 | + public function __construct($client,$failure,$cas_url,$no_response, |
| 69 | + $bad_response='',$cas_response='',$err_code='',$err_msg='' |
| 70 | + ) { |
| 71 | + phpCAS::traceBegin(); |
| 72 | + $lang = $client->getLangObj(); |
| 73 | + $client->printHTMLHeader($lang->getAuthenticationFailed()); |
| 74 | + printf( |
| 75 | + $lang->getYouWereNotAuthenticated(), |
| 76 | + htmlentities($client->getURL()), |
| 77 | + isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN']:'' |
| 78 | + ); |
| 79 | + phpCAS::trace('CAS URL: '.$cas_url); |
| 80 | + phpCAS::trace('Authentication failure: '.$failure); |
| 81 | + if ( $no_response ) { |
| 82 | + phpCAS::trace('Reason: no response from the CAS server'); |
| 83 | + } else { |
| 84 | + if ( $bad_response ) { |
| 85 | + phpCAS::trace('Reason: bad response from the CAS server'); |
| 86 | + } else { |
| 87 | + switch ($client->getServerVersion()) { |
| 88 | + case CAS_VERSION_1_0: |
| 89 | + phpCAS::trace('Reason: CAS error'); |
| 90 | + break; |
| 91 | + case CAS_VERSION_2_0: |
| 92 | + case CAS_VERSION_3_0: |
| 93 | + if ( empty($err_code) ) { |
| 94 | + phpCAS::trace('Reason: no CAS error'); |
| 95 | + } else { |
| 96 | + phpCAS::trace('Reason: ['.$err_code.'] CAS error: '.$err_msg); |
| 97 | + } |
| 98 | + break; |
| 99 | + } |
| 100 | + } |
| 101 | + phpCAS::trace('CAS response: '.$cas_response); |
| 102 | + } |
| 103 | + $client->printHTMLFooter(); |
| 104 | + phpCAS::traceExit(); |
| 105 | + } |
| 106 | + |
| 107 | +} |
| 108 | +?> |
0 commit comments