Serialization of Authentication object into Redis session no longer works
See original GitHub issueExpected Behavior
Serialization of attributes into Redis session works as before.
Actual Behaviour
It somehow does not populate attributes into Authentication
object:
Unexpected error occurred: null
java.lang.NullPointerException: null
at java.util.HashMap.putMapEntries(HashMap.java:497)
at java.util.HashMap.<init>(HashMap.java:486)
at io.micronaut.security.authentication.ClientAuthentication.getAttributes(ClientAuthentication.java:64)
at xxx.server.utils.extensions.AuthenticationExtensionsKt.getAccountId(AuthenticationExtensions.kt:11)
at xxx.server.controllers.api.SessionController.getSession(SessionController.kt:36)
at xxx.server.controllers.api.$SessionController$Definition$Intercepted.$$access$$getSession(Unknown Source)
at xxx.server.controllers.api.$SessionController$Definition$Exec.dispatch(Unknown Source)
at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:128)
at io.micronaut.transaction.interceptor.TransactionalInterceptor.intercept(TransactionalInterceptor.java:196)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
at xxx.server.controllers.api.$SessionController$Definition$Intercepted.getSession(Unknown Source)
at xxx.server.controllers.api.$SessionController$Definition$Exec.dispatch(Unknown Source)
at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378)
at io.micronaut.context.DefaultBeanContext$4.invoke(DefaultBeanContext.java:583)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:303)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:111)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:103)
at io.micronaut.http.server.RouteExecutor.lambda$executeRoute$14(RouteExecutor.java:659)
at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.run(FluxSubscribeOn.java:194)
at io.micronaut.reactive.reactor.instrument.ReactorInstrumentation.lambda$null$0(ReactorInstrumentation.java:62)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
at io.micronaut.scheduling.instrument.InvocationInstrumenterWrappedCallable.call(InvocationInstrumenterWrappedCallable.java:53)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.lang.Thread.run(Thread.java:829)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)
Steps To Reproduce
Micronaut team has a sample application in micronaut-graal-tests
, which can be simply modified to reproduci this behaviour: https://github.com/micronaut-graal-tests/micronaut-security-session-graal
Append to application.yml
:
---
redis:
url: redis://127.0.0.1:6379
micronaut:
session:
http:
redis:
enabled: true
Add dependency to build.gradle
:
implementation("io.micronaut.redis:micronaut-redis-lettuce")
You need to have Redis running on specified url for this test.
Environment Information
GraalVM 22.1
Example Application
No response
Version
3.5.1
Issue Analytics
- State:
- Created a year ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Spring Boot with Session/Redis Serialization Error with Bad ...
The Java object to be cached must implement the serializable interface, because spring will serialize the object and store it in redis.
Read more >Unreadable session after serialization · Issue #361 - GitHub
I use Spring session with a Redis repository. ... It works fine but I the session attributes that are storred in Redis are...
Read more >Handling Deserialization errors in Spring Redis Sessions
This blog post discusses a method to work around this issue. ... This happens because the serialized object in the session and the...
Read more >Express session middleware
Forces a session that is “uninitialized” to be saved to the store. A session is uninitialized when it is new but not modified....
Read more >Token cache serialization (MSAL.NET) - Microsoft Entra
A shared cache is faster because it's not serialized. ... Use an in-memory token cache in apps that participate in machine-to-machine auth ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
the regression happened because prior to 3.1.x the request context was not available in the lettuce reactive handler. My guess is that this changed in one of @dstepanov’s improvements to reactive context propagation. I’m not going to bother tracking down the specific change, since it’s certainly better for the request context. I’ll work on a fix on the security side instead.
ok i can see that it works with 3.0.x, i will look at why tomorrow.