ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthContainerCAS.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Auth/Container.php';
5 
6 
15 {
16 
17 
18  protected $server_version = null;
19  protected $server_hostname = null;
20  protected $server_port = null;
21  protected $server_uri = null;
22 
23 
26  public function __construct()
27  {
29  $this->initCAS();
30  }
31 
39  public function forceAuthentication($username,$status,$auth)
40  {
41  global $PHPCAS_CLIENT,$ilLog;
42 
43  if(!$PHPCAS_CLIENT->isAuthenticated())
44  {
45  $PHPCAS_CLIENT->forceAuthentication();
46  }
47  }
48 
52  public function loginObserver($a_username, $a_auth)
53  {
54  global $ilias, $rbacadmin, $ilSetting,$ilLog,$PHPCAS_CLIENT;
55 
56  $ilLog->write(__METHOD__.': Successful CAS login.');
57 
58  include_once("./Services/CAS/lib/CAS.php");
59 
60  if ($PHPCAS_CLIENT->getUser() != "")
61  {
62  $username = $PHPCAS_CLIENT->getUser();
63  $ilLog->write(__METHOD__.': Username: '.$username);
64 
65  // Authorize this user
66  include_once('./Services/User/classes/class.ilObjUser.php');
67  $local_user = ilObjUser::_checkExternalAuthAccount("cas", $username);
68 
69  if ($local_user != "")
70  {
71  $a_auth->setAuth($local_user);
72  }
73  else
74  {
75  if (!$ilSetting->get("cas_create_users"))
76  {
77  $a_auth->status = AUTH_CAS_NO_ILIAS_USER;
78  $a_auth->logout();
79  return false;
80  }
81 
82  $userObj = new ilObjUser();
83 
84  $local_user = ilAuthUtils::_generateLogin($username);
85 
86  $newUser["firstname"] = $local_user;
87  $newUser["lastname"] = "";
88 
89  $newUser["login"] = $local_user;
90 
91  // set "plain md5" password (= no valid password)
92  $newUser["passwd"] = "";
93  $newUser["passwd_type"] = IL_PASSWD_MD5;
94 
95  //$newUser["gender"] = "m";
96  $newUser["auth_mode"] = "cas";
97  $newUser["ext_account"] = $username;
98  $newUser["profile_incomplete"] = 1;
99 
100  // system data
101  $userObj->assignData($newUser);
102  $userObj->setTitle($userObj->getFullname());
103  $userObj->setDescription($userObj->getEmail());
104 
105  // set user language to system language
106  $userObj->setLanguage($ilSetting->get("language"));
107 
108  // Time limit
109  $userObj->setTimeLimitOwner(7);
110  $userObj->setTimeLimitUnlimited(1);
111  $userObj->setTimeLimitFrom(time());
112  $userObj->setTimeLimitUntil(time());
113 
114  // Create user in DB
115  $userObj->setOwner(0);
116  $userObj->create();
117  $userObj->setActive(1);
118 
119  $userObj->updateOwner();
120 
121  //insert user data in table user_data
122  $userObj->saveAsNew();
123 
124  // setup user preferences
125  $userObj->writePrefs();
126 
127  // to do: test this
128  $rbacadmin->assignUser($ilSetting->get('cas_user_default_role'), $userObj->getId(),true);
129  unset($userObj);
130 
131  $a_auth->setAuth($local_user);
132  return true;
133  }
134  }
135  else
136  {
137  $ilLog->write(__METHOD__.': Login failed.');
138 
139  // This should never occur unless CAS is not configured properly
140  $a_auth->status = AUTH_WRONG_LOGIN;
141  return false;
142  }
143  return false;
144  }
145 
146 
154  public function fetchData($a_username,$a_password,$isChallengeResponse = false)
155  {
156  global $PHPCAS_CLIENT,$ilLog;
157 
158  $ilLog->write(__METHOD__.': Fetch Data called');
159  return $PHPCAS_CLIENT->isAuthenticated();
160  }
161 
162  protected function initCAS()
163  {
164  global $ilSetting;
165 
166  include_once("./Services/CAS/lib/CAS.php");
167 
168  $this->server_version = CAS_VERSION_2_0;
169  $this->server_hostname = $ilSetting->get('cas_server');
170  $this->server_port = (int) $ilSetting->get('cas_port');
171  $this->server_uri = (string) $ilSetting->get('cas_uri');
172 
175  $this->server_version,
176  $this->server_hostname,
177  $this->server_port,
178  $this->server_uri
179  );
181  }
182 
183 }
184 ?>