LSauth : Recasted - Creation of LSauthMethod class
[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 (LSAUTH_CAS_DISABLE_LOGOUT) {
54                                 LSauth :: disableLogoutBtn();
55                         }
56
57                         return true;
58                 }
59                 else {
60                         LSerror :: addErrorCode('LSauthMethod_CAS_01');
61                 }
62                 return false;
63         }
64
65   /**
66    * Check Auth Data
67    * 
68    * Return authentication data or false
69    * 
70    * @retval Array|false Array of authentication data or False
71    **/
72   public function getAuthData() {
73                 
74                 if (class_exists('phpCAS')) {
75                         
76                         // Launch Auth
77                         phpCAS::forceAuthentication();
78
79                         $this -> authData = array(
80                                 'username' => phpCAS::getUser()
81                         );
82                         return $this -> authData;
83                 }
84                 return;
85         }
86         
87  /**
88   * Logout
89   * 
90   * @retval boolean True on success or False
91   **/
92         public function logout() {
93                 if(class_exists('phpCAS')) {
94                         if (LSauth :: displayLogoutBtn()) {
95                                 phpCAS :: forceAuthentication();
96                                 phpCAS :: logout();
97                                 return true;
98                         }
99                 }
100                 return;
101         }
102
103 }
104 /*
105  * Error Codes
106  */
107 LSerror :: defineError('LSauthMethod_CAS_01',
108 _("LSauthMethod_CAS : Failed to load phpCAS.")
109 );
110 ?>