ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAuthProviderCAS.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Authentication/classes/Provider/class.ilAuthProvider.php';
5 include_once './Services/Authentication/interfaces/interface.ilAuthProviderInterface.php';
6 
14 {
18  private $settings = null;
19 
25  {
26  global $DIC;
27 
28  parent::__construct($credentials);
29  include_once './Services/CAS/classes/class.ilCASSettings.php';
31  }
32 
36  protected function getSettings()
37  {
38  return $this->settings;
39  }
40 
45  {
46  include_once './Services/CAS/lib/CAS.php';
47  global $phpCAS;
48 
49  $this->getLogger()->debug('Starting cas authentication attempt... ');
50 
51  try {
52  phpCAS::setDebug(false);
53  phpCAS::setVerbose(true);
56  $this->getSettings()->getServer(),
57  (int) $this->getSettings()->getPort(),
58  $this->getSettings()->getUri()
59  );
60 
63  } catch (Exception $e) {
64  $this->getLogger()->error('Cas authentication failed with message: ' . $e->getMessage());
65  $this->handleAuthenticationFail($status, 'err_wrong_login');
66  return false;
67  }
68 
69  if (!strlen(phpCAS::getUser())) {
70  return $this->handleAuthenticationFail($status, 'err_wrong_login');
71  }
72  $this->getCredentials()->setUsername(phpCAS::getUser());
73 
74  // check and handle ldap data sources
75  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
77  return $this->handleLDAPDataSource($status);
78  }
79 
80  // Check account available
81  $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->getCredentials()->getUsername());
82  if (strlen($local_user)) {
83  $this->getLogger()->debug('CAS authentication successful.');
85  $status->setAuthenticatedUserId(ilObjUser::_lookupId($local_user));
86  return true;
87  }
88 
89  if (!$this->getSettings()->isUserCreationEnabled()) {
90  $this->getLogger()->debug('User creation disabled. No valid local account found');
91  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
92  return false;
93  }
94 
95 
96  include_once './Services/CAS/classes/class.ilCASAttributeToUser.php';
97  $importer = new ilCASAttributeToUser($this->getSettings());
98  $new_name = $importer->create($this->getCredentials()->getUsername());
99 
100  if (!strlen($new_name)) {
101  $this->getLogger()->debug('User creation failed.');
102  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
103  return false;
104  }
105 
107  $status->setAuthenticatedUserId(ilObjUser::_lookupId($new_name));
108  return true;
109  }
110 
116  {
117  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
120  );
121 
122  $this->getLogger()->debug('Using ldap data source for user: ' . $this->getCredentials()->getUsername());
123 
124  include_once './Services/LDAP/classes/class.ilLDAPUserSynchronisation.php';
125  $sync = new ilLDAPUserSynchronisation('cas', $server->getServerId());
126  $sync->setExternalAccount($this->getCredentials()->getUsername());
127  $sync->setUserData(array());
128  $sync->forceCreation(true);
129 
130  try {
131  $internal_account = $sync->sync();
132  } catch (UnexpectedValueException $e) {
133  $this->getLogger()->warning('Authentication failed with mesage: ' . $e->getMessage());
134  $this->handleAuthenticationFail($status, 'err_wrong_login');
135  return false;
137 
138  // No syncronisation allowed => create Error
139  $this->getLogger()->warning('User creation disabled. No valid local account found');
140  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
141  return false;
143 
144  // No syncronisation allowed => create Error
145  $this->getLogger()->warning('User creation disabled. No valid local account found');
146  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
147  return false;
148  }
150  $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
151  return true;
152  }
153 }
static forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
Definition: CAS.php:1094
Interface of auth credentials.
static getUser()
This method returns the CAS user&#39;s login name.
Definition: CAS.php:1175
CAS authentication provider.
global $DIC
Definition: saml.php:7
const AUTH_CAS
Synchronization of user accounts used in auth container ldap, radius , cas,...
handleLDAPDataSource(\ilAuthStatus $status)
Handle user data synchonization by ldap data source.
static _lookupId($a_user_str)
Lookup id by login.
Description of ilLDAPAccountMigrationRequiredException.
CAS user creation helper.
static getInstanceByServerId($a_server_id)
Get instance by server id.
setAuthenticatedUserId($a_id)
Base class for authentication providers (radius, ldap, apache, ...)
Standard interface for auth provider implementations.
static isDataSourceActive($a_auth_mode)
Check if a data source is active for a specific auth mode ilDB $ilDB.
setStatus($a_status)
Set auth status.
doAuthentication(\ilAuthStatus $status)
Do authentication.Authentication status bool
$sync
static getDataSource($a_auth_mode)
const CAS_VERSION_2_0
Definition: CAS.php:78
Create styles array
The data for the language used.
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
getLogger()
Get logger.
$server
Definition: getUserInfo.php:12
static setVerbose($verbose)
Enable verbose errors messages in the website output This is a security relevant since internal statu...
Definition: CAS.php:481
settings()
Definition: settings.php:2
__construct(ilAuthCredentials $credentials)
ilAuthProviderCAS constructor.
static setDebug($filename='')
Set/unset debug mode.
Definition: CAS.php:439
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
static setNoCasServerValidation()
Set no SSL validation for the CAS server.
Definition: CAS.php:1639
Auth status implementation.
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
phpCAS client initializer.
Definition: CAS.php:338
static getInstance()
Get singleton instance.