ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthRadius.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 
25 include_once('Auth/Auth.php');
26 
36 class ilAuthRadius extends Auth
37 {
38  private $radius_settings = null;
39  private $rad_to_user = null;
40  private $log = null;
41 
42  private $force_creation = false;
43 
44  public function __construct($a_options)
45  {
46  global $ilLog;
47 
48  $this->log = $ilLog;
49 
50  // Read setting of LDAP server
51  $this->initSettings();
52 
53  // Convert password to latin1
54  if($this->radius_settings->getCharset() == ilRadiusSettings::RADIUS_CHARSET_LATIN1)
55  {
56  #$_POST['username'] = utf8_decode($_POST['username']);
57  $_POST['password'] = utf8_decode($_POST['password']);
58  $this->log->write(__METHOD__.': Decoded username and password to latin1.');
59  }
60  if(is_array($a_options))
61  {
62  $options = array_merge($this->radius_settings->toPearAuthArray(),$a_options);
63  }
64  else
65  {
66  $options = $this->radius_settings->toPearAuthArray();
67  }
68 
69 
70  parent::Auth('RADIUS',$options,'',false);
71 
72  // Set callbacks
73  $this->setCallbacks();
74  }
75 
83  public function forceCreation($a_status)
84  {
85  $this->force_creation = true;
86  }
87 
88 
94  protected function loginObserver($a_username)
95  {
96  $user_data = array_change_key_case($this->getAuthData(),CASE_LOWER);
97 
98  $user_data['ilInternalAccount'] = ilObjUser::_checkExternalAuthAccount("radius",$a_username);
99 
100  if(!$user_data['ilInternalAccount'])
101  {
102  if($this->radius_settings->enabledCreation())
103  {
104  if($this->radius_settings->isAccountMigrationEnabled() and !$this->force_creation)
105  {
106  $this->logout();
107  $_SESSION['tmp_auth_mode'] = 'radius';
108  $_SESSION['tmp_external_account'] = $a_username;
109  $_SESSION['tmp_pass'] = $_POST['password'];
110  $_SESSION['tmp_roles'] = array(0 => $this->radius_settings->getDefaultRole());
111 
112  ilUtil::redirect('ilias.php?baseClass=ilStartUpGUI&cmd=showAccountMigration&cmdClass=ilstartupgui');
113  }
114  $this->initAttributeToUser();
115  $new_name = $this->radius_user->create($a_username);
116  $this->setAuth($new_name);
117  return true;
118  }
119  else
120  {
121  // No syncronisation allowed => create Error
122  $this->status = AUTH_RADIUS_NO_ILIAS_USER;
123  $this->logout();
124  return false;
125  }
126 
127  }
128  else
129  {
130  $this->setAuth($user_data['ilInternalAccount']);
131  return true;
132  }
133  }
134 
140  protected function failedLoginObserver()
141  {
142  #$this->log->write($this->logCache);
143  $this->logCache = '';
144  }
145 
146 
147  private function initSettings()
148  {
149  include_once 'Services/Radius/classes/class.ilRadiusSettings.php';
150  $this->radius_settings = ilRadiusSettings::_getInstance();
151  }
152 
153  private function initAttributeToUser()
154  {
155  include_once('Services/Radius/classes/class.ilRadiusAttributeToUser.php');
156  $this->radius_user = new ilRadiusAttributeToUser();
157  }
158 
163  private function setCallbacks()
164  {
165  $this->setLoginCallback(array($this,'loginObserver'));
166  $this->setFailedLoginCallback(array($this,'failedLoginObserver'));
167  }
168 
169 }
170 
171 ?>