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.
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
-
Method Details
-
resolve
Resolves the identifier for an authenticated, non-anonymous principal.- Parameters:
authentication- the current authentication, nevernull- Returns:
- the caller identifier without any prefix, or
nullif none can be resolved
-