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

Add AuthenticationRequest attributes to AuthenticationRequestContext so that users can access RoutingContext #40

Conversation

michalvavrik
Copy link
Contributor

@michalvavrik michalvavrik commented Dec 18, 2023

We add RoutingContext to authentication request attributes

https://github.com/quarkusio/quarkus/blob/main/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/security/HttpSecurityUtils.java#L14

which makes it possible for users to access RoutingContext when proactive auth is enabled. There are issues opened related to RoutingContext in augmentor

I've tried to explore passing the context via duplicated context local data quarkusio/quarkus#37795 but from comments you can see there are performance arguments against it. We already have this map with the RoutingContext, so now I propose to add authentication attributes to the authentication request context.

@michalvavrik
Copy link
Contributor Author

@sberyozkin I can't request review from you, can you have a look please?

@michalvavrik
Copy link
Contributor Author

@stuartwdouglas not sure if you wanna have a look and have a time?

@michalvavrik
Copy link
Contributor Author

Point here is that we already have a map with the context

https://github.com/quarkusio/quarkus/blob/4d07a919719e7bb50ecbc76501eb9b55559c711f/extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusIdentityProviderManagerImpl.java#L122

and users are trying to active CDI request context too early, so why don't give them chance to use the RoutingContext? We just pass the existing map without any modifications down, that is it.

@michalvavrik
Copy link
Contributor Author

michalvavrik commented Dec 29, 2023

I've changed my original proposal after talking to @sberyozkin . My original proposal was that we should add to SecurityIdentityAugmentor new method that will have authentication request attributes we already have (no creating of objects) and for those who don't need to the attributes, they could still use the original method:

default Uni<SecurityIdentity> augment(SecurityIdentity identity, AuthenticationRequestContext context, Map<String, Object> attributes) {
        return augment(identity, context);
    }

and I'd drop deprecation from my first commit, but Sergey raised the point that changing interface can be avoided by creating new authentication request context for every authentication request, so I accepted his proposal (it's normal we have different preferences :-), I liked mine).

I'll adjust PR description, title and maybe we can move on this.

@michalvavrik michalvavrik changed the title Propagate AuthenticationRequestContext attributes to augmentor Add AuthenticationRequest attributes to AuthenticationRequestContext so that users can access RoutingContext Dec 29, 2023
@sberyozkin
Copy link
Member

Hi @michalvavrik Thanks, sure, I'd still appreciate @stuartwdouglas commenting, only Stuart can merge it anyway.

Maybe your original proposal will win, today, now that I think about it after seeing both proposals, it looks OK, my only concern there is that the deprecated method will likely stay forever. But like you said, no context objects will be created during the augmentation - though an extra object will be allocated only if the augmentors are registered, which will not always be the case.

Can you please create a Quarkus branch based on the current PR for @stuartwdouglas to have a look ? I'll have no problems with your original PR code restored if this is what would be preferred.
Please look into it in early 2024 :-) and sorry if the current PR will end up to be reverted to your original idea in the end.

Thanks

@sberyozkin
Copy link
Member

@stuartwdouglas Please comment

@michalvavrik
Copy link
Contributor Author

Hi,

this is how Quarkus changes will look like (I'll write docs when there is final version of this PR) with current version of this PR: quarkusio/quarkus@3b741aa

Part that I consider strange is that during authentication (inside io.quarkus.security.identity.IdentityProvider#authenticate) same authentication attributes will be available both from AuthenticationRequest and from AuthenticationRequestContext.

Here is my preference:

@sberyozkin
Copy link
Member

Thanks @michalvavrik.
Unless an object creation has any real measurable impact, I'd go with this option, not because I suggested it, but because AuthenticationRequestContext seems like a good enough container for all things related to the request context (more or less the same a RoutingContext itself), even though right now, it is only positioned as a blocking context provider.
Otherwise, lets indeed do the original approach, I'll support it too.
Let @stuartwdouglas decide 👍

Thanks

@sberyozkin
Copy link
Member

@michalvavrik

Part that I consider strange is that during authentication (inside io.quarkus.security.identity.IdentityProvider#authenticate) same authentication attributes will be available both from AuthenticationRequest and from AuthenticationRequestContext.

Hmm, yeah, that is not quite cool. I suppose it favors your original PR then 👍

@michalvavrik
Copy link
Contributor Author

Let's hear third opinion, I think both proposals are acceptable. It can wait for Stuart. Thanks for your comments.

@sberyozkin
Copy link
Member

I'm now leaning toward your original proposal because having an ambiguity in the way these properties can be accepted in my proposal is not good, thanks. Hope Stuart will agree

@michalvavrik michalvavrik force-pushed the feature/add-auth-context-attributes-to-augmentor branch from c1cefd0 to 06ce769 Compare January 16, 2024 14:00
@michalvavrik
Copy link
Contributor Author

I'm now leaning toward your original proposal because having an ambiguity in the way these properties can be accepted in my proposal is not good, thanks. Hope Stuart will agree

in that case I switched to my original proposal but without deprecation, let's move on this one

@stuartwdouglas stuartwdouglas merged commit 4c04d40 into quarkusio:main Jan 17, 2024
3 checks passed
@michalvavrik michalvavrik deleted the feature/add-auth-context-attributes-to-augmentor branch January 17, 2024 08:30
@michalvavrik
Copy link
Contributor Author

Thank you for review. I've pinged @gsmet to make release when he finds a time.

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.

None yet

3 participants