19 declare(strict_types=1);
48 $this->
lng = $DIC->language();
50 if (null === $a_idp_id || 0 === $a_idp_id) {
57 $this->attributes = $credentials->getAttributes();
58 $this->return_to = $credentials->getReturnTo();
66 !is_array($this->attributes[$this->idp->getUidClaim()]) ||
67 !array_key_exists(0, $this->attributes[$this->idp->getUidClaim()]) ||
68 $this->attributes[$this->idp->getUidClaim()][0] ===
'' 71 'Could not find unique SAML attribute for the configured identifier: %s',
72 print_r($this->idp->getUidClaim(),
true)
76 $this->uid = $this->attributes[$this->idp->getUidClaim()][0];
81 if ([] === $this->attributes) {
82 $this->
getLogger()->warning(
'Could not parse any attributes from SAML response.');
93 $this->
getLogger()->warning($e->getMessage());
102 $update_auth_mode =
false;
105 'Login observer called for SAML authentication request of ext_account "%s" and auth_mode "%s".',
111 'Trying to find ext_account "%s" for auth_mode "%s".',
122 if (!is_string($internal_account) || $internal_account ===
'') {
123 $update_auth_mode =
true;
126 'Could not find ext_account "%s" for auth_mode "%s".',
131 $fallback_auth_mode =
'local';
133 'Trying to find ext_account "%s" for auth_mode "%s".',
140 if (
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode')) {
141 $defaultAuth =
$GLOBALS[
'DIC'][
'ilSetting']->get(
'auth_mode');
145 (!is_string($internal_account) || $internal_account ===
'') &&
149 'Could not find ext_account "%s" for auth_mode "%s".',
154 $fallback_auth_mode =
'default';
156 'Trying to find ext_account "%s" for auth_mode "%s".',
164 if (is_string($internal_account) && $internal_account !==
'') {
166 'Found user "%s" for ext_account "%s" in ILIAS database.',
171 if ($this->idp->isSynchronizationEnabled()) {
173 'SAML user synchronisation is enabled, so update existing user "%s" with ext_account "%s".',
177 $internal_account = $this->
importUser($internal_account, $this->uid, $this->attributes);
180 if ($update_auth_mode) {
185 'SAML Switched auth_mode of user with login "%s" and ext_account "%s" to "%s".',
192 'SAML Could not switch auth_mode of user with login "%s" and ext_account "%s" to "%s".',
201 'Authentication succeeded: Found internal login "%s for ext_account "%s" and auth_mode "%s".',
215 'Could not find an existing user for ext_account "%s" for any relevant auth_mode.',
218 if ($this->idp->isSynchronizationEnabled()) {
220 'SAML user synchronisation is enabled, so determine action for ext_account "%s" and auth_mode "%s".',
224 if (!$this->force_new_account && $this->idp->isAccountMigrationEnabled()) {
229 'Account migration is enabled, so redirecting ext_account "%s" to account migration screen.',
239 $new_name = $this->
importUser(null, $this->uid, $this->attributes);
241 'Created new user account with login "%s" and ext_account "%s".',
273 $this->
getLogger()->warning(
'Cannot find user id for external account: ' . $this->
getCredentials()->getUsername());
280 $this->return_to = (string)
ilSession::get(self::SESSION_TMP_RETURN_TO);
282 $this->force_new_account =
true;
289 $this->migration_account = $a_name;
304 return 'saml_' . $this->idp->getIdpId();
307 private function importUser(?
string $a_internal_login,
string $a_external_account, array $a_user_data = []): string
312 $xml_writer->xmlStartTag(
'Users');
313 if (null === $a_internal_login) {
314 $login = $a_user_data[$this->idp->getLoginClaim()][0];
317 $xml_writer->xmlStartTag(
320 'Action' =>
'Insert',
321 'Language' => $this->
lng->getDefaultLanguage()
324 $xml_writer->xmlElement(
'Login', [], $login);
326 $xml_writer->xmlElement(
'Role', [
327 'Id' => $this->idp->getDefaultRoleId(),
332 $xml_writer->xmlElement(
'Active', [],
"true");
334 $xml_writer->xmlElement(
'TimeLimitUnlimited', [], 1);
335 $xml_writer->xmlElement(
'TimeLimitFrom', [], time());
336 $xml_writer->xmlElement(
'TimeLimitUntil', [], time());
337 $xml_writer->xmlElement(
342 $xml_writer->xmlElement(
'ExternalAccount', [], $a_external_account);
346 $login = $a_internal_login;
349 $xml_writer->xmlStartTag(
'User', [
'Action' =>
'Update',
'Id' => $usr_id]);
351 $loginClaim = $a_user_data[$this->idp->getLoginClaim()][0];
354 $xml_writer->xmlElement(
'Login', [], $login);
360 foreach ($mapping as $rule) {
363 $value = $attributeValueParser->parse();
366 $this->
getLogger()->warning($e->getMessage());
371 $xml_writer->xmlEndTag(
'User');
372 $xml_writer->xmlEndTag(
'Users');
375 'Started import of user "%s" with ext_account "%s" and auth_mode "%s".',
381 $importParser->setXMLContent($xml_writer->xmlDumpMem(
false));
382 $importParser->setRoleAssignment([
383 $this->idp->getDefaultRoleId() => $this->idp->getDefaultRoleId(),
387 $importParser->startParsing();
399 $gender_attr =
'Gender';
400 match (strtolower($value)) {
401 'n',
'neutral' => $xml_writer->
xmlElement($gender_attr, [],
'n'),
402 'm',
'male' => $xml_writer->
xmlElement($gender_attr, [],
'm'),
404 default => $xml_writer->
xmlElement($gender_attr, [],
'f'),
409 $xml_writer->
xmlElement(
'Firstname', [], $value);
413 $xml_writer->
xmlElement(
'Lastname', [], $value);
421 $xml_writer->
xmlElement(
'SecondEmail', [], $value);
425 $xml_writer->
xmlElement(
'Institution', [], $value);
429 $xml_writer->
xmlElement(
'Department', [], $value);
441 $xml_writer->
xmlElement(
'Street', [], $value);
449 $xml_writer->
xmlElement(
'PostalCode', [], $value);
453 $xml_writer->
xmlElement(
'Country', [], $value);
457 $xml_writer->
xmlElement(
'PhoneOffice', [], $value);
461 $xml_writer->
xmlElement(
'PhoneHome', [], $value);
465 $xml_writer->
xmlElement(
'PhoneMobile', [], $value);
472 case 'referral_comment':
473 $xml_writer->
xmlElement(
'Comment', [], $value);
476 case 'matriculation':
477 $xml_writer->
xmlElement(
'Matriculation', [], $value);
481 $xml_writer->
xmlElement(
'Birthday', [], $value);
490 if (!isset($udf_data[1])) {
495 if (empty($definition)) {
497 "Invalid/Orphaned UD field mapping detected: %s",
505 [
'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)
const SESSION_TMP_ATTRIBUTES
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)
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)
const SESSION_TMP_RETURN_TO
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...
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.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
static set(string $a_var, $a_val)
Set a value.
setExternalAccountName(string $a_name)
static getFirstActiveIdp()