ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShibboleth.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 
24 require_once('Auth/Auth.php');
25 require_once('./Services/AuthShibboleth/classes/class.ilShibbolethRoleAssignmentRules.php');
26 require_once('include/Unicode/UtfNormal.php');
27 require_once('./Services/AuthShibboleth/classes/class.ilShibbolethPluginWrapper.php');
28 require_once('./Services/AuthShibboleth/classes/Config/class.shibConfig.php');
29 require_once('./Services/AuthShibboleth/classes/ServerData/class.shibServerData.php');
30 require_once('./Services/AuthShibboleth/classes/User/class.shibUser.php');
31 
42 class ShibAuth extends Auth {
43 
48  public function __construct($authParams, $updateUserData = false) {
49  if ($authParams['sessionName'] != '') {
50  parent::Auth('', array( 'sessionName' => $authParams['sessionName'] ));
51  } else {
52  parent::Auth('');
53  }
54  $this->updateUserData = $updateUserData;
55  if (! empty($authParams['sessionName'])) {
56  $this->setSessionName($authParams['sessionName']);
57  unset($authParams['sessionName']);
58  }
59  }
60 
61 
65  public function supportsRedirects() {
66  return true;
67  }
68 
69 
76  public function login() {
77  global $ilias, $ilSetting; // for backword compatibility of hook environment variables
78  $shibServerData = shibServerData::getInstance($_SERVER);
79  if ($shibServerData->getLogin()) {
80  $shibUser = shibUser::buildInstance($shibServerData);
81  // for backword compatibility of hook environment variables
82  $userObj =& $shibUser; // For shib_data_conv included Script
83  $newUser = $shibUser->isNew(); // For shib_data_conv included Script
84  if ($shibUser->isNew()) {
85  $shibUser->createFields();
86  $shibUser->setPref('hits_per_page', $ilSetting->get('hits_per_page'));
87 
88  // Modify user data before creating the user
89  // Include custom code that can be used to further modify
90  // certain Shibboleth user attributes
91  if ($ilias->getSetting('shib_data_conv') AND $ilias->getSetting('shib_data_conv') != ''
92  AND is_readable($ilias->getSetting('shib_data_conv'))
93  ) {
94  include($ilias->getSetting('shib_data_conv'));
95  }
96  $shibUser = ilShibbolethPluginWrapper::getInstance()->beforeCreateUser($shibUser);
97  $shibUser->create();
98  $shibUser->updateOwner();
99  $shibUser->saveAsNew();
100  $shibUser->writePrefs();
101  $shibUser = ilShibbolethPluginWrapper::getInstance()->afterCreateUser($shibUser);
102  ilShibbolethRoleAssignmentRules::doAssignments($shibUser->getId(), $_SERVER);
103  } else {
104  $shibUser->updateFields();
105  // Include custom code that can be used to further modify
106  // certain Shibboleth user attributes
107  if ($ilias->getSetting('shib_data_conv') AND $ilias->getSetting('shib_data_conv') != ''
108  AND is_readable($ilias->getSetting('shib_data_conv'))
109  ) {
110  include($ilias->getSetting('shib_data_conv'));
111  }
112  // $shibUser->update();
113  $shibUser = ilShibbolethPluginWrapper::getInstance()->beforeUpdateUser($shibUser);
114  $shibUser->update();
115  $shibUser = ilShibbolethPluginWrapper::getInstance()->afterUpdateUser($shibUser);
116  ilShibbolethRoleAssignmentRules::updateAssignments($shibUser->getId(), $_SERVER);
117  }
118  $this->setAuth($shibUser->getLogin(), $shibUser);
119  ilObjUser::_updateLastLogin($shibUser->getId());
120  if ($_GET['target'] != '') {
121  ilUtil::redirect('goto.php?target=' . $_GET['target'] . '&client_id=' . CLIENT_ID);
122  }
123  } else {
124  $this->status = AUTH_WRONG_LOGIN;
125  }
126  }
127 
128 
133  public function setAuth($username, ilObjUser $userObj = NULL) {
134  if ($userObj) {
135  ilShibbolethPluginWrapper::getInstance()->beforeLogin($userObj);
136  }
138  if ($userObj) {
139  ilShibbolethPluginWrapper::getInstance()->afterLogin($userObj);
140  }
141  }
142 
143 
144  public function logout() {
145  global $ilUser;
146  ilShibbolethPluginWrapper::getInstance()->beforeLogout($ilUser);
147  parent::logout();
148  ilShibbolethPluginWrapper::getInstance()->afterLogout($ilUser);
149  }
150 }
151 
152 ?>