Class SpringSecurityClientInfoAdapter
java.lang.Object
com.fayupable.logged.spring.security.SpringSecurityClientInfoAdapter
- All Implemented Interfaces:
IClientInfoPort
IClientInfoPort implementation that resolves the caller as the
authenticated Spring Security principal when one is present, falling back
to RequestClientIpResolver otherwise.
Only the principal's name is captured, never any other detail carried
by the Authentication (authorities, credentials, session
attributes), consistent with the rest of this library's approach of
capturing coarse identifiers rather than arbitrary request or security
data.
This adapter is only active when both Spring Security and Spring Web
are present, since it needs Authentication. Services that do not
carry Spring Security at all (for example internal microservices reached
only through a gateway that already authenticates the caller) still get
IP-based identity through HttpRequestClientInfoAdapter instead;
see that class for details, since IP resolution itself has nothing to do
with whether Spring Security is present.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionResolves an identifier describing who triggered the current invocation.Resolves the caller's IP address independent ofresolveCallerIdentity()'s outcome, unlike that method's authenticated-principal-first fallback chain.
-
Constructor Details
-
SpringSecurityClientInfoAdapter
public SpringSecurityClientInfoAdapter(boolean trustForwardedHeaders)
-
-
Method Details
-
resolveCallerIdentity
Description copied from interface:IClientInfoPortResolves an identifier describing who triggered the current invocation.- Specified by:
resolveCallerIdentityin interfaceIClientInfoPort- Returns:
- a caller identity such as
"user:42"or"ip:203.0.113.10", or an implementation-defined placeholder such as"unknown"if no identity can be resolved
-
resolveCallerIp
Resolves the caller's IP address independent ofresolveCallerIdentity()'s outcome, unlike that method's authenticated-principal-first fallback chain. This has no dependency onSecurityContextHolderstate, so it resolves the same way whether or not the current invocation also resolves to an authenticated user.- Specified by:
resolveCallerIpin interfaceIClientInfoPort- Returns:
- the caller's IP address, or
nullif it cannot be resolved (for example, no HTTP request is available on the current thread, or this adapter does not implement IP resolution)
-