19 declare(strict_types=1);
31 protected string $uid =
'';
41 $this->
lng = $DIC->language();
43 if (null === $a_idp_id || 0 === $a_idp_id) {
50 $this->attributes = $credentials->getAttributes();
51 $this->return_to = $credentials->getReturnTo();
59 !is_array($this->attributes[$this->idp->getUidClaim()]) ||
60 !array_key_exists(0, $this->attributes[$this->idp->getUidClaim()]) ||
61 $this->attributes[$this->idp->getUidClaim()][0] ===
'' 64 'Could not find unique SAML attribute for the configured identifier: %s',
65 print_r($this->idp->getUidClaim(),
true)
69 $this->uid = $this->attributes[$this->idp->getUidClaim()][0];
74 if (0 === count($this->attributes)) {
75 $this->
getLogger()->warning(
'Could not parse any attributes from SAML response.');
86 $this->
getLogger()->warning($e->getMessage());
95 $update_auth_mode =
false;
98 'Login observer called for SAML authentication request of ext_account "%s" and auth_mode "%s".',
104 'Trying to find ext_account "%s" for auth_mode "%s".',
115 if (!is_string($internal_account) || $internal_account ===
'') {
116 $update_auth_mode =
true;
119 'Could not find ext_account "%s" for auth_mode "%s".',
124 $fallback_auth_mode =
'local';
126 'Trying to find ext_account "%s" for auth_mode "%s".',
133 if (
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode')) {
134 $defaultAuth =
$GLOBALS[
'DIC'][
'ilSetting']->get(
'auth_mode');
138 (!is_string($internal_account) || $internal_account ===
'') &&
142 'Could not find ext_account "%s" for auth_mode "%s".',
147 $fallback_auth_mode =
'default';
149 'Trying to find ext_account "%s" for auth_mode "%s".',
157 if (is_string($internal_account) && $internal_account !==
'') {
159 'Found user "%s" for ext_account "%s" in ILIAS database.',
164 if ($this->idp->isSynchronizationEnabled()) {
166 'SAML user synchronisation is enabled, so update existing user "%s" with ext_account "%s".',
170 $internal_account = $this->
importUser($internal_account, $this->uid, $this->attributes);
173 if ($update_auth_mode) {
178 'SAML Switched auth_mode of user with login "%s" and ext_account "%s" to "%s".',
185 'SAML Could not switch auth_mode of user with login "%s" and ext_account "%s" to "%s".',
194 'Authentication succeeded: Found internal login "%s for ext_account "%s" and auth_mode "%s".',
208 'Could not find an existing user for ext_account "%s" for any relevant auth_mode.',
211 if ($this->idp->isSynchronizationEnabled()) {
213 'SAML user synchronisation is enabled, so determine action for ext_account "%s" and auth_mode "%s".',
217 if (!$this->force_new_account && $this->idp->isAccountMigrationEnabled()) {
222 'Account migration is enabled, so redirecting ext_account "%s" to account migration screen.',
232 $new_name = $this->
importUser(null, $this->uid, $this->attributes);
234 'Created new user account with login "%s" and ext_account "%s".',
266 $this->
getLogger()->warning(
'Cannot find user id for external account: ' . $this->
getCredentials()->getUsername());
275 $this->force_new_account =
true;
282 $this->migration_account = $a_name;
297 return 'saml_' . $this->idp->getIdpId();
300 private function importUser(?
string $a_internal_login,
string $a_external_account, array $a_user_data = []): string
305 $xml_writer->xmlStartTag(
'Users');
306 if (null === $a_internal_login) {
307 $login = $a_user_data[$this->idp->getLoginClaim()][0];
310 $xml_writer->xmlStartTag(
313 'Action' =>
'Insert',
314 'Language' => $this->
lng->getDefaultLanguage()
317 $xml_writer->xmlElement(
'Login', [], $login);
319 $xml_writer->xmlElement(
'Role', [
320 'Id' => $this->idp->getDefaultRoleId(),
325 $xml_writer->xmlElement(
'Active', [],
"true");
327 $xml_writer->xmlElement(
'TimeLimitUnlimited', [], 1);
328 $xml_writer->xmlElement(
'TimeLimitFrom', [], time());
329 $xml_writer->xmlElement(
'TimeLimitUntil', [], time());
330 $xml_writer->xmlElement(
335 $xml_writer->xmlElement(
'ExternalAccount', [], $a_external_account);
339 $login = $a_internal_login;
342 $xml_writer->xmlStartTag(
'User', [
'Action' =>
'Update',
'Id' => $usr_id]);
344 $loginClaim = $a_user_data[$this->idp->getLoginClaim()][0];
347 $xml_writer->xmlElement(
'Login', [], $login);
353 foreach ($mapping as $rule) {
356 $value = $attributeValueParser->parse();
359 $this->
getLogger()->warning($e->getMessage());
364 $xml_writer->xmlEndTag(
'User');
365 $xml_writer->xmlEndTag(
'Users');
368 'Started import of user "%s" with ext_account "%s" and auth_mode "%s".',
374 $importParser->setXMLContent($xml_writer->xmlDumpMem(
false));
375 $importParser->setRoleAssignment([
376 $this->idp->getDefaultRoleId() => $this->idp->getDefaultRoleId(),
380 $importParser->startParsing();
392 switch (strtolower($value)) {
412 $xml_writer->
xmlElement(
'Firstname', [], $value);
416 $xml_writer->
xmlElement(
'Lastname', [], $value);
424 $xml_writer->
xmlElement(
'SecondEmail', [], $value);
428 $xml_writer->
xmlElement(
'Institution', [], $value);
432 $xml_writer->
xmlElement(
'Department', [], $value);
444 $xml_writer->
xmlElement(
'Street', [], $value);
452 $xml_writer->
xmlElement(
'PostalCode', [], $value);
456 $xml_writer->
xmlElement(
'Country', [], $value);
460 $xml_writer->
xmlElement(
'PhoneOffice', [], $value);
464 $xml_writer->
xmlElement(
'PhoneHome', [], $value);
468 $xml_writer->
xmlElement(
'PhoneMobile', [], $value);
475 case 'referral_comment':
476 $xml_writer->
xmlElement(
'Comment', [], $value);
479 case 'matriculation':
480 $xml_writer->
xmlElement(
'Matriculation', [], $value);
484 $xml_writer->
xmlElement(
'Birthday', [], $value);
493 if (!isset($udf_data[1])) {
498 if (empty($definition)) {
500 "Invalid/Orphaned UD field mapping detected: %s",
508 [
'Id' => $definition[
'il_id'],
'Name' => $definition[
'field_name']],
doAuthentication(ilAuthStatus $status)
static get(string $a_var)
determineUidFromAttributes()
Class ilExternalAuthUserUpdateAttributeMappingFilter.
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
Interface of auth credentials.
static getLogger(string $a_component_id)
Get component logger.
__construct(ilAuthCredentials $credentials, ?int $a_idp_id=null)
importUser(?string $a_internal_login, string $a_external_account, array $a_user_data=[])
getExternalAccountName()
Get external account name.
static _writeAuthMode(int $a_usr_id, string $a_auth_mode)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupId($a_user_str)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
static getInstanceByIdpId(int $a_idp_id)
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
Base class for authentication providers (ldap, apache, ...)
Class ilAuthFrontendCredentialsSaml.
Class ilExternalAuthUserAttributeMapping.
setStatus(int $a_status)
Set auth status.
Class ilExternalAuthUserAttributeMappingRule.
string $migration_account
createNewAccount(ilAuthStatus $status)
Create new ILIAS account for external_account.
static _loginExists(string $a_login, int $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
migrateAccount(ilAuthStatus $status)
Create new account.
ilAuthCredentials $credentials
getUserAuthModeName()
Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth...
getTriggerAuthMode()
Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 1...
handleSamlAuth(ilAuthStatus $status)
Class ilAuthProviderSaml.
const STATUS_AUTHENTICATED
__construct(Container $dic, ilPlugin $plugin)
Class ilExternalAuthUserCreationAttributeMappingFilter.
static strToLower(string $a_string)
buildUserAttributeXml(ilXmlWriter $xml_writer, ilExternalAuthUserAttributeMappingRule $rule, string $value)
setAuthenticatedUserId(int $a_id)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
Class ilSamlMappedUserAttributeValueParser.
Auth status implementation.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
static set(string $a_var, $a_val)
Set a value.
setExternalAccountName(string $a_name)
static getFirstActiveIdp()