Interface CallerIdentityResolver

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 CallerIdentityResolver
Application-provided strategy that turns an authenticated principal into the identifier written as the caller of a @Logged invocation, used when the caller mode is CallerMode.CUSTOM.

Typical use is to log an internal user id instead of a login name that is personal data (such as an e-mail address):


 @Bean
 CallerIdentityResolver callerIdentityResolver() {
     return authentication -> authentication.getPrincipal() instanceof AppUser user
             ? String.valueOf(user.getId())
             : null;
 }
 

The returned value is prefixed with "user:" by SpringSecurityClientInfoAdapter. Returning null or a blank string means "no identity for this principal", in which case the adapter falls back to the caller's IP address exactly as it does for an unauthenticated caller.

  • Method Summary

    Modifier and Type
    Method
    Description
    resolve(org.springframework.security.core.Authentication authentication)
    Resolves the identifier for an authenticated, non-anonymous principal.
  • Method Details

    • resolve

      String resolve(org.springframework.security.core.Authentication authentication)
      Resolves the identifier for an authenticated, non-anonymous principal.
      Parameters:
      authentication - the current authentication, never null
      Returns:
      the caller identifier without any prefix, or null if none can be resolved