19 declare(strict_types=1);
43 $this->
logger = $DIC->logger()->auth();
67 return $this->int_account ===
'';
82 $importParser->setXMLContent($this->writer->xmlDumpMem(
false));
85 $importParser->setRoleAssignment($roles);
88 $importParser->startParsing();
89 $debug = $importParser->getProtocol();
102 $this->writer->xmlStartTag(
'Users');
105 $this->writer->xmlStartTag(
'User', [
'Action' =>
'Insert']);
108 $this->writer->xmlStartTag(
115 $this->writer->xmlElement(
'Login', [], $this->int_account);
118 $this->writer->xmlElement(
'ExternalAccount', array(), $this->ext_account);
119 $this->writer->xmlElement(
'AuthMode', array(
'type' => self::AUTH_MODE), null);
124 $this->writer->xmlElement(
'Active', array(),
"true");
125 $this->writer->xmlElement(
'TimeLimitOwner', array(), 7);
126 $this->writer->xmlElement(
'TimeLimitUnlimited', array(), 1);
127 $this->writer->xmlElement(
'TimeLimitFrom', array(), time());
128 $this->writer->xmlElement(
'TimeLimitUntil', array(), time());
131 foreach ($this->
settings->getProfileMappingFields() as $field => $lng_key) {
132 $connect_name = $this->
settings->getProfileMappingFieldValue($field);
133 if (!$connect_name) {
134 $this->
logger->debug(
'Ignoring unconfigured field: ' . $field);
138 $this->
logger->debug(
'Ignoring ' . $field .
' for update.');
142 $value = $this->
valueFrom($connect_name);
144 $this->
logger->debug(
'Cannot find user data in ' . $connect_name);
150 $this->writer->xmlElement(
'Firstname', [], $value);
154 $this->writer->xmlElement(
'Lastname', [], $value);
158 $this->writer->xmlElement(
'Email', [], $value);
162 $this->writer->xmlElement(
'Birthday', [], $value);
166 $this->writer->xmlEndTag(
'User');
167 $this->writer->xmlEndTag(
'Users');
169 $this->
logger->debug($this->writer->xmlDumpMem());
178 $this->
logger->debug(
'Parsing role assignments');
186 foreach ($this->
settings->getRoleMappings() as $role_id => $role_info) {
190 if ($role_info[
'value'] ===
'') {
191 $this->
logger->debug(
'No role mapping for role: ' . $role_id);
195 [$role_attribute, $role_value] = array_map(trim(...), explode(
'::', $role_info[
'value']));
197 if (!$role_attribute || !$role_value) {
198 $this->
logger->debug(
'No valid role mapping configuration for: ' . $role_id);
202 if (!isset($this->user_info->{$role_attribute})) {
203 $this->
logger->debug(
'No user info passed');
208 $this->
logger->debug(
'No user role update for role: ' . $role_id);
212 if (is_array($this->user_info->{$role_attribute})) {
213 $roles_claim = array_map(
214 static function (mixed $value):
string {
215 return match (
true) {
216 is_string($value) => trim($value),
217 $value instanceof
stdClass && property_exists($value,
'id') => trim((
string) $value->id),
218 $value instanceof
stdClass && property_exists($value,
'value') => trim((
string) $value->value),
220 'Unexpected role value type, please check your provider configuration: %s',
221 print_r($value,
true)
225 $this->user_info->{$role_attribute}
227 if (!in_array($role_value, $roles_claim,
true)) {
228 $this->
logger->debug(
'User account has no ' . $role_value);
231 } elseif (strcmp(trim($this->user_info->{$role_attribute}), $role_value) !== 0) {
232 $this->
logger->debug(
'User account has no ' . $role_value);
236 $this->
logger->debug(
'Matching role mapping for role_id: ' . $role_id);
239 $roles_assignable[(
int) $role_id] = (
int) $role_id;
240 $long_role_id = (
'il_' .
IL_INST_ID .
'_role_' . $role_id);
242 $this->writer->xmlElement(
245 'Id' => $long_role_id,
257 $this->writer->xmlElement(
260 'Id' => $long_role_id,
268 return $roles_assignable;
271 protected function valueFrom(
string $connect_name): string
273 if (!$connect_name) {
276 if (!property_exists($this->user_info, $connect_name)) {
277 $this->
logger->debug(
'Cannot find property ' . $connect_name .
' in user info ');
281 return (
string) $this->user_info->{$connect_name};
static _generateLogin(string $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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
setExternalAccount(string $ext_account)
setInternalAccount(string $int_account)
valueFrom(string $connect_name)
ilOpenIdConnectSettings $settings
parseRoleAssignments()
Parse role assignments.
__construct(ilOpenIdConnectSettings $settings, stdClass $user_info)