46 parent::__construct($credentials);
48 if (null === $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));
129 if (!
defined(
'AUTH_DEFAULT')) {
130 define(
'AUTH_DEFAULT',
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode') ?
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode') :
AUTH_LOCAL);
134 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Could not find ext_account "%s" for auth_mode "%s".', $this->uid, $fallback_auth_mode));
136 $fallback_auth_mode =
'default';
137 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Trying to find ext_account "%s" for auth_mode "%s".', $this->uid, $fallback_auth_mode));
142 if (strlen($internal_account) > 0) {
143 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Found user "%s" for ext_account "%s" in ILIAS database.', $internal_account, $this->uid));
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) {
167 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Could not find an existing user for ext_account "%s" for any relevant auth_mode.', $this->uid));
168 if ($this->idp->isSynchronizationEnabled()) {
174 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Account migration is enabled, so redirecting ext_account "%s" to account migration screen.', $this->uid));
181 $new_name = $this->
importUser(null, $this->uid, $this->attributes);
182 ilLoggerFactory::getLogger(
'auth')->debug(sprintf(
'Created new user account with login "%s" and ext_account "%s".', $new_name, $this->uid));
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");
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();
352 switch (strtolower($value)) {
431 case 'referral_comment':
435 case 'matriculation':
449 if (!isset($udf_data[1])) {
456 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
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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...
Create styles array
The data for the language used.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static _writeAuthMode($a_usr_id, $a_auth_mode)
Class ilSamlMappedUserAttributeValueParser.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Auth status implementation.
Description of class class.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
static getFirstActiveIdp()