48 if (
null === $a_idp_id) {
66 !array_key_exists($this->idp->getUidClaim(), $this->attributes) ||
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])
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';
129 if (!
defined(
'AUTH_DEFAULT')) {
130 define(
'AUTH_DEFAULT',
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode') ?
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode') :
AUTH_LOCAL);
136 $fallback_auth_mode =
'default';
142 if (strlen($internal_account) > 0) {
145 if ($this->idp->isSynchronizationEnabled()) {
146 ilLoggerFactory::getLogger(
'auth')->debug(
sprintf(
'SAML user synchronisation is enabled, so update existing user "%s" with ext_account "%s".', $internal_account, $this->uid));
147 $internal_account = $this->
importUser($internal_account, $this->uid, $this->attributes);
150 if ($update_auth_mode) {
168 if ($this->idp->isSynchronizationEnabled()) {
170 if ($this->idp->isAccountMigrationEnabled() && !$this->force_new_account) {
181 $new_name = $this->
importUser(
null, $this->uid, $this->attributes);
188 if (strlen($this->return_to)) {
220 $this->
getLogger()->warning(
'Cannot find user id for external account: ' . $this->
getCredentials()->getUsername());
229 $this->force_new_account =
true;
239 $this->migration_account = $a_name;
255 return AUTH_SAML .
'_' . $this->idp->getIdpId();
263 return 'saml_' . $this->idp->getIdpId();
272 public function importUser($a_internal_login, $a_external_account, $a_user_data = array())
277 $xml_writer->xmlStartTag(
'Users');
278 if (
null === $a_internal_login) {
279 $login = $a_user_data[$this->idp->getLoginClaim()][0];
282 $xml_writer->xmlStartTag(
'User', array(
'Action' =>
'Insert'));
283 $xml_writer->xmlElement(
'Login', array(), $login);
285 $xml_writer->xmlElement(
'Role', array(
286 'Id' => $this->idp->getDefaultRoleId(),
291 $xml_writer->xmlElement(
'Active', array(),
"true");
292 $xml_writer->xmlElement(
'TimeLimitOwner', array(),
USER_FOLDER_ID);
293 $xml_writer->xmlElement(
'TimeLimitUnlimited', array(), 1);
294 $xml_writer->xmlElement(
'TimeLimitFrom', array(), time());
295 $xml_writer->xmlElement(
'TimeLimitUntil', array(), time());
297 $xml_writer->xmlElement(
'ExternalAccount', array(), $a_external_account);
301 $login = $a_internal_login;
304 $xml_writer->xmlStartTag(
'User', array(
'Action' =>
'Update',
'Id' => $usr_id));
306 $loginClaim = $a_user_data[$this->idp->getLoginClaim()][0];
307 if ($login != $loginClaim) {
309 $xml_writer->xmlElement(
'Login', array(), $login);
315 foreach ($mapping as
$rule) {
318 $value = $attributeValueParser->parse();
321 $this->
getLogger()->warning($e->getMessage());
326 $xml_writer->xmlEndTag(
'User');
327 $xml_writer->xmlEndTag(
'Users');
330 include_once
'./Services/User/classes/class.ilUserImportParser.php';
332 $importParser->setXMLContent($xml_writer->xmlDumpMem(
false));
333 $importParser->setRoleAssignment(array(
334 $this->idp->getDefaultRoleId() => $this->idp->getDefaultRoleId()
338 $importParser->startParsing();
350 switch (strtolower(
$rule->getAttribute())) {
352 switch (strtolower($value)) {
355 $xml_writer->
xmlElement(
'Gender', array(),
'n');
360 $xml_writer->
xmlElement(
'Gender', array(),
'm');
366 $xml_writer->
xmlElement(
'Gender', array(),
'f');
372 $xml_writer->
xmlElement(
'Firstname', array(), $value);
376 $xml_writer->
xmlElement(
'Lastname', array(), $value);
380 $xml_writer->
xmlElement(
'Email', array(), $value);
384 $xml_writer->
xmlElement(
'Institution', array(), $value);
388 $xml_writer->
xmlElement(
'Department', array(), $value);
392 $xml_writer->
xmlElement(
'Hobby', array(), $value);
396 $xml_writer->
xmlElement(
'Title', array(), $value);
400 $xml_writer->
xmlElement(
'Street', array(), $value);
404 $xml_writer->
xmlElement(
'City', array(), $value);
408 $xml_writer->
xmlElement(
'PostalCode', array(), $value);
412 $xml_writer->
xmlElement(
'Country', array(), $value);
416 $xml_writer->
xmlElement(
'PhoneOffice', array(), $value);
420 $xml_writer->
xmlElement(
'PhoneHome', array(), $value);
424 $xml_writer->
xmlElement(
'PhoneMobile', array(), $value);
428 $xml_writer->
xmlElement(
'Fax', array(), $value);
431 case 'referral_comment':
432 $xml_writer->
xmlElement(
'Comment', array(), $value);
435 case 'matriculation':
436 $xml_writer->
xmlElement(
'Matriculation', array(), $value);
440 $xml_writer->
xmlElement(
'Birthday', array(), $value);
444 if (substr(
$rule->getAttribute(), 0, 4) !=
'udf_') {
448 $udf_data = explode(
'_',
$rule->getAttribute());
449 if (!isset($udf_data[1])) {
456 array(
'Id' => $definition[
'il_id'],
'Name' => $definition[
'field_name']),
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
const USER_FOLDER_ID
Class ilObjUserFolder.
Class ilAuthFrontendCredentialsSaml.
Description of class class.
Class ilAuthProviderSaml.
buildUserAttributeXml(\ilXmlWriter $xml_writer, \ilExternalAuthUserAttributeMappingRule $rule, $value)
determineUidFromAttributes()
__construct(\ilAuthFrontendCredentials $credentials, $a_idp_id=null)
ilAuthProviderSaml constructor.
setExternalAccountName($a_name)
Set external account name.
createNewAccount(\ilAuthStatus $status)
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.
doAuthentication(\ilAuthStatus $status)
Do authentication.bool
migrateAccount(ilAuthStatus $status)
Create new account.
importUser($a_internal_login, $a_external_account, $a_user_data=array())
handleSamlAuth(\ilAuthStatus $status)
getTriggerAuthMode()
Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 1...
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
Base class for ILIAS Exception handling.
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($a_idp_id)
static getFirstActiveIdp()
Class ilSamlMappedUserAttributeValueParser.
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
static _getInstance()
Get instance.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Description of class interface.
Standard interface for auth provider implementations.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'