46 parent::__construct($credentials);
48 if (null === $a_idp_id || 0 === $a_idp_id) {
55 $this->attributes = $credentials->getAttributes();
56 $this->return_to = $credentials->getReturnTo();
67 !is_array($this->attributes[$this->idp->getUidClaim()]) ||
68 !array_key_exists(0, $this->attributes[$this->idp->getUidClaim()]) ||
69 0 === strlen($this->attributes[$this->idp->getUidClaim()][0])
71 throw new \ilException(sprintf(
72 'Could not find unique SAML attribute for the configured identifier: %s',
73 var_export($this->idp->getUidClaim(), 1)
77 $this->uid = $this->attributes[$this->idp->getUidClaim()][0];
85 if (!is_array($this->attributes) || 0 === count($this->attributes)) {
86 $this->
getLogger()->warning(
'Could not parse any attributes from SAML response.');
96 $this->
getLogger()->warning($e->getMessage());
108 $update_auth_mode =
false;
120 if (strlen($internal_account) == 0) {
121 $update_auth_mode =
true;
125 $fallback_auth_mode =
'local';
126 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Trying to find ext_account "%s" for auth_mode "%s".', $this->uid, $fallback_auth_mode));
130 if (
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode')) {
131 $defaultAuth =
$GLOBALS[
'DIC'][
'ilSetting']->get(
'auth_mode');
135 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Could not find ext_account "%s" for auth_mode "%s".', $this->uid, $fallback_auth_mode));
137 $fallback_auth_mode =
'default';
138 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Trying to find ext_account "%s" for auth_mode "%s".', $this->uid, $fallback_auth_mode));
143 if (strlen($internal_account) > 0) {
144 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Found user "%s" for ext_account "%s" in ILIAS database.', $internal_account, $this->uid));
146 if ($this->idp->isSynchronizationEnabled()) {
147 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'SAML user synchronisation is enabled, so update existing user "%s" with ext_account "%s".', $internal_account, $this->uid));
148 $internal_account = $this->
importUser($internal_account, $this->uid, $this->attributes);
151 if ($update_auth_mode) {
168 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Could not find an existing user for ext_account "%s" for any relevant auth_mode.', $this->uid));
169 if ($this->idp->isSynchronizationEnabled()) {
175 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Account migration is enabled, so redirecting ext_account "%s" to account migration screen.', $this->uid));
182 $new_name = $this->
importUser(null, $this->uid, $this->attributes);
183 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Created new user account with login "%s" and ext_account "%s".', $new_name, $this->uid));
189 if (strlen($this->return_to)) {
221 $this->
getLogger()->warning(
'Cannot find user id for external account: ' . $this->
getCredentials()->getUsername());
230 $this->force_new_account =
true;
240 $this->migration_account = $a_name;
256 return AUTH_SAML .
'_' . $this->idp->getIdpId();
264 return 'saml_' . $this->idp->getIdpId();
273 public function importUser($a_internal_login, $a_external_account, $a_user_data = array())
278 $xml_writer->xmlStartTag(
'Users');
279 if (null === $a_internal_login) {
280 $login = $a_user_data[$this->idp->getLoginClaim()][0];
283 $xml_writer->xmlStartTag(
'User', array(
'Action' =>
'Insert'));
284 $xml_writer->xmlElement(
'Login', array(),
$login);
286 $xml_writer->xmlElement(
'Role', array(
287 'Id' => $this->idp->getDefaultRoleId(),
292 $xml_writer->xmlElement(
'Active', array(),
"true");
293 $xml_writer->xmlElement(
'TimeLimitOwner', array(),
USER_FOLDER_ID);
294 $xml_writer->xmlElement(
'TimeLimitUnlimited', array(), 1);
295 $xml_writer->xmlElement(
'TimeLimitFrom', array(), time());
296 $xml_writer->xmlElement(
'TimeLimitUntil', array(), time());
298 $xml_writer->xmlElement(
'ExternalAccount', array(), $a_external_account);
302 $login = $a_internal_login;
305 $xml_writer->xmlStartTag(
'User', array(
'Action' =>
'Update',
'Id' => $usr_id));
307 $loginClaim = $a_user_data[$this->idp->getLoginClaim()][0];
308 if (
$login != $loginClaim) {
310 $xml_writer->xmlElement(
'Login', array(),
$login);
316 foreach ($mapping as
$rule) {
319 $value = $attributeValueParser->parse();
322 $this->
getLogger()->warning($e->getMessage());
327 $xml_writer->xmlEndTag(
'User');
328 $xml_writer->xmlEndTag(
'Users');
331 include_once
'./Services/User/classes/class.ilUserImportParser.php';
333 $importParser->setXMLContent($xml_writer->xmlDumpMem(
false));
334 $importParser->setRoleAssignment(array(
335 $this->idp->getDefaultRoleId() => $this->idp->getDefaultRoleId()
339 $importParser->startParsing();
353 switch (strtolower($value)) {
356 $xml_writer->
xmlElement(
'Gender', array(),
'n');
361 $xml_writer->
xmlElement(
'Gender', array(),
'm');
367 $xml_writer->
xmlElement(
'Gender', array(),
'f');
373 $xml_writer->
xmlElement(
'Firstname', array(), $value);
377 $xml_writer->
xmlElement(
'Lastname', array(), $value);
381 $xml_writer->
xmlElement(
'Email', array(), $value);
385 $xml_writer->
xmlElement(
'Institution', array(), $value);
389 $xml_writer->
xmlElement(
'Department', array(), $value);
393 $xml_writer->
xmlElement(
'Hobby', array(), $value);
397 $xml_writer->
xmlElement(
'Title', array(), $value);
401 $xml_writer->
xmlElement(
'Street', array(), $value);
405 $xml_writer->
xmlElement(
'City', array(), $value);
409 $xml_writer->
xmlElement(
'PostalCode', array(), $value);
413 $xml_writer->
xmlElement(
'Country', array(), $value);
417 $xml_writer->
xmlElement(
'PhoneOffice', array(), $value);
421 $xml_writer->
xmlElement(
'PhoneHome', array(), $value);
425 $xml_writer->
xmlElement(
'PhoneMobile', array(), $value);
429 $xml_writer->
xmlElement(
'Fax', array(), $value);
432 case 'referral_comment':
433 $xml_writer->
xmlElement(
'Comment', array(), $value);
436 case 'matriculation':
437 $xml_writer->
xmlElement(
'Matriculation', array(), $value);
441 $xml_writer->
xmlElement(
'Birthday', array(), $value);
450 if (!isset($udf_data[1])) {
457 array(
'Id' => $definition[
'il_id'],
'Name' => $definition[
'field_name']),
buildUserAttributeXml(\ilXmlWriter $xml_writer, \ilExternalAuthUserAttributeMappingRule $rule, $value)
__construct(\ilAuthFrontendCredentials $credentials, $a_idp_id=null)
ilAuthProviderSaml constructor.
createNewAccount(\ilAuthStatus $status)
determineUidFromAttributes()
Class ilExternalAuthUserUpdateAttributeMappingFilter.
static _getInstance()
Get instance.
Description of class interface.
importUser($a_internal_login, $a_external_account, $a_user_data=array())
doAuthentication(\ilAuthStatus $status)
Do authentication.Authentication status bool
getExternalAccountName()
Get external account name.string
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
static getInstanceByIdpId($a_idp_id)
static _lookupId($a_user_str)
Lookup id by login.
setAuthenticatedUserId($a_id)
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...
setExternalAccountName($a_name)
Set external account name.
Base class for authentication providers (radius, ldap, apache, ...)
Class ilAuthFrontendCredentialsSaml.
Standard interface for auth provider implementations.
Class ilExternalAuthUserAttributeMapping.
setStatus($a_status)
Set auth status.
Class ilExternalAuthUserAttributeMappingRule.
migrateAccount(ilAuthStatus $status)
Create new account.
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...
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
Class ilAuthProviderSaml.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
const STATUS_AUTHENTICATED
Class ilExternalAuthUserCreationAttributeMappingFilter.
handleSamlAuth(\ilAuthStatus $status)
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
const USER_FOLDER_ID
Class ilObjUserFolder.
static getLogger($a_component_id)
Get component logger.
static _writeAuthMode($a_usr_id, $a_auth_mode)
Class ilSamlMappedUserAttributeValueParser.
Auth status implementation.
Description of class class.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static getFirstActiveIdp()