ILIAS  Release_4_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  $this->log->write(__METHOD__.': Decoded username and password to latin1.');
61  }
62 
63  parent::__construct($this->radius_settings->toPearAuthArray());
64 
65  }
66 
74  public function forceCreation($a_status)
75  {
76  $this->force_creation = true;
77  }
78 
84  public function loginObserver($a_username,$a_auth)
85  {
86  $user_data = array_change_key_case($a_auth->getAuthData(),CASE_LOWER);
87  $user_data['ilInternalAccount'] = ilObjUser::_checkExternalAuthAccount("radius",$a_username);
88 
89  if(!$user_data['ilInternalAccount'])
90  {
91  if($this->radius_settings->enabledCreation())
92  {
93  if($this->radius_settings->isAccountMigrationEnabled() and !$this->force_creation)
94  {
95  $a_auth->logout();
96  $_SESSION['tmp_auth_mode'] = 'radius';
97  $_SESSION['tmp_external_account'] = $a_username;
98  $_SESSION['tmp_pass'] = $_POST['password'];
99  $_SESSION['tmp_roles'] = array(0 => $this->radius_settings->getDefaultRole());
100 
101  ilUtil::redirect('ilias.php?baseClass=ilStartUpGUI&cmd=showAccountMigration&cmdClass=ilstartupgui');
102  }
103  $this->initRADIUSAttributeToUser();
104  $new_name = $this->radius_user->create($a_username);
105  $a_auth->setAuth($new_name);
106  return true;
107  }
108  else
109  {
110  // No syncronisation allowed => create Error
111  $a_auth->status = AUTH_RADIUS_NO_ILIAS_USER;
112  $a_auth->logout();
113  return false;
114  }
115 
116  }
117  else
118  {
119  $a_auth->setAuth($user_data['ilInternalAccount']);
120  return true;
121  }
122  }
123 
128  private function initSettings()
129  {
130  include_once 'Services/Radius/classes/class.ilRadiusSettings.php';
131  $this->radius_settings = ilRadiusSettings::_getInstance();
132  }
133 
134 
141  private function initRADIUSAttributeToUser()
142  {
143  include_once('Services/Radius/classes/class.ilRadiusAttributeToUser.php');
144  $this->radius_user = new ilRadiusAttributeToUser();
145  }
146 }
147 
148 ?>