ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthModeDetermination.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 
32 include_once('Services/Authentication/classes/class.ilAuthUtils.php');
33 
35 {
36  const TYPE_MANUAL = 0;
37  const TYPE_AUTOMATIC = 1;
38 
39  protected static $instance = null;
40 
41  protected $db = null;
42  protected $settings = null;
43 
44  protected $kind = 0;
45  protected $position = array();
46 
47 
54  private function __construct()
55  {
56  global $ilSetting,$ilDB;
57 
58  $this->db = $ilDB;
59 
60  include_once "./Services/Administration/classes/class.ilSetting.php";
61  $this->settings = new ilSetting("auth_mode_determination");
62  $this->read();
63  }
64 
72  public static function _getInstance()
73  {
74  if(self::$instance)
75  {
76  return self::$instance;
77  }
78  return self::$instance = new ilAuthModeDetermination();
79  }
80 
89  public function isManualSelection()
90  {
91  return $this->kind == self::TYPE_MANUAL;
92  }
93 
100  public function getKind()
101  {
102  return $this->kind;
103  }
104 
112  public function setKind($a_kind)
113  {
114  $this->kind = $a_kind;
115  }
116 
123  public function getAuthModeSequence()
124  {
125  return $this->position ? $this->position : array();
126  }
127 
134  public function getCountActiveAuthModes()
135  {
136  return count($this->position);
137  }
138 
146  public function setAuthModeSequence($a_pos)
147  {
148  $this->position = $a_pos;
149  }
150 
158  public function save()
159  {
160  $this->settings->deleteAll();
161 
162  $this->settings->set('kind',$this->getKind());
163 
164  $counter = 0;
165  foreach($this->position as $auth_mode)
166  {
167  $this->settings->set((string) $counter++,$auth_mode);
168  }
169  }
170 
171 
179  private function read()
180  {
181  $this->kind = $this->settings->get('kind',self::TYPE_MANUAL);
182 
183  include_once('Services/LDAP/classes/class.ilLDAPServer.php');
184  $ldap_active = ilLDAPServer::_getFirstActiveServer();
185 
186  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
187  $rad_settings = ilRadiusSettings::_getInstance();
188  $rad_active = $rad_settings->isActive();
189 
190 
191  // Check if active
192  for($i = 0; $i < 3; $i++)
193  {
194  if($auth_mode = $this->settings->get((string) $i,0))
195  {
196  switch($auth_mode)
197  {
198  case AUTH_LOCAL:
199  $this->position[] = $auth_mode;
200  break;
201  case AUTH_LDAP:
202  if($ldap_active)
203  {
204  $this->position[] = $auth_mode;
205  }
206  break;
207 
208  case AUTH_RADIUS:
209  if($rad_active)
210  {
211  $this->position[] = $auth_mode;
212  }
213  break;
214  }
215  }
216  }
217 
218  // Append missing active auth modes
219  if(!in_array(AUTH_LOCAL,$this->position))
220  {
221  $this->position[] = AUTH_LOCAL;
222  }
223  if($ldap_active)
224  {
225  if(!in_array(AUTH_LDAP,$this->position))
226  {
227  $this->position[] = AUTH_LDAP;
228  }
229  }
230  if($rad_active)
231  {
232  if(!in_array(AUTH_RADIUS,$this->position))
233  {
234  $this->position[] = AUTH_RADIUS;
235  }
236 
237  }
238  }
239 }
240 
241 
242 ?>