1<?
php declare(strict_types=1);
32 if (
null === $a_idp_id || 0 === $a_idp_id) {
50 !array_key_exists($this->idp->getUidClaim(), $this->attributes) ||
51 !is_array($this->attributes[$this->idp->getUidClaim()]) ||
52 !array_key_exists(0, $this->attributes[$this->idp->getUidClaim()]) ||
53 0 === strlen($this->attributes[$this->idp->getUidClaim()][0])
56 'Could not find unique SAML attribute for the configured identifier: %s',
57 print_r($this->idp->getUidClaim(),
true)
61 $this->uid = $this->attributes[$this->idp->getUidClaim()][0];
69 if (!is_array($this->attributes) || 0 === count($this->attributes)) {
70 $this->
getLogger()->warning(
'Could not parse any attributes from SAML response.');
81 $this->
getLogger()->warning($e->getMessage());
94 $update_auth_mode =
false;
97 'Login observer called for SAML authentication request of ext_account "%s" and auth_mode "%s".',
103 'Trying to find ext_account "%s" for auth_mode "%s".',
114 if (!is_string($internal_account) || $internal_account ===
'') {
115 $update_auth_mode =
true;
118 'Could not find ext_account "%s" for auth_mode "%s".',
123 $fallback_auth_mode =
'local';
125 'Trying to find ext_account "%s" for auth_mode "%s".',
132 if (
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode')) {
133 $defaultAuth =
$GLOBALS[
'DIC'][
'ilSetting']->get(
'auth_mode');
136 if ((!is_string($internal_account) || 0 === strlen($internal_account)) && ($defaultAuth ==
AUTH_LOCAL || $defaultAuth == $this->
getTriggerAuthMode())) {
138 'Could not find ext_account "%s" for auth_mode "%s".',
143 $fallback_auth_mode =
'default';
145 'Trying to find ext_account "%s" for auth_mode "%s".',
153 if (is_string($internal_account) && $internal_account !==
'') {
155 'Found user "%s" for ext_account "%s" in ILIAS database.',
160 if ($this->idp->isSynchronizationEnabled()) {
162 'SAML user synchronisation is enabled, so update existing user "%s" with ext_account "%s".',
166 $internal_account = $this->
importUser($internal_account, $this->uid, $this->attributes);
169 if ($update_auth_mode) {
174 'SAML Switched auth_mode of user with login "%s" and ext_account "%s" to "%s".',
181 'SAML Could not switch auth_mode of user with login "%s" and ext_account "%s" to "%s".',
190 'Authentication succeeded: Found internal login "%s for ext_account "%s" and auth_mode "%s".',
204 'Could not find an existing user for ext_account "%s" for any relevant auth_mode.',
207 if ($this->idp->isSynchronizationEnabled()) {
209 'SAML user synchronisation is enabled, so determine action for ext_account "%s" and auth_mode "%s".',
213 if ($this->idp->isAccountMigrationEnabled() && !$this->force_new_account) {
218 'Account migration is enabled, so redirecting ext_account "%s" to account migration screen.',
228 $new_name = $this->
importUser(
null, $this->uid, $this->attributes);
230 'Created new user account with login "%s" and ext_account "%s".',
239 if (strlen($this->return_to)) {
272 $this->
getLogger()->warning(
'Cannot find user id for external account: ' . $this->
getCredentials()->getUsername());
282 $this->force_new_account =
true;
293 $this->migration_account = $a_name;
309 return AUTH_SAML .
'_' . $this->idp->getIdpId();
317 return 'saml_' . $this->idp->getIdpId();
326 public function importUser(?
string $a_internal_login,
string $a_external_account, array $a_user_data = [])
331 $xml_writer->xmlStartTag(
'Users');
332 if (
null === $a_internal_login) {
333 $login = $a_user_data[$this->idp->getLoginClaim()][0];
336 $xml_writer->xmlStartTag(
'User', [
'Action' =>
'Insert']);
337 $xml_writer->xmlElement(
'Login', [],
$login);
339 $xml_writer->xmlElement(
'Role', [
340 'Id' => $this->idp->getDefaultRoleId(),
345 $xml_writer->xmlElement(
'Active', [],
"true");
347 $xml_writer->xmlElement(
'TimeLimitUnlimited', [], 1);
348 $xml_writer->xmlElement(
'TimeLimitFrom', [], time());
349 $xml_writer->xmlElement(
'TimeLimitUntil', [], time());
350 $xml_writer->xmlElement(
355 $xml_writer->xmlElement(
'ExternalAccount', [], $a_external_account);
359 $login = $a_internal_login;
362 $xml_writer->xmlStartTag(
'User', [
'Action' =>
'Update',
'Id' => $usr_id]);
364 $loginClaim = $a_user_data[$this->idp->getLoginClaim()][0];
367 $xml_writer->xmlElement(
'Login', [],
$login);
373 foreach ($mapping as $rule) {
376 $value = $attributeValueParser->parse();
379 $this->
getLogger()->warning($e->getMessage());
384 $xml_writer->xmlEndTag(
'User');
385 $xml_writer->xmlEndTag(
'Users');
388 'Started import of user "%s" with ext_account "%s" and auth_mode "%s".',
394 $importParser->setXMLContent($xml_writer->xmlDumpMem(
false));
395 $importParser->setRoleAssignment([
396 $this->idp->getDefaultRoleId() => $this->idp->getDefaultRoleId(),
400 $importParser->startParsing();
417 switch (strtolower($value)) {
437 $xml_writer->
xmlElement(
'Firstname', [], $value);
441 $xml_writer->
xmlElement(
'Lastname', [], $value);
449 $xml_writer->
xmlElement(
'Institution', [], $value);
453 $xml_writer->
xmlElement(
'Department', [], $value);
465 $xml_writer->
xmlElement(
'Street', [], $value);
473 $xml_writer->
xmlElement(
'PostalCode', [], $value);
477 $xml_writer->
xmlElement(
'Country', [], $value);
481 $xml_writer->
xmlElement(
'PhoneOffice', [], $value);
485 $xml_writer->
xmlElement(
'PhoneHome', [], $value);
489 $xml_writer->
xmlElement(
'PhoneMobile', [], $value);
496 case 'referral_comment':
497 $xml_writer->
xmlElement(
'Comment', [], $value);
500 case 'matriculation':
501 $xml_writer->
xmlElement(
'Matriculation', [], $value);
505 $xml_writer->
xmlElement(
'Birthday', [], $value);
514 if (!isset($udf_data[1])) {
521 [
'Id' => $definition[
'il_id'],
'Name' => $definition[
'field_name']],
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
Class ilAuthFrontendCredentialsSaml.
Description of class class.
Class ilAuthProviderSaml.
createNewAccount(ilAuthStatus $status)
Create new ILIAS account for external_account.
importUser(?string $a_internal_login, string $a_external_account, array $a_user_data=[])
setExternalAccountName(string $a_name)
Set external account name.
buildUserAttributeXml(ilXmlWriter $xml_writer, ilExternalAuthUserAttributeMappingRule $rule, string $value)
handleSamlAuth(ilAuthStatus $status)
determineUidFromAttributes()
getExternalAccountName()
Get external account name.string
getUserAuthModeName()
Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth.
migrateAccount(ilAuthStatus $status)
Create new account.
doAuthentication(ilAuthStatus $status)
getTriggerAuthMode()
Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 1...
__construct(ilAuthFrontendCredentials $credentials, ?int $a_idp_id=null)
ilAuthProviderSaml constructor.
Base class for authentication providers (radius, ldap, apache, ...)
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
Auth status implementation.
setStatus($a_status)
Set auth status.
const STATUS_AUTHENTICATED
const STATUS_ACCOUNT_MIGRATION_REQUIRED
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilExternalAuthUserAttributeMappingRule.
Class ilExternalAuthUserAttributeMapping.
Class ilExternalAuthUserCreationAttributeMappingFilter.
Class ilExternalAuthUserUpdateAttributeMappingFilter.
static getLogger($a_component_id)
Get component logger.
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
static _writeAuthMode($a_usr_id, $a_auth_mode)
static _lookupId($a_user_str)
Lookup id by login.
static _loginExists($a_login, $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...
static getInstanceByIdpId(int $a_idp_id)
static getFirstActiveIdp()
Class ilSamlMappedUserAttributeValueParser.
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
static strToLower($a_string)
static _getInstance()
Get instance.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
Description of class interface.
Standard interface for auth provider implementations.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc