Skip to content

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Oct 31, 2019

We need security annotations to result in the creation of an interceptor
which is not possible when a method is final.
The default behavior of Arc to simply warn about the final method is not
good enough for security annotations because it could cause methods
that should have been secure to not be by a simple oversight.

Fixes: #5051

A note on the implementation: I went for a simple approach here instead of introducing some more build items and tying deeper into Arc since IMHO that would require us to handle other Arc warnings in a uniform manner instead of having a specific implementation for interceptors

We need security annotations to result in the creation of an interceptor
which is not possible when a method is final.
The default behavior of Arc to simply warn about the final method is not
good enough for security annotations because it could cause methods
that should have been secure to not be by a simple oversight.

Fixes: quarkusio#5051
@geoand geoand requested a review from mkouba October 31, 2019 16:41
@geoand geoand added this to the 0.28.0 milestone Oct 31, 2019
@geoand geoand changed the title Ensure that Security annotation are always places on non-final methods Ensure that Security annotation are always placed on non-final methods Oct 31, 2019
Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

It looks good to me but I'll let Stuart have the final say on this matter.

@geoand geoand requested a review from stuartwdouglas October 31, 2019 17:17
if (bean.isClassBean()) {
// Ensure that all security annotations are placed on non final methods
// this is done because Arc only warns about final methods not being interceptable
for (MethodInfo method : bean.getTarget().get().asClass().methods()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Inherited methods are not processed. Also iterating over all methods of all beans could be quite time-consuming (for large deployments). I'd rather move the validation to io.quarkus.arc.processor.BeanInfo.initInterceptedMethods() or somewhere "nearby".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pondered that option as well but went with the current solution because it seemed cleaner since it wouldn't involve baking specific security annotations inside the general Arc code.
I can certainly move things inside initInterceptedMethods but I assume that the security annotations will have to be hard coded - or at best have some kind of build item that is dedicated to this case and will propagate the information down the Arc layers.
What would be your preference?

Copy link
Member

Choose a reason for hiding this comment

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

It might be a stupid question but why don't we throw an error for any interceptor binding annotation on final methods? I mean it won't work and could have very bad consequences. Security is one of the occurrences of this problem but there might be other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine with me TBH. I just didn't do it because it was mentioned in the issue that we might not want that as a default.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should modify BeanDeploymentValidator#skipValidation() to handle similar use cases...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Really I think that automatically removing the final modifier is probably the most user friendly approach, especially for Kotlin applications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stuartwdouglas are you thinking for this interceptor use case or for all types of issues we might encounter with Kotlin?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was just thinking for the interceptor use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll do it and we can see what @mkouba thinks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here you go: #5104

@geoand
Copy link
Contributor Author

geoand commented Nov 1, 2019

I am going to close this one as #5104 is the more accepted solution

@geoand geoand closed this Nov 1, 2019
@geoand geoand removed this from the 0.28.0 milestone Nov 1, 2019
@geoand geoand deleted the #5051 branch November 1, 2019 11:04
@gsmet gsmet added this to the 0.28.0 milestone Nov 3, 2019
@gsmet gsmet added triage/out-of-date This issue/PR is no longer valid or relevant triage/invalid This doesn't seem right and removed triage/out-of-date This issue/PR is no longer valid or relevant labels Nov 3, 2019
@gsmet gsmet removed this from the 0.28.0 milestone Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage/invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quarkus 0.27 - JWT role validation does not work

4 participants