ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAuthProviderCAS Class Reference

CAS authentication provider. More...

+ Inheritance diagram for ilAuthProviderCAS:
+ Collaboration diagram for ilAuthProviderCAS:

Public Member Functions

 __construct (ilAuthCredentials $credentials)
 ilAuthProviderCAS constructor. More...
 
 doAuthentication (\ilAuthStatus $status)
 Do authentication.
Parameters
\ilAuthStatus$statusAuthentication status
Returns
bool
More...
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 

Protected Member Functions

 getSettings ()
 
 handleLDAPDataSource (\ilAuthStatus $status)
 Handle user data synchonization by ldap data source. More...
 
- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, $a_reason)
 Handle failed authentication. More...
 

Private Attributes

 $settings = null
 

Additional Inherited Members

- Data Fields inherited from ilAuthProvider
const STATUS_UNDEFINED = 0
 
const STATUS_AUTHENTICATION_SUCCESS = 1
 
const STATUS_AUTHENTICATION_FAILED = 2
 
const STATUS_MIGRATION = 3
 

Detailed Description

CAS authentication provider.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 13 of file class.ilAuthProviderCAS.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderCAS::__construct ( ilAuthCredentials  $credentials)

ilAuthProviderCAS constructor.

Parameters
\ilAuthCredentials$credentials

Definition at line 24 of file class.ilAuthProviderCAS.php.

References $DIC, ilCASSettings\getInstance(), and settings().

25  {
26  global $DIC;
27 
28  parent::__construct($credentials);
29  include_once './Services/CAS/classes/class.ilCASSettings.php';
31  }
settings()
Definition: settings.php:2
global $DIC
static getInstance()
Get singleton instance.
+ Here is the call graph for this function:

Member Function Documentation

◆ doAuthentication()

ilAuthProviderCAS::doAuthentication ( \ilAuthStatus  $status)

Do authentication.

Parameters
\ilAuthStatus$statusAuthentication status
Returns
bool

Implements ilAuthProviderInterface.

Definition at line 44 of file class.ilAuthProviderCAS.php.

References ilObjUser\_checkExternalAuthAccount(), ilObjUser\_lookupId(), AUTH_CAS, CAS_VERSION_2_0, phpCAS\client(), phpCAS\forceAuthentication(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), getSettings(), phpCAS\getUser(), ilAuthProvider\handleAuthenticationFail(), handleLDAPDataSource(), ilLDAPServer\isDataSourceActive(), ilAuthStatus\setAuthenticatedUserId(), phpCAS\setDebug(), phpCAS\setNoCasServerValidation(), ilAuthStatus\setStatus(), phpCAS\setVerbose(), and ilAuthStatus\STATUS_AUTHENTICATED.

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  }
64  catch(Exception $e) {
65  $this->getLogger()->error('Cas authentication failed with message: ' . $e->getMessage());
66  $this->handleAuthenticationFail($status, 'err_wrong_login');
67  return false;
68  }
69 
70  if(!strlen(phpCAS::getUser()))
71  {
72  return $this->handleAuthenticationFail($status, 'err_wrong_login');
73  }
74  $this->getCredentials()->setUsername(phpCAS::getUser());
75 
76  // check and handle ldap data sources
77  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
79  {
80  return $this->handleLDAPDataSource($status);
81  }
82 
83  // Check account available
84  $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->getCredentials()->getUsername());
85  if(strlen($local_user))
86  {
87  $this->getLogger()->debug('CAS authentication successful.');
89  $status->setAuthenticatedUserId(ilObjUser::_lookupId($local_user));
90  return true;
91  }
92 
93  if(!$this->getSettings()->isUserCreationEnabled())
94  {
95  $this->getLogger()->debug('User creation disabled. No valid local account found');
96  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
97  return false;
98  }
99 
100 
101  include_once './Services/CAS/classes/class.ilCASAttributeToUser.php';
102  $importer = new ilCASAttributeToUser($this->getSettings());
103  $new_name = $importer->create($this->getCredentials()->getUsername());
104 
105  if(!strlen($new_name))
106  {
107  $this->getLogger()->debug('User creation failed.');
108  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
109  return false;
110  }
111 
113  $status->setAuthenticatedUserId(ilObjUser::_lookupId($new_name));
114  return true;
115  }
static forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
Definition: CAS.php:1094
static getUser()
This method returns the CAS user's login name.
Definition: CAS.php:1175
const AUTH_CAS
handleLDAPDataSource(\ilAuthStatus $status)
Handle user data synchonization by ldap data source.
static _lookupId($a_user_str)
Lookup id by login.
CAS user creation helper.
static isDataSourceActive($a_auth_mode)
Check if a data source is active for a specific auth mode ilDB $ilDB.
const CAS_VERSION_2_0
Definition: CAS.php:78
getLogger()
Get logger.
static setVerbose($verbose)
Enable verbose errors messages in the website output This is a security relevant since internal statu...
Definition: CAS.php:481
static setDebug($filename='')
Set/unset debug mode.
Definition: CAS.php:439
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
static setNoCasServerValidation()
Set no SSL validation for the CAS server.
Definition: CAS.php:1639
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
phpCAS client initializer.
Definition: CAS.php:338
+ Here is the call graph for this function:

