Class SpringSecurityClientInfoAdapter

java.lang.Object
com.fayupable.logged.spring.security.SpringSecurityClientInfoAdapter
All Implemented Interfaces:
IClientInfoPort

public class SpringSecurityClientInfoAdapter extends Object implements 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 Details

    • SpringSecurityClientInfoAdapter

      public SpringSecurityClientInfoAdapter(boolean trustForwardedHeaders)
  • Method Details

    • resolveCallerIdentity

      public String resolveCallerIdentity()
      Description copied from interface: IClientInfoPort
      Resolves an identifier describing who triggered the current invocation.
      Specified by:
      resolveCallerIdentity in interface IClientInfoPort
      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