-
Notifications
You must be signed in to change notification settings - Fork 27
issue-1931 nameid lookup api #1959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kayjoosten
wants to merge
6
commits into
main
Choose a base branch
from
feature/1931-nameid-lookup-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ec4b54
feat: add NameID lookup API (#1931)
kayjoosten 6367c74
test: add unit, functional and integration tests for NameID lookup API
kayjoosten c074c69
Comments
kayjoosten 499ceb9
config: merge api.users_nameid and api.users_id into single feature flag
kayjoosten 19e1678
feat: use single feature flag for both NameID lookup endpoints
kayjoosten d049fad
config: replace two NameID feature flag params with single feature_ap…
kayjoosten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| parameters: | ||
| api.users.nameIdLookup.username: nameid | ||
| api.users.nameIdLookup.password: secret | ||
| feature_api_users_nameid_lookup: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2026 SURFnet B.V. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenConext\EngineBlock\Doctrine\Migrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
|
|
||
| /** | ||
| * Corrects the column comment on saml_persistent_id.persistent_id. | ||
| * | ||
| * The original comment read "SHA1 of service_provider_uuid + user_uuid", which was | ||
| * inaccurate in two ways: the operand order was wrong, and the COIN: salt was omitted. | ||
johanib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * The actual value stored is sha1('COIN:' + user_uuid + service_provider_uuid), as | ||
| * defined in EngineBlock_Saml2_NameIdResolver::PERSISTENT_NAMEID_SALT. | ||
| * | ||
| * NOTE: This migration is NOT mandatory. It only updates a database-level column comment | ||
| * and has no effect on data integrity or application behaviour. It is safe to skip on | ||
| * existing installations where updating the comment is not considered necessary. | ||
| */ | ||
| final class Version20260331000000 extends AbstractEngineBlockMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return 'Corrects the column comment on saml_persistent_id.persistent_id to accurately reflect the SHA1 formula.'; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| $this->addSql( | ||
| "ALTER TABLE `saml_persistent_id` MODIFY COLUMN `persistent_id` CHAR(40) NOT NULL COMMENT 'SHA1 of COIN: + user_uuid + service_provider_uuid'" | ||
| ); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| $this->addSql( | ||
| "ALTER TABLE `saml_persistent_id` MODIFY COLUMN `persistent_id` CHAR(40) NOT NULL COMMENT 'SHA1 of service_provider_uuid + user_uuid'" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/OpenConext/EngineBlock/Service/NameIdLookupService.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2026 SURFnet B.V. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| namespace OpenConext\EngineBlock\Service; | ||
|
|
||
| use OpenConext\EngineBlock\Authentication\Value\CollabPersonId; | ||
| use OpenConext\EngineBlock\Authentication\Value\CollabPersonUuid; | ||
| use OpenConext\EngineBlock\Authentication\Value\SchacHomeOrganization; | ||
| use OpenConext\EngineBlock\Authentication\Value\Uid; | ||
| use OpenConext\EngineBlockBundle\Authentication\Entity\SamlPersistentId; | ||
| use OpenConext\EngineBlockBundle\Authentication\Repository\SamlPersistentIdRepository; | ||
| use OpenConext\EngineBlockBundle\Authentication\Repository\ServiceProviderUuidRepository; | ||
| use OpenConext\EngineBlockBundle\Authentication\Repository\UserRepository; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| final class NameIdLookupService | ||
| { | ||
| public function __construct( | ||
| private readonly UserRepository $userRepository, | ||
| private readonly ServiceProviderUuidRepository $spUuidRepository, | ||
| private readonly SamlPersistentIdRepository $persistentIdRepository, | ||
| private readonly LoggerInterface $logger | ||
| ) { | ||
| } | ||
|
|
||
| public function resolveNameId(string $schacHomeOrganization, string $uid, string $spEntityId): ?NameIdResult | ||
| { | ||
| $collabPersonId = CollabPersonId::generateWithReplacedAtSignFrom( | ||
| new Uid($uid), | ||
| new SchacHomeOrganization($schacHomeOrganization) | ||
| ); | ||
|
|
||
| $user = $this->userRepository->findByCollabPersonId($collabPersonId); | ||
| if ($user === null) { | ||
| $this->logger->debug('NameIdLookupService: user not found', [ | ||
johanib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'collabPersonId' => $collabPersonId->getCollabPersonId(), | ||
| ]); | ||
| return null; | ||
| } | ||
|
|
||
| $spUuid = $this->spUuidRepository->findUuidByEntityId($spEntityId); | ||
| if ($spUuid === null) { | ||
| $this->logger->debug('NameIdLookupService: SP not found', ['spEntityId' => $spEntityId]); | ||
| return null; | ||
| } | ||
|
|
||
| $userUuid = $user->collabPersonUuid->getUuid(); | ||
| $stored = $this->persistentIdRepository->findByUserAndSpUuid($userUuid, $spUuid); | ||
|
|
||
| if ($stored !== null) { | ||
| return new NameIdResult($stored->persistentId, true); | ||
| } | ||
|
|
||
| return new NameIdResult(SamlPersistentId::generate($userUuid, $spUuid)->persistentId, false); | ||
| } | ||
|
|
||
| public function resolveUserIdentity(string $persistentId): ?UserIdentityResult | ||
| { | ||
| $entry = $this->persistentIdRepository->find($persistentId); | ||
| if ($entry === null) { | ||
| return null; | ||
| } | ||
|
|
||
| $user = $this->userRepository->findByCollabPersonUuid(new CollabPersonUuid($entry->userUuid)); | ||
| if ($user === null) { | ||
| $this->logger->warning( | ||
| 'NameIdLookupService: saml_persistent_id entry exists but user record is missing', | ||
| ['userUuid' => $entry->userUuid] | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| $spEntityId = $this->spUuidRepository->findEntityIdByUuid($entry->serviceProviderUuid); | ||
| if ($spEntityId === null) { | ||
| $this->logger->warning( | ||
| 'NameIdLookupService: saml_persistent_id entry exists but SP UUID record is missing', | ||
| ['serviceProviderUuid' => $entry->serviceProviderUuid] | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| return new UserIdentityResult( | ||
| $user->collabPersonId->getSchacHomeOrganization(), | ||
| $user->collabPersonId->getStoredUid(), | ||
| $spEntityId, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2026 SURFnet B.V. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| namespace OpenConext\EngineBlock\Service; | ||
|
|
||
| use JsonSerializable; | ||
|
|
||
| final class NameIdResult implements JsonSerializable | ||
| { | ||
| public function __construct( | ||
| public readonly string $nameId, | ||
| public readonly bool $stored, | ||
| ) { | ||
| } | ||
|
|
||
| public function jsonSerialize(): array | ||
| { | ||
| return [ | ||
| 'nameid' => $this->nameId, | ||
| 'stored' => $this->stored, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2026 SURFnet B.V. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| namespace OpenConext\EngineBlock\Service; | ||
|
|
||
| use JsonSerializable; | ||
|
|
||
| final class UserIdentityResult implements JsonSerializable | ||
| { | ||
| public function __construct( | ||
| public readonly string $schacHomeOrganization, | ||
| public readonly string $uid, | ||
| public readonly string $spEntityId, | ||
| ) { | ||
| } | ||
|
|
||
| public function jsonSerialize(): array | ||
| { | ||
| return [ | ||
| 'schacHomeOrganization' => $this->schacHomeOrganization, | ||
| 'uid' => $this->uid, | ||
| 'sp_entityid' => $this->spEntityId, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.