ILIAS  Release_4_0_x_branch Revision 61816
 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 
195  // Check if active
196  for($i = 0; $i < 4; $i++)
197  {
198  if($auth_mode = $this->settings->get((string) $i,0))
199  {
200  switch($auth_mode)
201  {
202  case AUTH_LOCAL:
203  $this->position[] = $auth_mode;
204  break;
205 
206  case AUTH_LDAP:
207  if($ldap_active)
208  {
209  $this->position[] = $auth_mode;
210  }
211  break;
212 
213  case AUTH_RADIUS:
214  if($rad_active)
215  {
216  $this->position[] = $auth_mode;
217  }
218  break;
219 
220  case AUTH_SOAP:
221  if($soap_active)
222  {
223  $this->position[] = $auth_mode;
224  }
225  break;
226  }
227  }
228  }
229 
230  // Append missing active auth modes
231  if(!in_array(AUTH_LOCAL,$this->position))
232  {
233  $this->position[] = AUTH_LOCAL;
234  }
235  if($ldap_active)
236  {
237  if(!in_array(AUTH_LDAP,$this->position))
238  {
239  $this->position[] = AUTH_LDAP;
240  }
241  }
242  if($rad_active)
243  {
244  if(!in_array(AUTH_RADIUS,$this->position))
245  {
246  $this->position[] = AUTH_RADIUS;
247  }
248 
249  }
250  if($soap_active)
251  {
252  if(!in_array(AUTH_SOAP,$this->position))
253  {
254  $this->position[] = AUTH_SOAP;
255  }
256  }
257  }
258 }
259 
260 
261 ?>