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

Prioritize groups path over groups claim #767

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

oemel09
Copy link
Contributor

@oemel09 oemel09 commented Feb 29, 2024

Fixes #766
Potentially existing group claims will be overwritten by the claim specified in smallrye.jwt.path.groups.

@sberyozkin
Copy link
Contributor

@oemel09 I believe it has to be done somehow differently, something along this line: 1) if the path is set - start with checking it, if it produces nothing, check the groups, and finally fallback to the default role

It also should be tested

@oemel09
Copy link
Contributor Author

oemel09 commented Mar 1, 2024

Question is if the groups should be checked at all when the claim specified by smallrye.jwt.path.groups is empty or if it should use the default groups (specified via smallrye.jwt.claims.groups) without checking the actual groups claim in that case.
I'd vote for the latter.

@sberyozkin
Copy link
Contributor

Question is if the groups should be checked at all when the claim specified by smallrye.jwt.path.groups is empty or if it should use the default groups (specified via smallrye.jwt.claims.groups) without checking the actual groups claim in that case.

So, if the path is configured, check it, otherwise check groups, and in both cases, fallback to the default role if it is set.
It makes sense, but I don't want to break someone's code where they may have the path configured right now which may be pointing to some non-existing claim, which has no impact anyway because the groups is always producing roles, and now, since the order is changed, and we skip the roles, their applications are broken

@oemel09
Copy link
Contributor Author

oemel09 commented Mar 5, 2024

but I don't want to break someone's code

When the groups claim is present in the token and the user has set smallrye.jwt.claims.groups to another claim which exists, the current implementation will still use the roles from the groups claim, but we want it to use the roles from the custom claim. So this is a breaking change already.

With the flow you described it is not possible to use the default role (via smallrye.jwt.claims.groups) in combination with the smallrye.jwt.claims.groups setting when the token also has a groups claim.

@oemel09 oemel09 force-pushed the always-respect-groups-path branch from 3308b38 to 5c1f29c Compare March 5, 2024 12:22
@sberyozkin
Copy link
Contributor

sberyozkin commented Mar 5, 2024

@oemel09 Can I ask for the clarification. Do you have tokens with the custom groups claim whose value has nothing to do with roles ? Or do you have tokens with the groups claim containing roles but you want some other claim be used as a source of roles ?

@oemel09
Copy link
Contributor Author

oemel09 commented Mar 6, 2024

It's the former, in the groups claim in the token there are integers. But what I'm interested in is stored in a role claim.

@oemel09
Copy link
Contributor Author

oemel09 commented Mar 8, 2024

I changed the implementation in the way you suggested and also added tests to it.
As explained I'm still in favor of the other flow. But anyway, for my use case both flows would work.
What's the way forward here? And, in case you know it, how long will it take for this change to end up in quarkus? 🙈

@oemel09 oemel09 force-pushed the always-respect-groups-path branch from 5c1f29c to 62025e5 Compare March 8, 2024 12:30
@sberyozkin
Copy link
Contributor

@oemel09 I've been thinking about it for a while, and came to the conclusion that I was over-thinking about the side-effects.
If someone does set the custom role claims path then it should simply be used.

So lets get back to what I believe you were suggesting:

  • if the custom path is set - use it
  • otherwise check groups
  • If the roles is null and the default role is set - use it

Please do the final update per the above and resolve this issue

Thanks for the patience

@oemel09
Copy link
Contributor Author

oemel09 commented Mar 11, 2024

I did the changes and adapted the tests. I think I added all the relevant cases, please have a look at them and check if you are okay with all the expected results for each combination.

sberyozkin
sberyozkin previously approved these changes Mar 11, 2024
Copy link
Contributor

@sberyozkin sberyozkin left a comment

Choose a reason for hiding this comment

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

@oemel09 Can you please squash commits to only have a single one, with the same name as this PR one ?

@sberyozkin
Copy link
Contributor

You may have to build with Maven if the build fails with formatting errors

But when the custom path speficied in `smallrye.jwt.path.groups` is empty and no default groups is set
via `smallrye.jwt.claims.groups` an existing groups claim will still be used.

Signed-off-by: Lukas Ziefle <[email protected]>
@oemel09
Copy link
Contributor Author

oemel09 commented Mar 12, 2024

All done 👍

@sberyozkin sberyozkin self-requested a review March 12, 2024 10:28
@sberyozkin sberyozkin added this to the 4.5.0 milestone Mar 12, 2024
@sberyozkin sberyozkin merged commit 1847015 into smallrye:main Mar 12, 2024
5 checks passed
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.

Respect smallrye.jwt.path.groups even if the groups claim is present in the token
2 participants