ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthContainerRadius.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 
24 include_once('Auth/Container/RADIUS.php');
25 
38 {
39  private $radius_settings = null;
40  private $rad_to_user = null;
41  private $log = null;
42  private $force_creation = false;
43 
51  public function __construct()
52  {
53  $this->initSettings();
54 
55  // Convert password to latin1
56  if($this->radius_settings->getCharset() == ilRadiusSettings::RADIUS_CHARSET_LATIN1)
57  {
58  #$_POST['username'] = utf8_decode($_POST['username']);
59  #$_POST['password'] = utf8_decode($_POST['password']);
60  $GLOBALS['ilLog']->write(__METHOD__.': Decoded username and password to latin1.');
61  }
62 
63  parent::__construct($this->radius_settings->toPearAuthArray());
64 
65  }
66 
67  /*
68  public function fetchData($username, $password, $challenge = null)
69  {
70  return true;
71  }
72  */
73 
81  public function forceCreation($a_status)
82  {
83  $this->force_creation = true;
84  }
85 
91  public function loginObserver($a_username,$a_auth)
92  {
93  // Radius with ldap as data source
94  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
96  {
97  return $this->handleLDAPDataSource($a_auth,$a_username);
98  }
99 
100  $user_data = array_change_key_case($a_auth->getAuthData(),CASE_LOWER);
101  $user_data['ilInternalAccount'] = ilObjUser::_checkExternalAuthAccount("radius",$a_username);
102 
103  if(!$user_data['ilInternalAccount'])
104  {
105  if($this->radius_settings->enabledCreation())
106  {
107  if($this->radius_settings->isAccountMigrationEnabled() and !$this->force_creation)
108  {
109  $a_auth->logout();
110  $_SESSION['tmp_auth_mode'] = 'radius';
111  $_SESSION['tmp_external_account'] = $a_username;
112  $_SESSION['tmp_pass'] = $_POST['password'];
113  $_SESSION['tmp_roles'] = array(0 => $this->radius_settings->getDefaultRole());
114 
115  ilUtil::redirect('ilias.php?baseClass=ilStartUpGUI&cmd=showAccountMigration&cmdClass=ilstartupgui');
116  }
117  $this->initRADIUSAttributeToUser();
118  $new_name = $this->radius_user->create($a_username);
119  $a_auth->setAuth($new_name);
120  return true;
121  }
122  else
123  {
124  // No syncronisation allowed => create Error
125  $a_auth->status = AUTH_RADIUS_NO_ILIAS_USER;
126  $a_auth->logout();
127  return false;
128  }
129 
130  }
131  else
132  {
133  $a_auth->setAuth($user_data['ilInternalAccount']);
134  return true;
135  }
136  }
137 
142  private function initSettings()
143  {
144  include_once 'Services/Radius/classes/class.ilRadiusSettings.php';
145  $this->radius_settings = ilRadiusSettings::_getInstance();
146  }
147 
148 
155  private function initRADIUSAttributeToUser()
156  {
157  include_once('Services/Radius/classes/class.ilRadiusAttributeToUser.php');
158  $this->radius_user = new ilRadiusAttributeToUser();
159  }
160 
166  protected function handleLDAPDataSource($a_auth,$ext_account)
167  {
168  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
171  );
172 
173  $GLOBALS['ilLog']->write(__METHOD__.'Using ldap data source');
174 
175  include_once './Services/LDAP/classes/class.ilLDAPUserSynchronisation.php';
176  $sync = new ilLDAPUserSynchronisation('radius', $server->getServerId());
177  $sync->setExternalAccount($ext_account);
178  $sync->setUserData(array());
179  $sync->forceCreation($this->force_creation);
180 
181  try {
182  $internal_account = $sync->sync();
183  }
184  catch(UnexpectedValueException $e) {
185  $GLOBALS['ilLog']->write(__METHOD__.': Login failed with message: '. $e->getMessage());
186  $a_auth->status = AUTH_WRONG_LOGIN;
187  $a_auth->logout();
188  return false;
189  }
191  // No syncronisation allowed => create Error
192  $GLOBALS['ilLog']->write(__METHOD__.': Login failed with message: '. $e->getMessage());
193  $a_auth->status = AUTH_RADIUS_NO_ILIAS_USER;
194  $a_auth->logout();
195  return false;
196  }
198  $GLOBALS['ilLog']->write(__METHOD__.': Starting account migration.');
199  $a_auth->logout();
200  ilUtil::redirect('ilias.php?baseClass=ilStartUpGUI&cmdClass=ilstartupgui&cmd=showAccountMigration');
201  }
202 
203  $a_auth->setAuth($internal_account);
204  return true;
205  }
206 
210  public function supportsCaptchaVerification()
211  {
212  return true;
213  }
214 }
215 
216 ?>