Skip to content

Core Library

GitHub Repository https://github.com/AirCommerce/library-core
Maven Coordinates one.aircommerce.library:core-library (Inherited automatically via one.aircommerce.pom:boot-base-super-pom)

The Core Library (library-core) is the foundational production Java stack inherited at compile scope by every AirCommerce Spring Boot microservice via boot-base-super-pom (ADR 0005). It centralizes web, OAuth2 security, OpenFeign client propagation, OpenTelemetry observability, validation aspects, and error handling so individual microservices never duplicate infrastructure boilerplate.

Exported Capabilities & Public API Catalog

Section titled “Exported Capabilities & Public API Catalog”

1. Auto-Configuration & Security (one.aircommerce.library.core.config)

Section titled “1. Auto-Configuration & Security (one.aircommerce.library.core.config)”

Registered automatically via META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (CoreAutoConfiguration):

  • SecurityConfig:
    • Configures the Spring Security SecurityFilterChain as an OAuth2 Resource Server using KeycloakJwtAuthenticationConverter (bound to coreProperties.getRoleAudiences()).
    • Permits Swagger/OpenAPI (/v3/api-docs/**, /swagger-ui/**) and Actuator (/actuator/**) endpoints while requiring authentication on all business endpoints.
    • Registers TokenExchangeOAuth2AuthorizedClientProvider (OAuth2AuthorizedClientManager) to perform OAuth2 token exchange when propagating caller JWT credentials to downstream microservices.
  • FeignConfiguration & FeignTracingConfig:
    • Configures OpenFeign clients with OAuth2 bearer token propagation, correlation header forwarding, and CustomFeignLogger.
  • OpenTelemetryConfiguration & TraceIdFilter:
    • Configures OpenTelemetry Spring Boot instrumentation, Logback trace correlation (logback-spring.xml), and HTTP request/response trace ID headers (RequestLoggingFilterConfig).
  • OpenAPISecurityConfig:
    • Registers Bearer JWT security schemes for SpringDoc OpenAPI generation.

2. Request-Scoped Security Context (one.aircommerce.library.core.security)

Section titled “2. Request-Scoped Security Context (one.aircommerce.library.core.security)”

Standardized in ADR 0009 to provide structured, strongly-typed access to caller JWT claims originating from Keycloak:

  • AirCommerceSecurityContext:
    • @RequestScope bean holding caller identity and partitioned scope attributes parsed from Keycloak’s nested claim mapping (attributes.<scope>.<attribute>).
    • Downstream controllers and services inject this bean directly rather than parsing raw JWT payload maps.
  • ScopeAttributes:
    • Represents an isolated attribute namespace (such as Point of Sale claims under pos):
      • getAttribute(name): Retrieves mandatory claim string; throws MissingRequiredAttributeException if absent.
      • getOptionalAttribute(name): Returns Optional<String> for optional claims.
      • hasAttribute(name): Boolean check for attribute presence.
  • AirCommerceSecurityContextHolder:
    • ThreadLocal bridge synchronizing parsed claims from the Spring Security filter chain into the application context.
  • Background Task Execution:
    • System-Triggered Tasks (@EventListener, @Scheduled, RabbitMQ listeners): Must be annotated with @RunAsSystem to initialize a system context, retrieved directly via AirCommerceSecurityContextHolder.get().
    • Asynchronous User Tasks (@Async): Must accept ScopeAttributes explicitly as a method argument from the invoking HTTP thread to avoid ScopeNotActiveException.

3. Security & Validation Aspects (one.aircommerce.library.core.aspect)

Section titled “3. Security & Validation Aspects (one.aircommerce.library.core.aspect)”
Annotation / Aspect Package Purpose
@Authorized (AuthorizationAspect) one.aircommerce.library.core.aspect Enforces role/authority checks on controller or service methods.
@RunAsSystem (RunAsSystemAspect) one.aircommerce.library.core.aspect Executes internal background/startup calls (such as util-configuration bootstrap) under a system security context.
@FieldContained (FieldContainedValidator) one.aircommerce.library.core.aspect Jakarta Bean Validation constraint verifying field values against allowed sets.

4. Standard Response Envelope (one.aircommerce.library.core.model)

Section titled “4. Standard Response Envelope (one.aircommerce.library.core.model)”
  • BaseResponse<T>: Standard JSON envelope for internal REST APIs containing payload data, ResponseCode, List<Error>, and List<Warning>.
  • Error & Warning: Structured diagnostic items with key and localized/formatted message.
  • ResponseCode: Standardized outcome enum (SUCCESS, WARNING, ERROR, etc.).

5. Exception Hierarchy & Global Handling (one.aircommerce.library.core.exception)

Section titled “5. Exception Hierarchy & Global Handling (one.aircommerce.library.core.exception)”

GlobalExceptionHandler (@RestControllerAdvice) intercepts all ServiceException subclasses and Jakarta validation errors, translating them into standardized HTTP statuses and BaseResponse error payloads:

Exception Class (one.aircommerce.library.core.exception.concretes) Base Class HTTP Semantics
ValidationException ServiceException 400 Bad Request — Schema or field validation failure
InvalidRequestException ServiceException 400 Bad Request — Malformed request payload or parameters
AuthenticationFailedException ServiceException 401 Unauthorized — Missing or invalid JWT / credentials
SubjectTokenResolutionException ServiceException 401 Unauthorized — Token exchange principal resolution failure
AuthorizationFailedException / ForbiddenException ServiceException 403 Forbidden — Insufficient permissions
MissingRequiredAttributeException ServiceException 403 Forbidden — Missing mandatory JWT scope or attribute (ResponseCode.AUTHORIZATION_FAILED)
NotFoundException ServiceException 404 Not Found — Target resource or booking not found
ConflictException / AlreadyExistException ServiceException 409 Conflict — State conflict or duplicate resource
BusinessRuleException ServiceException 422 Unprocessable Entity — Domain/orchestration business rule violation
ExternalServerErrorException ServiceException 502 Bad Gateway — Downstream PSS (iFlyRes) or external system fault
InternalServerErrorException ServiceException 500 Internal Server Error — Unhandled platform failure
Showing 1 of 1 architecture decisions

None