ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthBase.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
33 abstract class ilAuthBase
34 {
35  // Used for SOAP Auth
36  // TODO: Find another solution
37  protected $sub_status = null;
38 
44  public function supportRedirects()
45  {
46  return true;
47  }
48 
53  public final function getContainer()
54  {
55  return $this->storage;
56  }
57 
63  protected final function initAuth()
64  {
66 
67  //$this->enableLogging = true;
68  $this->enableLogging = false;
69 
70  if ($this->enableLogging)
71  {
72  $GLOBALS['ilLog']->write(__METHOD__.': Init callbacks');
73  }
74  $this->setLoginCallback(array($this,'loginObserver'));
75  $this->setFailedLoginCallback(array($this,'failedLoginObserver'));
76  $this->setCheckAuthCallback(array($this,'checkAuthObserver'));
77  $this->setLogoutCallback(array($this,'logoutObserver'));
78 
79  include_once('Services/Authentication/classes/class.ilAuthLogObserver.php');
80  $this->attachLogObserver(new ilAuthLogObserver(AUTH_LOG_DEBUG));
81 
82  }
83 
90  protected function loginObserver($a_username,$a_auth)
91  {
92  ilSessionControl::handleLoginEvent($a_username, $a_auth);
93 
94  global $ilLog, $ilAppEventHandler;
95 
96  if($this->getContainer()->loginObserver($a_username,$a_auth))
97  {
98  $ilAppEventHandler->raise("Services/Authentication", "afterLogin",
99  array("username" => $a_auth->getUsername()));
100 
101  // check if profile is complete
102  include_once "Services/User/classes/class.ilObjUser.php";
103  $user_id = ilObjUser::_loginExists($a_auth->getUsername());
104  if($user_id != ANONYMOUS_USER_ID)
105  {
106  $user = new ilObjUser($user_id);
107  include_once "Services/User/classes/class.ilUserProfile.php";
109  {
110  $user->setProfileIncomplete(true);
111  $user->update();
112  }
113  }
114 
115  $ilLog->write(__METHOD__.': logged in as '.$a_auth->getUsername().
116  ', remote:'.$_SERVER['REMOTE_ADDR'].':'.$_SERVER['REMOTE_PORT'].
117  ', server:'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT']
118  );
119  }
120 
121  }
122 
123 
130  protected function failedLoginObserver($a_username,$a_auth)
131  {
132  global $ilLog;
133 
134  $ilLog->write(__METHOD__.': login failed for user '.$a_username.
135  ', remote:'.$_SERVER['REMOTE_ADDR'].':'.$_SERVER['REMOTE_PORT'].
136  ', server:'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT']
137  );
138 
139  require_once 'Services/PrivacySecurity/classes/class.ilSecuritySettings.php';
140  $security = ilSecuritySettings::_getInstance();
141  if($a_username &&
142  $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED
143  )
144  {
145  $usr_id = ilObjUser::_lookupId($a_username);
146  if(!in_array($usr_id, array(ANONYMOUS_USER_ID, SYSTEM_USER_ID)))
147  {
149 
150  $login_attempts = ilObjUser::_getLoginAttempts($usr_id);
151  $max_attempts = $security->getLoginMaxAttempts();
152  if((int)$max_attempts && $login_attempts >= $max_attempts)
153  {
155  }
156  }
157  }
158 
159  return $this->getContainer()->failedLoginObserver($a_username,$a_auth);
160  }
161 
168  protected function checkAuthObserver($a_username,$a_auth)
169  {
170  #$GLOBALS['ilLog']->write(__METHOD__.': Check auth observer called');
171  return $this->getContainer()->checkAuthObserver($a_username,$a_auth);
172  }
173 
180  protected function logoutObserver($a_username,$a_auth)
181  {
183 
184  $GLOBALS['ilLog']->write(__METHOD__.': Logout observer called');
185  $this->getContainer()->logoutObserver($a_username,$a_auth);
186  }
187 
188 }
189 ?>