Class ExecutionContextMapper

java.lang.Object
com.smeup.kokos.sdk.util.mapper.ExecutionContextMapper

public final class ExecutionContextMapper extends Object
Author:
mattia.bonardi This mapper create the ExecutionContext instance from ExecutionContextDTO
  • Field Details

    • AUTH_TOKEN_KEY

      public static final String AUTH_TOKEN_KEY
      Cookie name used to carry the auth token when it's not sent as a bearer header.
      See Also:
    • TRACKED_HEADERS

      public static final String[] TRACKED_HEADERS
      Auth and V3 headers copied from an incoming request into a plain map. Does not include AUTH_TOKEN_KEY (cookie) or transport-specific keys.
  • Method Details

    • fromDTO

      public static ExecutionContext fromDTO(ExecutionContextDTO dto)
    • fromDTO

      public static ExecutionContext fromDTO(PropertiesExecutionContextDTO dto)
    • toDTO

      public static ExecutionContextDTO toDTO(ExecutionContext context)
    • toPropertiesDTO

      public static PropertiesExecutionContextDTO toPropertiesDTO(ExecutionContext context)
    • fromHeaders

      public static ExecutionContext fromHeaders(Map<String,String> headers) throws Exception
      Builds a partial ExecutionContext from a plain header map (user/app/version only). Resolves identity from V3 auth headers when present, otherwise from the JWT bearer token.

      Internal: intended for ExecutionContextManager only. External callers must use ExecutionContextManager.createContext(Map, IServiceCaller).

      Parameters:
      headers - the request headers (and, optionally, the "AuthToken" cookie value)
      Returns:
      the resolved (not yet hydrated) execution context
      Throws:
      Exception - if no usable auth token/headers are found, or the app is unknown
    • toHeaders

      public static Map<String,String> toHeaders(KokosUser user)
      Encodes a KokosUser into the V3 auth header values, ready to be set on an outgoing (proxied) request. The auth-properties entry is omitted when the user has no additional properties.
    • toHeaders

      public static Map<String,String> toHeaders(KokosUser user, String version)
      Encodes a KokosUser into the V3 auth header values and, when version is non-blank, the API version header (HeaderManager.V3.VERSION). Ready to be set on an outgoing (proxied) request.
    • extractAuthToken

      public static String extractAuthToken(Map<String,String> headers)
      Extracts the auth token from the given headers: either the "AuthToken" cookie value or the Authorization header (stripping the "Bearer " prefix if present).
      Returns:
      the token, or null if absent
    • extractAppName

      public static String extractAppName(Map<String,String> headers) throws Exception
      Extracts the app name from the given headers, either from the V3 auth header or from the JWT bearer token, without looking up the corresponding App configuration. Useful for callers (e.g. legacy/standalone connectors) that only need the raw app name.
      Throws:
      Exception - if no app name can be resolved
    • extractHeadersFromRequest

      public static Map<String,String> extractHeadersFromRequest(org.eclipse.jetty.server.Request request)
      Extracts TRACKED_HEADERS and the "AuthToken" cookie from a Jetty request.