1

I am using Spring Webflux with Kotlin Coroutine and Spring AOP. I have simple Advice which is like this.

@Around("@annotation(LogAccess)")
public Object logErrorAccess(ProceedingJoinPoint joinPoint) throws Throwable {

    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    Method method = methodSignature.getMethod();
    LogAccess logAccess = method.getAnnotation(LogAccess.class);

    try {
        var result = joinPoint.proceed();
        // Get the current user and user id and log
        return result;
    } catch (Exception e) {
        // Get the current user and user id and log
        throw e;
    }
}

I tried to use this.

ReactiveSecurityContextHolder.getContext().map(ct -> ct.getAuthentication().getPrincipal());

But I am getting null. I am using JWT for Auth, However in my controller I can access that information like this.

@GetMapping("/profile")
suspend fun profile(authentication: Authentication): Response

Is there any way to get this info in Advice somehow.

nicholasnet
  • 2,117
  • 2
  • 24
  • 46
  • You can use reactor context (https://projectreactor.io/docs/core/release/reference/#context) Meaning the context you want to access is attached to your Mono or Flux. I am on the same pb right now. Maybe by accessing the Mono or Flux in parameter ? – terrasson marc Oct 09 '20 at 15:17
  • ReactiveSecurityContextHolder use the Context API behind. Can you provide how you are using ReactiveSecurityContextHolder in the advice ? – JEY Oct 21 '20 at 11:46
  • do you have an answer for this? – Victor Mikhailov Mar 07 '22 at 09:30

0 Answers0