Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Command/UpsertProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class UpsertProvider extends Base {
'shortcut' => null, 'mode' => InputOption::VALUE_REQUIRED, 'setting_key' => ProviderService::SETTING_MAPPING_LANGUAGE,
'description' => 'Attribute mapping of the account language',
],
'mapping-locale' => [
'shortcut' => null, 'mode' => InputOption::VALUE_REQUIRED, 'setting_key' => ProviderService::SETTING_MAPPING_LOCALE,
'description' => 'Attribute mapping of the account locale',
],
'mapping-website' => [
'shortcut' => null, 'mode' => InputOption::VALUE_REQUIRED, 'setting_key' => ProviderService::SETTING_MAPPING_WEBSITE,
'description' => 'Attribute mapping of the website',
Expand Down
2 changes: 2 additions & 0 deletions lib/Service/ProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ProviderService {
public const SETTING_MAPPING_QUOTA = 'mappingQuota';
public const SETTING_MAPPING_GROUPS = 'mappingGroups';
public const SETTING_MAPPING_LANGUAGE = 'mappingLanguage';
public const SETTING_MAPPING_LOCALE = 'mappingLocale';
public const SETTING_MAPPING_ADDRESS = 'mappingAddress';
public const SETTING_MAPPING_STREETADDRESS = 'mappingStreetaddress';
public const SETTING_MAPPING_POSTALCODE = 'mappingPostalcode';
Expand Down Expand Up @@ -147,6 +148,7 @@ private function getSupportedSettings(): array {
self::SETTING_MAPPING_UID,
self::SETTING_MAPPING_GROUPS,
self::SETTING_MAPPING_LANGUAGE,
self::SETTING_MAPPING_LOCALE,
self::SETTING_MAPPING_ADDRESS,
self::SETTING_MAPPING_STREETADDRESS,
self::SETTING_MAPPING_POSTALCODE,
Expand Down
19 changes: 19 additions & 0 deletions lib/Service/ProvisioningService.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
$languageAttribute = $this->providerService->getSetting($providerId, ProviderService::SETTING_MAPPING_LANGUAGE, 'language');
$language = $this->getClaimValue($idTokenPayload, $languageAttribute, $providerId);//$idTokenPayload->{$languageAttribute} ?? null;

$localeAttribute = $this->providerService->getSetting($providerId, ProviderService::SETTING_MAPPING_LOCALE, 'locale');
$locale = $this->getClaimValue($idTokenPayload, $localeAttribute, $providerId);

$genderAttribute = $this->providerService->getSetting($providerId, ProviderService::SETTING_MAPPING_GENDER, 'gender');
$gender = $this->getClaimValue($idTokenPayload, $genderAttribute, $providerId);//$idTokenPayload->{$genderAttribute} ?? null;

Expand Down Expand Up @@ -303,6 +306,22 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
}
}

$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_LOCALE, $idTokenPayload, $locale);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Locale mapping event dispatched');
if ($event->hasValue()) {
$locale = $event->getValue();
$locales = $this->l10nFactory->findAvailableLocales();
$localeCodes = array_map(static function ($l) {
return $l['code'];
}, $locales);
if (in_array($locale, $localeCodes, true) || $locale === 'en') {
$this->config->setUserValue($user->getUID(), 'core', 'locale', $locale);
} else {
$this->logger->debug('Invalid locale in ID token', ['locale' => $locale]);
}
}

$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_LANGUAGE, $idTokenPayload, $language);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Language mapping event dispatched');
Expand Down
7 changes: 7 additions & 0 deletions src/components/SettingsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@
type="text"
placeholder="language">
</p>
<p>
<label for="mapping-locale">{{ t('user_oidc', 'Locale mapping') }}</label>
<input id="mapping-locale"
v-model="localProvider.settings.mappingLocale"
type="text"
placeholder="locale">
</p>
<p>
<label for="mapping-role">{{ t('user_oidc', 'Role/Title mapping') }}</label>
<input id="mapping-role"
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Service/ProviderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function testGetProvidersWithSettings() {
'mappingUid' => '1',
'mappingGroups' => '1',
'mappingLanguage' => '1',
'mappingLocale' => '1',
'mappingAddress' => '1',
'mappingStreetaddress' => '1',
'mappingPostalcode' => '1',
Expand Down Expand Up @@ -113,6 +114,7 @@ public function testGetProvidersWithSettings() {
'mappingUid' => '1',
'mappingGroups' => '1',
'mappingLanguage' => '1',
'mappingLocale' => '1',
'mappingAddress' => '1',
'mappingStreetaddress' => '1',
'mappingPostalcode' => '1',
Expand Down Expand Up @@ -161,6 +163,7 @@ public function testSetSettings() {
'providerBasedId' => false,
'groupProvisioning' => true,
'mappingLanguage' => 'language',
'mappingLocale' => 'locale',
'mappingAddress' => 'address',
'mappingStreetaddress' => 'street_address',
'mappingPostalcode' => 'postal_code',
Expand Down Expand Up @@ -192,6 +195,7 @@ public function testSetSettings() {
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_UID, '', 'uid'],
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_GROUPS, '', 'groups'],
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_LANGUAGE, '', 'language'],
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_LOCALE, '', 'locale'],
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_ADDRESS, '', 'address'],
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_STREETADDRESS, '', 'street_address'],
[Application::APP_ID, 'provider-1-' . ProviderService::SETTING_MAPPING_POSTALCODE, '', 'postal_code'],
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Service/ProvisioningServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function testProvisionUserAutoProvisioning(): void {
[$providerId, ProviderService::SETTING_MAPPING_QUOTA, 'quota', 'quota'],
[$providerId, ProviderService::SETTING_GROUP_PROVISIONING, '0', '0'],
[$providerId, ProviderService::SETTING_MAPPING_LANGUAGE, 'language', 'language'],
[$providerId, ProviderService::SETTING_MAPPING_LOCALE, 'locale', 'locale'],
[$providerId, ProviderService::SETTING_MAPPING_ADDRESS, 'address', 'address'],
[$providerId, ProviderService::SETTING_MAPPING_STREETADDRESS, 'street_address', 'street_address'],
[$providerId, ProviderService::SETTING_MAPPING_POSTALCODE, 'postal_code', 'postal_code'],
Expand Down Expand Up @@ -201,6 +202,7 @@ public function testProvisionUserInvalidProperties(): void {
[$providerId, ProviderService::SETTING_MAPPING_QUOTA, 'quota', 'quota'],
[$providerId, ProviderService::SETTING_GROUP_PROVISIONING, '0', '0'],
[$providerId, ProviderService::SETTING_MAPPING_LANGUAGE, 'language', 'language'],
[$providerId, ProviderService::SETTING_MAPPING_LOCALE, 'locale', 'locale'],
[$providerId, ProviderService::SETTING_MAPPING_ADDRESS, 'address', 'address'],
[$providerId, ProviderService::SETTING_MAPPING_STREETADDRESS, 'street_address', 'street_address'],
[$providerId, ProviderService::SETTING_MAPPING_POSTALCODE, 'postal_code', 'postal_code'],
Expand Down
Loading