Skip to content
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

Overwrite the NameID when specified in use_as_nameid ARP setting #1308

Merged
merged 6 commits into from
Aug 21, 2024

Conversation

MKodde
Copy link
Member

@MKodde MKodde commented Aug 15, 2024

This PR aims to close the feature described in issue: #1301 For functional details, please study the well described feature there.

For this PR some noteworthy things passed:

  1. A small boyscout task was performed in commit b82468c
  2. I tried to make things solid as possible. But the library code is challenging in that regard. But I tried to make up for that by adding as many tests as possible.

MKodde added 4 commits August 15, 2024 09:25
Boyscout work. This was done to make testing easier, but mostly to
follow the best practice
This resolver actually searches the ARP for a given SP and resolves if
NameID substitution should take place. If it decides it should, it
returns the attributename of which attr to take the new NameId value
The output filter will handle the name id substitution logic. As it
already juggles the correctly setting of the desired identity (nameid,
collabpersonid) values.
@MKodde MKodde force-pushed the feature/use_as_nameid branch from 12257be to b6f59b0 Compare August 15, 2024 08:50
@MKodde MKodde requested a review from parijke August 15, 2024 08:56
Copy link

@parijke parijke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job again. I set some suggestions. Feel free to adapt or ignore them

public function findNameIdSubstitute(AttributeReleasePolicy $arp, array $responseAttributes): ?string
{
$substituteAttribute = $arp->findNameIdSubstitute();
if ($substituteAttribute !== null && array_key_exists($substituteAttribute, $responseAttributes)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to encapsulate this complex if in a descriptive private method like isValidAttibute

Comment on lines 142 to +145
if (isset($rule['use_as_nameid']) && $rule['use_as_nameid'] === true) {
if (array_key_exists('release_as', $rule)) {
return $rule['release_as'];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be combined in a local method like ruleHasReleaseAs or so?

if ($this->ruleHasReleaseAs($rule)) {
    return $rule['release_as'];
}


// Find out if the EduPersonTargetedId is in the ARP of the destination SP.
// If the ARP is NULL this means no ARP = let everything through including ePTI.
// Otherwise, only add ePTI if it's actually in the ARP.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment needs to be reworded because the logic is now spread to other places.

Maybe here something like: if there's an ARP, but it does not contain the EPTI, we're done now.

And below: We arrive here if either: 1) the ARP is NULL, this means no ARP = let everything through including ePTI; or 2) the ARP is not null and does contain the EPTI attribute. In both cases, set the EPTI attribute.

An alternative is to change the logic and keep everything related to EPTI together. So remove this condition and return here, but check for ARP === null OR ARP contains EPTI below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I think improving the inline doc is a nice improvement. Moving the logic to the input filter will not result in the desired outcome. This is what I tried first. But then the AddIdentityAttributes output filter would overwrite the NameId again.

Or do you suggest another solution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just a very clear comment like there's now suffices to alleviate the concern of understandability.

$arp = $destinationMetadata->getAttributeReleasePolicy();
if (!is_null($arp) && !$arp->hasAttribute(Constants::EPTI_URN_MACE)) {
return;
if (!is_null($arp)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we go through the trouble to resolve a nameid above if we're going to overwrite it anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at it like this:

  1. We need to set the nameId to the resolved value.
  2. We might need to overwrite it with the substitute value.

What could be done is to move the NameIdResolver logic down below, and only resolve the nameId if we did not use the substitute.

Copy link
Member

@thijskh thijskh Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, there's two ways to look at this, you do what you think is best

MKodde added 2 commits August 20, 2024 16:14
Thanks @thijskh for suggesting this improvement
Prevent possible unnecesary resolving of the NameId

This makes the logic slightly less intuitive (INHM) but prevents the
resolver from doing it's work without reason.
@MKodde MKodde force-pushed the feature/use_as_nameid branch from fb00eed to 2acb8c9 Compare August 21, 2024 07:05
@MKodde MKodde merged commit 39c6279 into feature/release-as Aug 21, 2024
2 checks passed
@MKodde MKodde deleted the feature/use_as_nameid branch August 21, 2024 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants