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

Detect permission constructor parameters based on formal method names match with a method secured by the @PermissionsAllowed annotation #54

Conversation

michalvavrik
Copy link
Member

@michalvavrik michalvavrik commented Sep 19, 2024

Proposes to detect parameters of a custom java.security.Permission based on matching formal parameter names between Permission constructor and a method secured with the @PermissionsAllowed annotation. For ambiguous scenarios, user can specify params attribute explicitly like @PermissionsAllowed(params = "beanParam.nested"). This allows to determine concrete secured method parameter that needs to be passed to a Permission specified via permisson attribute, like @PermissionsAllowed(permission = "CustomPermission").

This is motivated by discussion in quarkusio/quarkus#43353.

@FroMage
Copy link
Member

FroMage commented Sep 19, 2024

This seems to be missing the implementation change. I'd suggest full names for the constants, so PARAMETER instead of `PARAM.

@michalvavrik
Copy link
Member Author

This seems to be missing the implementation change.

Autodetection based on parameter names is implemented and it is already done, what is different at the moment is that: it's only activated when you specify @PermissionsAllowed(params = "something"). It is in the Quarkus, but extra validation to improve user experience had to be done.

I'd suggest full names for the constants, so PARAMETER instead of `PARAM.

Will change that, thank you.

@michalvavrik
Copy link
Member Author

michalvavrik commented Sep 19, 2024

This seems to be missing the implementation change.

But yeah, it can only be merged/released/bumped to Quarkus when quarkusio/quarkus#43353 is finalized and approved, not before. Sorry I didn't mention it in the PR description, but I thought Sergey knew that.

@michalvavrik michalvavrik force-pushed the feature/change-default-permissions-allowed-behavior branch from 867d4e5 to 30dc1bb Compare September 19, 2024 13:33
@sberyozkin
Copy link
Member

I have a feeling we should not be really introducing these strategies but should simply enhance Quarkus directly to cover ambiguities. In many cases, just having BeanParam alone can handle all the ambiguities with multiple String types for example.

Otherwise, in those advanced cases where passing a BeanParam bean is not enough, expecting a precise name match is a totally normal expectation if a user, having 5 String JAX-RS parameters, only wants the 1st and last String parameter at the custom Permission level. Matching by types alone just does not work.

@sberyozkin
Copy link
Member

sberyozkin commented Sep 19, 2024

Michal, are you concerned that we have JAX-RS: String a but a custom permission having String theAValue ? Does any of our examples suggest such an option ? If not, we should just fix it to use names without having to deal with all the breaking changes flow, where in fact, we are just making it work properly in all the variations

@sberyozkin
Copy link
Member

sberyozkin commented Sep 19, 2024

@michalvavrik We can discuss it in a wider forum, and I guess I can add a breaking change note to the Migration guide, we just don't need an API change to support types only IMHO, this option's robustness is very limited

@michalvavrik
Copy link
Member Author

michalvavrik commented Sep 19, 2024

Michal, are you concerned that we have JAX-RS: String a but a custom permission having String theAValue ?

Yes, that is exactly my concern. I agree with above-mentioned arguments (your and Stephane comments).

Does any of our examples suggest such an option ?

I have checked https://quarkus.io/guides/security-authorize-web-endpoints-reference#permission-annotation and only problematic part I can see is one sentence The formal parameter update is identified as the first Library parameter and gets passed to the LibraryPermission class. .

If not, we should just fix it to use names without having to deal with all the breaking changes flow, where in fact, we are just making it work properly in all the variations

What we can do is to do matching based on parameter names. If there is not a one match based on name, we can fallback to matching based on the parameter types. I think we should drop behavior where it's identified based on data type if multiple strategies like proposed in this PR are not desirable. However this is why I think it is breaking change:

@PermissionsAllowed(permission=Custom.class)
public String getSomething(Library update, Library create) {

}

# and permission constructor

Custom(Library create) {}

that previously would be update and now is create.

@michalvavrik
Copy link
Member Author

However, that create update example is hopefully edge case. I believe if I add there validation exception that explains permission constructor and secured method parameters are not matching, it should be alright and users will know how to fix it easily. Let's drop autodetection based on parameter types completely. I'll integrate it.

@michalvavrik michalvavrik force-pushed the feature/change-default-permissions-allowed-behavior branch from 30dc1bb to e916ebe Compare September 20, 2024 06:49
@michalvavrik
Copy link
Member Author

@sberyozkin @FroMage updated API in this PR, now I'll update quarkusio/quarkus#43353 accordingly; comment if you want, or wait till the implementation is done

@michalvavrik michalvavrik force-pushed the feature/change-default-permissions-allowed-behavior branch from e916ebe to e96f1dd Compare September 20, 2024 09:48
@sberyozkin
Copy link
Member

Thanks @michalvavrik I think it looks good, let me just have another look early next week :-)

@cescoffier, FYI, here, Michal is only updating the JavaDocs advising how to ensure the JAX-RS parameter names match the custom permission constructor parameters, if you'd like, please comment

@sberyozkin sberyozkin self-requested a review September 22, 2024 21:08
@sberyozkin
Copy link
Member

@michalvavrik, I've just looked again, and it is really all very well explained, and indeed, like you said, that create update example is hopefully edge case. - definitely very edge case :-)

@sberyozkin
Copy link
Member

Let's keep the PR itself open for a while till you get time to implement it in Quarkus, and in case some more comments will follow here, thanks for your help, @michalvavrik

@cescoffier
Copy link
Member

Could you rephrase the PR to highlight that it's a javadoc enhancement.

@michalvavrik michalvavrik changed the title Autodetect PermissionsAllowed#params based on parameter names match between Permission constructor and secured method Detect permission constructor parameters based on formal method names match with a method secured by the @PermissionsAllowed annotation Sep 23, 2024
@michalvavrik
Copy link
Member Author

michalvavrik commented Sep 23, 2024

Could you rephrase the PR to highlight that it's a javadoc enhancement.

Rewrote the PR title and description. If additional adjustments are needed, please let me know.

@cescoffier cescoffier merged commit 8e9154b into quarkusio:main Sep 23, 2024
3 checks passed
@michalvavrik michalvavrik deleted the feature/change-default-permissions-allowed-behavior branch September 30, 2024 13:58
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.

4 participants