Closed allertonm closed 1 year ago
/cc @evanchooly (kotlin), @geoand (kotlin), @sberyozkin (security)
@allertonm As far as I understand you can't access it outside of the asserter, does val principal2 = securityIdentity.principal
work ?
Otherwise, since it is run on the Vert.x context, non-blocking, the advice from https://quarkus.io/guides/security-proactive-authentication-concept should help, io.quarkus.security.identity.CurrentIdentityAssociation
and Uni<SecurityIdentity>
should be used.
CC @michalvavrik
Neither case works, for what it's worth.
Thanks for the reference, it looks like we were just lucky not to hit this previously.
@allertonm you can't block on IO thread, so as @sberyozkin said when running on IO thread you will need to use io.quarkus.security.identity.CurrentIdentityAssociation#getDeferredIdentity
.
@michalvavrik Understood. I was aware of not being able to block, but the surprise was that access to the SecurityIdentity was blocking. In practice this only broke in tests, which previously were not running on Vertx contexts but have needed to change to match the Quarkus 3 Panache behaviour.
Closing as resolved due to this being documented behaviour.
Describe the bug
If a test is annotated with @QuarkusTest, @TestSecurity & @RunOnVertxContext, and injected with SecurityIdentity, calling getPrincipal on the injected identity will fail due to attempting to block in a Vertx context.
Expected behavior
SecurityIdentity.getPrincipal returns a principal
Actual behavior
SecurityIdentity.getPrincipal throws an exception
How to Reproduce?
Run the following test (this test can also be found as part of this project https://github.com/allertonm/quarkus-coroutine-interceptor-example/blob/main/src/test/kotlin/com/example/FooTest.kt)
Running this test will throw the following exception
Output of
uname -a
orver
Darwin M-L10KJGH6 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64 x86_64
Output of
java -version
openjdk version "17.0.7" 2023-04-18 LTS OpenJDK Runtime Environment Corretto-17.0.7.7.1 (build 17.0.7+7-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.7.7.1 (build 17.0.7+7-LTS, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
3.1.1.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response