◆ getSettings()

ilAuthProviderCAS::getSettings ( )
protected
Returns

Definition at line 36 of file class.ilAuthProviderCAS.php.

References $settings.

Referenced by doAuthentication().

37  {
38  return $this->settings;
39  }
+ Here is the caller graph for this function:

◆ handleLDAPDataSource()

ilAuthProviderCAS::handleLDAPDataSource ( \ilAuthStatus  $status)
protected

Handle user data synchonization by ldap data source.

Parameters
\ilAuthStatus$status

Definition at line 121 of file class.ilAuthProviderCAS.php.

References $server, ilObjUser\_lookupId(), array, AUTH_CAS, ilAuthProvider\getCredentials(), ilLDAPServer\getDataSource(), ilLDAPServer\getInstanceByServerId(), ilAuthProvider\getLogger(), ilAuthProvider\handleAuthenticationFail(), ilAuthStatus\setAuthenticatedUserId(), ilLDAPUserSynchronisation\setExternalAccount(), ilAuthStatus\setStatus(), and ilAuthStatus\STATUS_AUTHENTICATED.

Referenced by doAuthentication().

122  {
123  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
126  );
127 
128  $this->getLogger()->debug('Using ldap data source for user: ' . $this->getCredentials()->getUsername());
129 
130  include_once './Services/LDAP/classes/class.ilLDAPUserSynchronisation.php';
131  $sync = new ilLDAPUserSynchronisation('cas', $server->getServerId());
132  $sync->setExternalAccount($this->getCredentials()->getUsername());
133  $sync->setUserData(array());
134  $sync->forceCreation(true);
135 
136  try {
137  $internal_account = $sync->sync();
138  }
139  catch(UnexpectedValueException $e) {
140  $this->getLogger()->warning('Authentication failed with mesage: ' . $e->getMessage());
141  $this->handleAuthenticationFail($status, 'err_wrong_login');
142  return false;
143  }
145 
146  // No syncronisation allowed => create Error
147  $this->getLogger()->warning('User creation disabled. No valid local account found');
148  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
149  return false;
150  }
152 
153  // No syncronisation allowed => create Error
154  $this->getLogger()->warning('User creation disabled. No valid local account found');
155  $this->handleAuthenticationFail($status, 'err_auth_cas_no_ilias_user');
156  return false;
157  }
159  $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
160  return true;
161  }
const AUTH_CAS
Synchronization of user accounts used in auth container ldap, radius , cas,...
static _lookupId($a_user_str)
Lookup id by login.
setExternalAccount($a_ext)
Set external account (unique for each auth mode)
Description of ilLDAPAccountMigrationRequiredException.
static getInstanceByServerId($a_server_id)
Get instance by server id.
static getDataSource($a_auth_mode)
Create styles array
The data for the language used.
getLogger()
Get logger.
$server
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $settings

ilAuthProviderCAS::$settings = null
private

Definition at line 18 of file class.ilAuthProviderCAS.php.

Referenced by getSettings().


The documentation for this class was generated from the following file: