Class HttpRequestClientInfoAdapter

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

public class HttpRequestClientInfoAdapter extends Object implements IClientInfoPort
IClientInfoPort implementation that resolves the caller purely from the current HTTP request's client IP address, via RequestClientIpResolver.

Resolving a caller's IP address has nothing to do with Spring Security. This adapter exists for applications that carry Spring Web but not Spring Security at all — for example, an internal microservice behind a gateway that already authenticates the caller upstream. Such a service still benefits from knowing which address a call came from, even though it never performs authentication itself, so it should not be forced to fall back to "unknown" just because Spring Security is absent from its classpath.

LoggedAutoConfiguration only activates this adapter when SpringSecurityClientInfoAdapter itself is not active (Spring Security missing), so an application with Spring Security still gets the richer, authentication-aware resolution.

  • Constructor Details

    • HttpRequestClientInfoAdapter

      public HttpRequestClientInfoAdapter(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
    • resolveCallerIp

      public String resolveCallerIp()
      Description copied from interface: IClientInfoPort
      Resolves the IP address of the caller that triggered the current invocation, independent of whatever IClientInfoPort.resolveCallerIdentity() itself resolves to.

      Unlike IClientInfoPort.resolveCallerIdentity(), which resolves a single identity from an either/or chain of tiers (authenticated principal, then IP, then a placeholder), this method exists so that a caller's IP can be recorded alongside an authenticated identity rather than only as a fallback used when no identity is available — valuable for security-sensitive operations (login, password reset, admin actions) where the IP remains useful for audit and rate-limiting purposes even when the call also resolves to an authenticated user.

      This is a default method, not an abstract one, so that adding it does not break existing implementations of this interface compiled against an earlier version of this library. The default returns null, meaning "this adapter does not support resolving an IP independent of caller identity" — consistent with this library's convention of using null for "not available" on structured fields, rather than a placeholder string.

      Specified by:
      resolveCallerIp in interface IClientInfoPort
      Returns:
      the caller's IP address, or null if it cannot be resolved (for example, no HTTP request is available on the current thread, or this adapter does not implement IP resolution)