diff --git a/AGENTS.md b/AGENTS.md
index 767c2f0..5597672 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -12,6 +12,7 @@ Auto-generated from all feature plans. Last updated: 2026-04-09
- H2 in-memory (test profile) (004-test-coverage)
- Java 21 + Spring Boot 3.3.5, Spring Data JPA, H2 (existing — no new dependencies) (005-persistent-storage)
- H2 file-based (`jdbc:h2:file:./data/sfdb`) for dev; H2 mem for tes (005-persistent-storage)
+- `data/users.json` (file-based, MVP) (007-authentication)
- Java 21 for backend, TypeScript 5.x with React 18 for dashboard + Spring Boot 3.3.5 (`web`, `data-jpa`, `actuator`, `test`), H2, Jackson JSON/YAML, React 18, Vite 5, Tailwind 3 (001-sf-ci-emulator)
@@ -31,9 +32,9 @@ npm test && npm run lint
Java 21 for backend, TypeScript 5.x with React 18 for dashboard: Follow standard conventions
## Recent Changes
+- 007-authentication: Added Java 21
- 005-persistent-storage: Added Java 21 + Spring Boot 3.3.5, Spring Data JPA, H2 (existing — no new dependencies)
- 004-test-coverage: Added Java 21 + Spring Boot 3.3.5 (spring-boot-starter-test), JUnit 5, MockMvc, AssertJ
-- 003-ms-test-sf-localstack: Added Java 21 (both repos), Spring Boot 3.3.x + Testcontainers 1.19+ (GenericContainer), WireMock (removed from metadata-service test scope), Spring Tes
diff --git a/service/pom.xml b/service/pom.xml
index 3f9f46c..35c116a 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -59,6 +59,30 @@
spring-boot-starter-test
test
+
+
+
+ io.jsonwebtoken
+ jjwt-api
+ 0.12.6
+
+
+ io.jsonwebtoken
+ jjwt-impl
+ 0.12.6
+ runtime
+
+
+ io.jsonwebtoken
+ jjwt-jackson
+ 0.12.6
+ runtime
+
+
+
+ org.springframework.security
+ spring-security-crypto
+
diff --git a/service/src/main/java/co/razkevich/sflocalstack/auth/controller/AuthController.java b/service/src/main/java/co/razkevich/sflocalstack/auth/controller/AuthController.java
new file mode 100644
index 0000000..f03cd0e
--- /dev/null
+++ b/service/src/main/java/co/razkevich/sflocalstack/auth/controller/AuthController.java
@@ -0,0 +1,222 @@
+package co.razkevich.sflocalstack.auth.controller;
+
+import co.razkevich.sflocalstack.auth.model.Role;
+import co.razkevich.sflocalstack.auth.model.User;
+import co.razkevich.sflocalstack.auth.service.JwtService;
+import co.razkevich.sflocalstack.auth.store.UserStore;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.Instant;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@RestController
+@RequestMapping("/api/auth")
+public class AuthController {
+
+ private final UserStore userStore;
+ private final JwtService jwtService;
+
+ public AuthController(UserStore userStore, JwtService jwtService) {
+ this.userStore = userStore;
+ this.jwtService = jwtService;
+ }
+
+ @PostMapping("/register")
+ public ResponseEntity> register(@RequestBody Map body,
+ @RequestHeader(value = "Authorization", required = false) String authHeader) {
+ String username = body.get("username");
+ String email = body.get("email");
+ String password = body.get("password");
+
+ if (username == null || email == null || password == null) {
+ return ResponseEntity.badRequest()
+ .body(Map.of("error", "Bad Request", "message", "username, email, and password are required"));
+ }
+
+ if (userStore.findByUsername(username).isPresent()) {
+ return ResponseEntity.status(HttpStatus.CONFLICT)
+ .body(Map.of("error", "Conflict", "message", "Username already exists"));
+ }
+
+ Role role;
+ if (!userStore.hasUsers()) {
+ role = Role.ADMIN;
+ } else {
+ if (authHeader == null || !authHeader.startsWith("Bearer ")) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Admin JWT required to register new users"));
+ }
+ try {
+ String tokenRole = jwtService.extractRole(authHeader.substring(7));
+ if (!"ADMIN".equals(tokenRole)) {
+ return ResponseEntity.status(HttpStatus.FORBIDDEN)
+ .body(Map.of("error", "Forbidden", "message", "Only admins can register new users"));
+ }
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Invalid token"));
+ }
+ role = Role.USER;
+ }
+
+ User user = userStore.createUser(username, email, password, role);
+ String accessToken = jwtService.generateAccessToken(user);
+ String refreshToken = jwtService.generateRefreshToken(user);
+
+ Map response = new LinkedHashMap<>();
+ response.put("accessToken", accessToken);
+ response.put("refreshToken", refreshToken);
+ response.put("user", toUserResponse(user));
+ return ResponseEntity.status(HttpStatus.CREATED).body(response);
+ }
+
+ @PostMapping("/login")
+ public ResponseEntity> login(@RequestBody Map body) {
+ String username = body.get("username");
+ String password = body.get("password");
+
+ if (username == null || password == null) {
+ return ResponseEntity.badRequest()
+ .body(Map.of("error", "Bad Request", "message", "username and password are required"));
+ }
+
+ if (!userStore.validateCredentials(username, password)) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Invalid username or password"));
+ }
+
+ User user = userStore.findByUsername(username).orElseThrow();
+ user.setLastLoginAt(Instant.now());
+
+ String accessToken = jwtService.generateAccessToken(user);
+ String refreshToken = jwtService.generateRefreshToken(user);
+
+ Map response = new LinkedHashMap<>();
+ response.put("accessToken", accessToken);
+ response.put("refreshToken", refreshToken);
+ response.put("user", toUserResponse(user));
+ return ResponseEntity.ok(response);
+ }
+
+ @PostMapping("/refresh")
+ public ResponseEntity> refresh(@RequestBody Map body) {
+ String refreshToken = body.get("refreshToken");
+ if (refreshToken == null) {
+ return ResponseEntity.badRequest()
+ .body(Map.of("error", "Bad Request", "message", "refreshToken is required"));
+ }
+
+ try {
+ var claims = jwtService.validateToken(refreshToken);
+ if (!"refresh".equals(claims.get("type", String.class))) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Not a refresh token"));
+ }
+
+ String userId = claims.get("userId", String.class);
+ Optional userOpt = userStore.findById(userId);
+ if (userOpt.isEmpty()) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "User not found"));
+ }
+
+ String newAccessToken = jwtService.generateAccessToken(userOpt.get());
+ return ResponseEntity.ok(Map.of("accessToken", newAccessToken));
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Invalid refresh token"));
+ }
+ }
+
+ @GetMapping("/me")
+ public ResponseEntity> me(@RequestHeader(value = "Authorization", required = false) String authHeader) {
+ if (authHeader == null || !authHeader.startsWith("Bearer ")) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Bearer token required"));
+ }
+
+ try {
+ String userId = jwtService.extractUserId(authHeader.substring(7));
+ Optional userOpt = userStore.findById(userId);
+ if (userOpt.isEmpty()) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "User not found"));
+ }
+ return ResponseEntity.ok(toUserResponse(userOpt.get()));
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Invalid token"));
+ }
+ }
+
+ @GetMapping("/users")
+ public ResponseEntity> listUsers(@RequestHeader(value = "Authorization", required = false) String authHeader) {
+ if (authHeader == null || !authHeader.startsWith("Bearer ")) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Bearer token required"));
+ }
+
+ try {
+ String role = jwtService.extractRole(authHeader.substring(7));
+ if (!"ADMIN".equals(role)) {
+ return ResponseEntity.status(HttpStatus.FORBIDDEN)
+ .body(Map.of("error", "Forbidden", "message", "Admin role required"));
+ }
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+ .body(Map.of("error", "Unauthorized", "message", "Invalid token"));
+ }
+
+ List