Shared library for the ordered-system microservices — the small set of things that would otherwise be copy-pasted into every service's security and common packages.
Not a Spring Boot application: no spring-boot-maven-plugin, packaged as a plain .jar that order-service, product-service, user-service, and engagement-service each add as a Maven dependency. It isn't published to Maven Central — every consumer builds it locally first (see below).
<groupId>pl.dybcio</groupId>
<artifactId>ordered-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>| Class | Purpose |
|---|---|
JwtClaimsAuthenticationFilter |
Reads the JWT already verified upstream by the gateway and populates Spring Security's context from its custom claims (userId, roles) — services trust the gateway's signature check and just parse claims, they don't re-verify the token. |
AuthenticatedUser |
The Principal implementation exposed to controllers (@AuthenticationPrincipal AuthenticatedUser user) — wraps userId and granted roles. |
ProblemDetailAuthenticationEntryPoint |
Turns unauthenticated requests into a proper RFC 7807 ProblemDetail 401 response instead of Spring Security's default. |
CommonExceptionHandler |
Base @RestControllerAdvice with the exception → ProblemDetail mappings shared across services (validation errors, not-found, etc.), extended per-service for domain-specific exceptions. |
PageResponse |
A consistent pagination envelope so list endpoints look the same across every service's API. |
Java 21 · Spring Boot 4.1.0 (as provided-scope dependencies, not pulled in transitively — each consuming service supplies its own Spring Boot version) · JJWT 0.12.6
Local development — build once, every service on the machine picks it up from ~/.m2:
git clone https://github.com/ordered-system/ordered-commons.git
cd ordered-commons
make install # mvn clean install, skips testsThen in the consuming service, just run ./mvnw spring-boot:run as normal — Maven resolves ordered-commons from the local repo.
Docker builds don't have access to ~/.m2, so each service's Dockerfile compiles ordered-commons from source in an earlier build stage using a named additional build context:
FROM eclipse-temurin:21-jdk-alpine AS commons-build
WORKDIR /commons
COPY --from=commons . .
RUN apk add --no-cache maven && mvn -B -q clean install -DskipTestswhich ordered-infra's docker-compose.prod.yml wires up per service:
order-service:
build:
context: ../ordered-order-service
additional_contexts:
commons: ../ordered-commonsi.e. ordered-commons must be cloned as a sibling directory next to whichever service you're building, at the same folder depth ordered-infra expects (see its README for the exact layout).
CI does the same thing without Docker — every service's GitHub Actions workflow checks out ordered-system/ordered-commons@main into a subfolder and runs mvn install -DskipTests on it before testing the service itself.
make testEach class has a matching unit test under src/test.
Part of the ordered-system organization. Consumed by ordered-order-service, ordered-product-service, ordered-user-service, and ordered-engagement-service.
MIT — see LICENSE.