Coder Social home page Coder Social logo

anonymous `SecurityIdentity` is not available inside background vertx worker, says "RequestScoped context was not active" about quarkus HOT 9 CLOSED

Felk avatar Felk commented on July 18, 2024
anonymous `SecurityIdentity` is not available inside background vertx worker, says "RequestScoped context was not active"

from quarkus.

Comments (9)

mkouba avatar mkouba commented on July 18, 2024 2

Judging from the changelog of 3.7.2, this might be a consequence of #38605

Looking at the pull request's description, my use-case was never legal and should have never worked to begin with. Would you agree @mkouba ?

@Felk That's correct. It only "worked" by coincidence.

from quarkus.

sberyozkin avatar sberyozkin commented on July 18, 2024 1

Also CC @manovotn @michalvavrik

from quarkus.

Felk avatar Felk commented on July 18, 2024

Here's a reproducer project:
inject-securityidentity-regression.zip

It's basically just https://code.quarkus.io/?a=inject-securityidentity-regression&j=21&e=oidc&e=scheduler with the above code added.

from quarkus.

quarkus-bot avatar quarkus-bot commented on July 18, 2024

/cc @sberyozkin (security)

from quarkus.

Felk avatar Felk commented on July 18, 2024

Judging from the changelog of 3.7.2, this might be a consequence of #38605

Looking at the pull request's description, my use-case was never legal and should have never worked to begin with. Would you agree @mkouba ?

My solution would then be to catch ContextNotActiveException and treat that as an anonymous user.

from quarkus.

michalvavrik avatar michalvavrik commented on July 18, 2024

Hey, I'll let answer Martins on CDI request being active, but I have a comment on the use case if you don't mind.

I checked your reproducer and the identity is always going to be anonymous (even with active CDI request context), won't it? If so, I'm not sure why to bother, just use QuarkusSecurityIdentity.builder().setAnonymous(true).build(). I appreciate your real use case might be much more complex, but I can't imagine where the identity is coming from unless you set it yourself in the SecurityIdentityAssociation, in which case you need to do it inside same CDI request context in which you set it. Doesn't it basically means you need to do it inside scope of the same method where you request the identity (if you also want to be able to deactivate the context)?

I ask because if your real use case has non-anonymous identity that is accessible without the ContextNotActiveException, it should mean you had activated CDI request context in that scenario. So you can just activate it here as well.

from quarkus.

Felk avatar Felk commented on July 18, 2024

My real-world usecase is that I have a @PreUpdate listener on JPA entities that sets a "updated_by"-kind of field on every update. That listener exists in all situations, including background workers, but also in the context of actual HTTP requests that do have a security context automatically. I didn't model any of that in the reproducer, so sorry if the reproducer looks a bit silly.

from quarkus.

michalvavrik avatar michalvavrik commented on July 18, 2024

My real-world usecase is that I have a @PreUpdate listener on JPA entities that sets a "updated_by"-kind of field on every update. That listener exists in all situations, including background workers, but also in the context of actual HTTP requests that do have a security context automatically.

Cool, that's legit scenario.

I didn't model any of that in the reproducer, so sorry if the reproducer looks a bit silly.

I just tried to understand, this is okay. Thank you

from quarkus.

Felk avatar Felk commented on July 18, 2024

Alright, thanks for confirming! I'll close this issue

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.