Interface AlhUserIdResolver

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AlhUserIdResolver
Strategy for extracting the current user id to populate AlhMdcKeys.USER_ID.

Provide a @Bean AlhUserIdResolver to override the default behavior. The default implementation returns "anonymous" for every request — apps that use Spring Security typically want to plug in something like:


 @Bean
 AlhUserIdResolver alhUserIdResolver() {
     return req -> {
         var auth = SecurityContextHolder.getContext().getAuthentication();
         if (auth != null && auth.getPrincipal() instanceof Long userId) {
             return String.valueOf(userId);
         }
         return "anonymous";
     };
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    resolve(jakarta.servlet.http.HttpServletRequest request)
     
  • Method Details

    • resolve

      String resolve(jakarta.servlet.http.HttpServletRequest request)