ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthMultiple.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
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 |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
34 
36 {
37  protected $settings = null;
38  protected $auth = null;
39  protected $auth_modes = null;
40  protected $current_auth_modes = null;
41  protected $first_auth_method = true;
42 
49  public function __construct()
50  {
51  include_once('./Services/Authentication/classes/class.ilAuthModeDetermination.php');
52  $this->settings = ilAuthModeDetermination::_getInstance();
53 
54  $this->auth_modes = $this->settings->getAuthModeSequence();
55 
56  $this->initNextAuthObject();
57  $this->first_auth_method = false;
58  }
59 
67  public function setIdle($time,$add = false)
68  {
69  $this->auth->setIdle($time,$add);
70  }
71 
77  public function setExpire($time,$add = false)
78  {
79  $this->auth->setExpire($time,$add);
80  }
81 
89  public function logout()
90  {
91  $this->auth->logout();
92  }
93 
101  public function checkAuth()
102  {
103  global $ilLog;
104 
105  do
106  {
107  if($this->auth->checkAuth())
108  {
109  return true;
110  }
111  $this->auth->logout();
112 
113  }
114  while($this->initNextAuthObject());
115 
116  $ilLog->write(__METHOD__.': Authentication failed.');
117  return false;
118  }
119 
127  public function getUsername()
128  {
129  return $this->auth->getUsername();
130  }
131 
139  public function getAuth()
140  {
141  return $this->checkAuth();
142  }
143 
150  public function start()
151  {
152  $this->auth->start();
153  }
154 
162  public function getStatus()
163  {
164  return $this->auth->getStatus();
165  }
166 
167 
175  private function initNextAuthObject()
176  {
177  global $ilLog,$ilClientIniFile;
178 
179  if(!$this->current_auth_mode = current($this->auth_modes))
180  {
181  return false;
182  }
183  next($this->auth_modes);
184  switch($this->current_auth_mode)
185  {
186  case AUTH_LDAP:
187  $ilLog->write(__METHOD__.': Current Authentication method is LDAP.');
188  include_once 'Services/LDAP/classes/class.ilAuthLDAP.php';
189  $auth_params['sessionName'] = "_authhttp".md5(CLIENT_ID);
190  $this->auth = new ilAuthLDAP($auth_params);
191  break;
192 
193  case AUTH_RADIUS:
194  $ilLog->write(__METHOD__.': Current Authentication method is RADIUS.');
195  include_once('Services/Radius/classes/class.ilAuthRadius.php');
196  $auth_params['sessionName'] = "_authhttp".md5(CLIENT_ID);
197  $this->auth = new ilAuthRadius($auth_params);
198  break;
199  case AUTH_LOCAL:
200  $ilLog->write(__METHOD__.': Current Authentication method is ILIAS DB.');
201  $auth_params = array(
202  'dsn' => IL_DSN,
203  'table' => $ilClientIniFile->readVariable("auth", "table"),
204  'usernamecol' => $ilClientIniFile->readVariable("auth", "usercol"),
205  'passwordcol' => $ilClientIniFile->readVariable("auth", "passcol")
206  );
207  $auth_params['sessionName'] = "_authhttp".md5(CLIENT_ID);
208  require_once 'class.ilAuthContainerMDB2.php';
209  $authContainer = new ilAuthContainerMDB2($auth_params);
210  $authContainer->setObserversEnabled(true);
211  $this->auth = new Auth($authContainer, $auth_params,"",false);
212  break;
213  }
214  if(!$this->first_auth_method)
215  {
216  $this->auth->start();
217  }
218  return true;
219  }
220 
221 }
222 ?>