ILIAS  Release_4_1_x_branch Revision 61804
 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  global $ilSetting;
182 
183  $this->kind = $this->settings->get('kind',self::TYPE_MANUAL);
184 
185  include_once('Services/LDAP/classes/class.ilLDAPServer.php');
186  $ldap_active = ilLDAPServer::_getFirstActiveServer();
187 
188  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
189  $rad_settings = ilRadiusSettings::_getInstance();
190  $rad_active = $rad_settings->isActive();
191 
192  $soap_active = $ilSetting->get('soap_auth_active',false);
193 
194  // apache settings
195  $apache_settings = new ilSetting('apache_auth');
196  $apache_active = $apache_settings->get('apache_enable_auth');
197 
198  // Check if active
199  for($i = 0; $i < 5; $i++)
200  {
201  if($auth_mode = $this->settings->get((string) $i,0))
202  {
203  switch($auth_mode)
204  {
205  case AUTH_LOCAL:
206  $this->position[] = $auth_mode;
207  break;
208 
209  case AUTH_LDAP:
210  if($ldap_active)
211  {
212  $this->position[] = $auth_mode;
213  }
214  break;
215 
216  case AUTH_RADIUS:
217  if($rad_active)
218  {
219  $this->position[] = $auth_mode;
220  }
221  break;
222 
223  case AUTH_SOAP:
224  if($soap_active)
225  {
226  $this->position[] = $auth_mode;
227  }
228  break;
229 
230  case AUTH_APACHE:
231  if($apache_active)
232  {
233  $this->position[] = $auth_mode;
234  }
235  break;
236  }
237  }
238  }
239 
240  // Append missing active auth modes
241  if(!in_array(AUTH_LOCAL,$this->position))
242  {
243  $this->position[] = AUTH_LOCAL;
244  }
245  if($ldap_active)
246  {
247  if(!in_array(AUTH_LDAP,$this->position))
248  {
249  $this->position[] = AUTH_LDAP;
250  }
251  }
252  if($rad_active)
253  {
254  if(!in_array(AUTH_RADIUS,$this->position))
255  {
256  $this->position[] = AUTH_RADIUS;
257  }
258 
259  }
260  if($soap_active)
261  {
262  if(!in_array(AUTH_SOAP,$this->position))
263  {
264  $this->position[] = AUTH_SOAP;
265  }
266  }
267  if($apache_active)
268  {
269  if(!in_array(AUTH_APACHE,$this->position))
270  {
271  $this->position[] = AUTH_APACHE;
272  }
273  }
274  }
275 }
276 
277 
278 ?>