LSauthCAS : added possibility to set CURLOPT_SSLVERSION option with parameter LSAUTH_...
[ldapsaisie.git] / public_html / includes / class / class.LSauthMethod_CAS.php
1 <?php
2 /*******************************************************************************
3  * Copyright (C) 2007 Easter-eggs
4  * http://ldapsaisie.labs.libre-entreprise.org
5  *
6  * Author: See AUTHORS file in top-level directory.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version 2
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 ******************************************************************************/
22
23 /**
24  * CAS Authentication provider for LSauth
25  *
26  * @author Benjamin Renard <brenard@easter-eggs.com>
27  */
28 class LSauthMethod_CAS extends LSauthMethod {
29
30   function LSauthMethod_CAS() {
31                 LSauth :: disableLoginForm();
32                 
33                 if (!parent :: LSauthMethod())
34                         return;
35
36                 if (LSsession :: includeFile(PHP_CAS_PATH)) {
37                         if (defined('PHP_CAS_DEBUG_FILE')) {
38                                 phpCAS::setDebug(PHP_CAS_DEBUG_FILE);
39                         }
40                         phpCAS::client(constant(LSAUTH_CAS_VERSION),LSAUTH_CAS_SERVER_HOSTNAME,LSAUTH_CAS_SERVER_PORT,LSAUTH_CAS_SERVER_URI,false);
41                         if (LSAUTH_CAS_SERVER_NO_SSL_VALIDATION) {
42                                 phpCAS::setNoCasServerValidation();
43                         }
44
45                         if (defined('LSAUTH_CAS_SERVER_SSL_CERT')) {
46                                 phpCAS::setCasServerCert(LSAUTH_CAS_SERVER_SSL_CERT);
47                         }
48
49                         if (defined('LSAUTH_CAS_SERVER_SSL_CACERT')) {
50                                 phpCAS::setCasServerCACert(LSAUTH_CAS_SERVER_SSL_CACERT);
51                         }
52
53                         if (defined('LSAUTH_CAS_CURL_SSLVERION')) {
54                                 phpCAS::setExtraCurlOption(CURLOPT_SSLVERSION,LSAUTH_CAS_CURL_SSLVERION);
55                         }
56
57                         if (LSAUTH_CAS_DISABLE_LOGOUT) {
58                                 LSauth :: disableLogoutBtn();
59                         }
60
61                         return true;
62                 }
63                 else {
64                         LSerror :: addErrorCode('LSauthMethod_CAS_01');
65                 }
66                 return false;
67         }
68
69   /**
70    * Check Auth Data
71    * 
72    * Return authentication data or false
73    * 
74    * @retval Array|false Array of authentication data or False
75    **/
76   public function getAuthData() {
77                 
78                 if (class_exists('phpCAS')) {
79                         
80                         // Launch Auth
81                         phpCAS::forceAuthentication();
82
83                         $this -> authData = array(
84                                 'username' => phpCAS::getUser()
85                         );
86                         return $this -> authData;
87                 }
88                 return;
89         }
90         
91  /**
92   * Logout
93   * 
94   * @retval boolean True on success or False
95   **/
96         public function logout() {
97                 if(class_exists('phpCAS')) {
98                         if (LSauth :: displayLogoutBtn()) {
99                                 phpCAS :: forceAuthentication();
100                                 phpCAS :: logout();
101                                 return true;
102                         }
103                 }
104                 return;
105         }
106
107 }
108 /*
109  * Error Codes
110  */
111 LSerror :: defineError('LSauthMethod_CAS_01',
112 _("LSauthMethod_CAS : Failed to load phpCAS.")
113 );
114 ?>