|
| 1 | +# security-jwt-extension |
| 2 | + |
| 3 | +  |
| 4 | + |
| 5 | +JWT authentication and authorization utilities for Spring Security. This module extends the Spring Security authentication model with JWT-aware tokens and filters, for both the servlet (Web) and reactive (WebFlux) stacks. |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [1. Project Overview](#1-project-overview) |
| 10 | +- [2. Features & Status](#2-features--status) |
| 11 | +- [3. Requirements & Compatibility](#3-requirements--compatibility) |
| 12 | +- [4. Architecture & Modules](#4-architecture--modules) |
| 13 | +- [5. Installation](#5-installation) |
| 14 | +- [6. Quick Start](#6-quick-start) |
| 15 | +- [7. Configuration](#7-configuration) |
| 16 | +- [8. Core Usage / API](#8-core-usage--api) |
| 17 | +- [9. Testing & Build](#9-testing--build) |
| 18 | +- [10. Versioning & Branches](#10-versioning--branches) |
| 19 | +- [11. Contributing & License](#11-contributing--license) |
| 20 | + |
| 21 | +## 1. Project Overview |
| 22 | + |
| 23 | +**What it is** |
| 24 | + |
| 25 | +`security-jwt-extension` provides JWT-oriented building blocks for Spring Security applications: authentication tokens carrying a JWT principal/credentials plus optional request metadata (signature, longitude, latitude), a reactive JWT authentication web filter, a servlet-side authorization success handler, and a token-refresh REST endpoint placeholder. |
| 26 | + |
| 27 | +**What it is not** |
| 28 | + |
| 29 | +- It is not a JWT library — token creation/parsing is delegated to your application or the underlying Spring Security infrastructure. |
| 30 | +- It is not a complete Spring Security starter: no auto-configuration is shipped in this module; wire the components into your own `SecurityFilterChain` / `SecurityWebFilterChain`. |
| 31 | + |
| 32 | +**Typical scenarios** |
| 33 | + |
| 34 | +| Scenario | Description | |
| 35 | +| :--- | :--- | |
| 36 | +| Servlet + JWT authorization | Attach `JwtAuthorizationSuccessHandler` to your authorization flow to build the response after a successful JWT check. | |
| 37 | +| WebFlux + JWT authentication | Use `JwtAuthenticationWebFilter` with a `ReactiveAuthenticationManager` that validates JWT credentials. | |
| 38 | +| Token refresh endpoint (WIP) | `RefreshTokenEndpoint` marks the intended location of a refresh-token REST endpoint. | |
| 39 | + |
| 40 | +## 2. Features & Status |
| 41 | + |
| 42 | +| Capability | Status | Notes | |
| 43 | +| :--- | :--- | :--- | |
| 44 | +| `JwtAuthenticationToken` | Available | Servlet authentication token with principal/credentials, `sign`, `longitude`, `latitude` metadata. | |
| 45 | +| `JwtAuthorizationToken` | Available | Authorization-phase token with the same metadata fields. | |
| 46 | +| `JwtAuthenticationWebFilter` | Available | WebFlux filter over `ReactiveAuthenticationManager`. | |
| 47 | +| `JwtAuthorizationSuccessHandler` | Available | Servlet `AuthenticationSuccessHandler` for authorization success responses. | |
| 48 | +| `RefreshTokenEndpoint` | WIP | `@RestController` placeholder; no endpoints implemented yet. | |
| 49 | + |
| 50 | +> Status is reported as of `1.0.x.20260630-SNAPSHOT` on the `feature/1.0.x` branch. |
| 51 | +
|
| 52 | +## 3. Requirements & Compatibility |
| 53 | + |
| 54 | +| Item | Version | |
| 55 | +| :--- | :--- | |
| 56 | +| JDK | 8+ | |
| 57 | +| Maven | 3.0+ (Maven Wrapper 3.5.0 bundled) | |
| 58 | +| Spring Security | 5.6.0 (`spring-security-core`, `spring-security-web`) | |
| 59 | +| Spring Framework | 5.3.39 (`spring-web`, `spring-webflux`) | |
| 60 | +| Jackson | 2.17.2 (`jackson-databind`) | |
| 61 | +| easy4j dependency | `io.github.easy4j:spring-security-extension` | |
| 62 | + |
| 63 | +**Version lines** |
| 64 | + |
| 65 | +| Branch | JDK baseline | Version pattern | |
| 66 | +| :--- | :--- | :--- | |
| 67 | +| `feature/1.0.x` | JDK 8 | `1.0.x.*` | |
| 68 | +| `feature/2.0.x` | JDK 17 | `2.0.x.*` | |
| 69 | +| `feature/3.0.x` | JDK 21 | `3.0.x.*` | |
| 70 | + |
| 71 | +## 4. Architecture & Modules |
| 72 | + |
| 73 | +```text |
| 74 | + Servlet / WebFlux client (Bearer JWT) |
| 75 | + | |
| 76 | + +--(servlet)--> JwtAuthorizationSuccessHandler |
| 77 | + | |
| 78 | + +--(webflux)--> JwtAuthenticationWebFilter |
| 79 | + | ReactiveAuthenticationManager |
| 80 | + v |
| 81 | + JwtAuthenticationToken / JwtAuthorizationToken |
| 82 | + | (sign, longitude, latitude) |
| 83 | + v |
| 84 | + Spring Security (core) |
| 85 | + | |
| 86 | + +-- RefreshTokenEndpoint (WIP, REST) |
| 87 | +``` |
| 88 | + |
| 89 | +This is a **single-module** project (packaging `jar`): |
| 90 | + |
| 91 | +| Module / artifact | Role | |
| 92 | +| :--- | :--- | |
| 93 | +| `security-jwt-extension` | JWT tokens, filters and handlers for Spring Security (servlet + WebFlux). | |
| 94 | + |
| 95 | +## 5. Installation |
| 96 | + |
| 97 | +The artifact is not yet published to Maven Central. Resolve it from the project's configured artifact repository (Aliyun Packages) or install it locally from source; the snapshot version currently used on the `feature/1.0.x` branch is `1.0.x.20260630-SNAPSHOT`. |
| 98 | + |
| 99 | +**Maven** |
| 100 | + |
| 101 | +```xml |
| 102 | +<dependency> |
| 103 | + <groupId>io.github.easy4j</groupId> |
| 104 | + <artifactId>security-jwt-extension</artifactId> |
| 105 | + <version>1.0.x.20260630-SNAPSHOT</version> |
| 106 | +</dependency> |
| 107 | +``` |
| 108 | + |
| 109 | +**Gradle** |
| 110 | + |
| 111 | +```groovy |
| 112 | +implementation 'io.github.easy4j:security-jwt-extension:1.0.x.20260630-SNAPSHOT' |
| 113 | +``` |
| 114 | + |
| 115 | +## 6. Quick Start |
| 116 | + |
| 117 | +Build a JWT authentication token and let the reactive filter hand it to your `ReactiveAuthenticationManager`: |
| 118 | + |
| 119 | +```java |
| 120 | +import org.springframework.security.boot.jwt.authentication.JwtAuthenticationToken; |
| 121 | +import org.springframework.security.boot.jwt.authentication.JwtAuthenticationWebFilter; |
| 122 | +import org.springframework.security.authentication.ReactiveAuthenticationManager; |
| 123 | + |
| 124 | +// 1. Token |
| 125 | +JwtAuthenticationToken token = |
| 126 | + new JwtAuthenticationToken(principal, jwtCredentials); |
| 127 | +token.setSign("optional-request-sign"); |
| 128 | +token.setLongitude(116.397128d); |
| 129 | +token.setLatitude(39.916527d); |
| 130 | + |
| 131 | +// 2. Reactive filter wired with your JWT-validating manager |
| 132 | +ReactiveAuthenticationManager manager = /* your manager */; |
| 133 | +JwtAuthenticationWebFilter filter = new JwtAuthenticationWebFilter(manager); |
| 134 | +``` |
| 135 | + |
| 136 | +**Expected result:** incoming requests matched by the filter are authenticated against the manager using the JWT credentials carried by `JwtAuthenticationToken`. |
| 137 | + |
| 138 | +## 7. Configuration |
| 139 | + |
| 140 | +This is a pure library: no configuration properties, no property prefix, no auto-configuration. All components are instantiated and wired by the application. |
| 141 | + |
| 142 | +## 8. Core Usage / API |
| 143 | + |
| 144 | +| Class | Package | Role | |
| 145 | +| :--- | :--- | :--- | |
| 146 | +| `JwtAuthenticationToken` | `org.springframework.security.boot.jwt.authentication` | `AbstractAuthenticationToken` subclass for the authentication phase. | |
| 147 | +| `JwtAuthorizationToken` | `org.springframework.security.boot.jwt.authorization` | Token for the authorization phase (same metadata fields). | |
| 148 | +| `JwtAuthenticationWebFilter` | `org.springframework.security.boot.jwt.authentication` | WebFlux `AuthenticationWebFilter` using a `ReactiveAuthenticationManager`. | |
| 149 | +| `JwtAuthorizationSuccessHandler` | `org.springframework.security.boot.jwt.authorization` | Servlet `AuthenticationSuccessHandler`; also exposes `clearAuthenticationAttributes`. | |
| 150 | +| `RefreshTokenEndpoint` | `org.springframework.security.boot.jwt.endpoint` | `@RestController` placeholder (no endpoints yet). | |
| 151 | + |
| 152 | +Servlet-style authorization success handling: |
| 153 | + |
| 154 | +```java |
| 155 | +import org.springframework.security.boot.jwt.authorization.JwtAuthorizationSuccessHandler; |
| 156 | + |
| 157 | +JwtAuthorizationSuccessHandler handler = new JwtAuthorizationSuccessHandler(); |
| 158 | +// Called by your authorization flow when the JWT check succeeds |
| 159 | +handler.onAuthenticationSuccess(request, response, authentication); |
| 160 | +``` |
| 161 | + |
| 162 | +## 9. Testing & Build |
| 163 | + |
| 164 | +```bash |
| 165 | +# Full build with JaCoCo coverage report/check |
| 166 | +./mvnw clean verify |
| 167 | + |
| 168 | +# Install into the local repository |
| 169 | +./mvnw install |
| 170 | +``` |
| 171 | + |
| 172 | +Test & gate facts (as configured in the pom): |
| 173 | + |
| 174 | +- No unit tests exist in this module yet. |
| 175 | +- JaCoCo is bound to `prepare-agent` / `report` / `check`; the `check` rule requires a **90% line coverage ratio** (configured with `haltOnFailure=false`). |
| 176 | + |
| 177 | +## 10. Versioning & Branches |
| 178 | + |
| 179 | +| Branch | JDK baseline | Version pattern | Status | |
| 180 | +| :--- | :--- | :--- | :--- | |
| 181 | +| `feature/1.0.x` | JDK 8 | `1.0.x.*` | Active; current snapshot `1.0.x.20260630-SNAPSHOT` | |
| 182 | +| `feature/2.0.x` | JDK 17 | `2.0.x.*` | Maintained | |
| 183 | +| `feature/3.0.x` | JDK 21 | `3.0.x.*` | Maintained | |
| 184 | + |
| 185 | +Maintenance strategy: the 1.0.x line keeps JDK 8 compatibility for legacy deployments; the 2.0.x and 3.0.x lines are the modern JDK baselines. Release artifacts are published to the project's configured artifact repository (Aliyun Packages) and GitHub Releases; the project has not yet published to Maven Central. |
| 186 | + |
| 187 | +## 11. Contributing & License |
| 188 | + |
| 189 | +Contributions are welcome — please open an issue or a pull request on the [GitHub repository](https://github.com/easy-4-java/security-jwt-extension). |
| 190 | + |
| 191 | +This project is licensed under the **Apache License 2.0**. See [LICENSE](LICENSE) for details. |
0 commit comments