ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.shibUser.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/AuthShibboleth/classes/Config/class.shibConfig.php');
3 require_once('./Services/User/classes/class.ilObjUser.php');
4 
10 class shibUser extends ilObjUser {
11 
15  protected $shibServerData;
16 
17 
23  public static function buildInstance(shibServerData $shibServerData) {
24  $shibUser = new self();
25  $shibUser->shibServerData = $shibServerData;
26  $ext_id = $shibUser->shibServerData->getLogin();
27  $shibUser->setExternalAccount($ext_id);
28  $existing_usr_id = self::getUsrIdByExtId($ext_id);
29  if ($existing_usr_id) {
30  $shibUser->setId($existing_usr_id);
31  $shibUser->read();
32  }
33  $shibUser->setAuthMode('shibboleth');
34 
35  return $shibUser;
36  }
37 
38 
39  public function updateFields() {
40  $shibConfig = shibConfig::getInstance();
41  if ($shibConfig->getUpdateFirstname()) {
42  $this->setFirstname($this->shibServerData->getFirstname());
43  }
44  if ($shibConfig->getUpdateLastname()) {
45  $this->setLastname($this->shibServerData->getLastname());
46  }
47  if ($shibConfig->getUpdateGender()) {
48  $this->setGender($this->shibServerData->getGender());
49  }
50  if ($shibConfig->getUpdateTitle()) {
51  $this->setTitle($this->shibServerData->getTitle());
52  }
53  if ($shibConfig->getUpdateInstitution()) {
55  }
56  if ($shibConfig->getUpdateDepartment()) {
57  $this->setDepartment($this->shibServerData->getDepartment());
58  }
59  if ($shibConfig->getUpdateStreet()) {
60  $this->setStreet($this->shibServerData->getStreet());
61  }
62  if ($shibConfig->getUpdateZipcode()) {
63  $this->setZipcode($this->shibServerData->getZipcode());
64  }
65  if ($shibConfig->getUpdateCountry()) {
66  $this->setCountry($this->shibServerData->getCountry());
67  }
68  if ($shibConfig->getUpdatePhoneOffice()) {
70  }
71  if ($shibConfig->getUpdatePhoneHome()) {
72  $this->setPhoneHome($this->shibServerData->getPhoneHome());
73  }
74  if ($shibConfig->getUpdatePhoneMobile()) {
76  }
77  if ($shibConfig->getUpdateFax()) {
78  $this->setFax($this->shibServerData->getFax());
79  }
80  if ($shibConfig->getUpdateMatriculation()) {
82  }
83  if ($shibConfig->getUpdateEmail()) {
84  $this->setEmail($this->shibServerData->getEmail());
85  }
86  if ($shibConfig->getUpdateHobby()) {
87  $this->setHobby($this->shibServerData->getHobby());
88  }
89  if ($shibConfig->getUpdateLanguage()) {
90  $this->setLanguage($this->shibServerData->getLanguage());
91  }
92  $this->setDescription($this->getEmail());
93  }
94 
95 
96  public function createFields() {
97  $this->setFirstname($this->shibServerData->getFirstname());
98  $this->setLastname($this->shibServerData->getLastname());
99  $this->setLogin($this->returnNewLoginName());
101  $this->setGender($this->shibServerData->getGender());
102  $this->setExternalAccount($this->shibServerData->getLogin());
103  $this->setTitle($this->shibServerData->getTitle());
104  $this->setInstitution($this->shibServerData->getInstitution());
105  $this->setDepartment($this->shibServerData->getDepartment());
106  $this->setStreet($this->shibServerData->getStreet());
107  $this->setZipcode($this->shibServerData->getZipcode());
108  $this->setCountry($this->shibServerData->getCountry());
109  $this->setPhoneOffice($this->shibServerData->getPhoneOffice());
110  $this->setPhoneHome($this->shibServerData->getPhoneHome());
111  $this->setPhoneMobile($this->shibServerData->getPhoneMobile());
112  $this->setFax($this->shibServerData->getFax());
114  $this->setEmail($this->shibServerData->getEmail());
115  $this->setHobby($this->shibServerData->getHobby());
116  $this->setTitle($this->getFullname());
117  $this->setDescription($this->getEmail());
118  $this->setLanguage($this->shibServerData->getLanguage());
119  $this->setTimeLimitOwner(7);
120  $this->setTimeLimitUnlimited(1);
121  $this->setTimeLimitFrom(time());
122  $this->setTimeLimitUntil(time());
123  $this->setActive(true);
124  }
125 
126 
127  public function create() {
128  if ($this->getLogin() != '' AND $this->getLogin() != '.') {
129  parent::create();
130  } else {
131  throw new ilUserException('No Login-name created');
132  }
133  }
134 
135 
139  protected function returnNewLoginName() {
140  $login = substr(self::cleanName($this->getFirstname()), 0, 1) . '.' . self::cleanName($this->getLastname());
141  //remove whitespaces see mantis 0023123: https://www.ilias.de/mantis/view.php?id=23123
142  $login = preg_replace('/\s+/', '', $login);
143  $appendix = null;
144  $login_tmp = $login;
145  while (self::loginExists($login, $this->getId())) {
146  $login = $login_tmp . $appendix;
147  $appendix ++;
148  }
149 
150  return $login;
151  }
152 
153 
157  public function isNew() {
158  return (bool)($this->getId() == 0);
159  }
160 
161 
167  protected static function cleanName($name) {
168  $name = strtolower(strtr(utf8_decode($name), utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'), 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'));
169 
170  return $name;
171  }
172 
173 
180  private static function loginExists($login, $usr_id) {
181  global $DIC;
182  $ilDB = $DIC['ilDB'];
186  $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $ilDB->quote($login, 'text');
187  $query .= ' AND usr_id != ' . $ilDB->quote($usr_id, 'integer');
188 
189  return (bool)($ilDB->numRows($ilDB->query($query)) > 0);
190  }
191 
192 
198  protected static function getUsrIdByExtId($ext_id) {
199  global $DIC;
200  $ilDB = $DIC['ilDB'];
204  $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $ilDB->quote($ext_id, 'text');
205  $a_set = $ilDB->query($query);
206  if ($ilDB->numRows($a_set) == 0) {
207  return false;
208  } else {
209  $usr = $ilDB->fetchObject($a_set);
210 
211  return $usr->usr_id;
212  }
213  }
214 }
static cleanName($name)
Class for user related exception handling in ILIAS.
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately public
setInstitution($a_str)
set institution public
getLogin()
get login / username public
Class shibServerData.
setDepartment($a_str)
set department public
getFirstname()
get firstname public
setLanguage($a_str)
set user language public
const IL_PASSWD_CRYPTED
$login
all user related data in single vars public
setTimeLimitOwner($a_owner)
static generatePasswords($a_number)
Generate a number of passwords.
setLastname($a_str)
set lastame public
static getInstance()
setCountry($a_str)
Set country (free text)
setPhoneHome($a_str)
set home phone public
setTimeLimitUnlimited($a_unlimited)
setTitle($a_title)
set object title
setZipcode($a_str)
set zipcode public
setEmail($a_str)
set email public
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password public
setTimeLimitUntil($a_until)
setLogin($a_str)
set login / username public
getEmail()
get email address public
getLastname()
get lastname public
Class shibUser.
setExternalAccount($a_str)
set external account
getId()
get object id public
setHobby($a_str)
set hobby public
setMatriculation($a_str)
set matriculation number public
static buildInstance(shibServerData $shibServerData)
setGender($a_str)
set gender public
setTimeLimitFrom($a_from)
setPhoneOffice($a_str)
set office phone public
getFullname($a_max_strlen=0)
get fullname public
setFirstname($a_str)
set firstname public
setFax($a_str)
set fax public
global $ilDB
setDescription($a_desc)
set object description
global $DIC
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
setStreet($a_str)
set street public
setPhoneMobile($a_str)
set mobile phone public