{"openapi":"3.1.0","info":{"title":"Access management PoC","description":"API with JWT and RBAC","version":"1.0"},"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"security":[{"bearerAuth":[]}],"tags":[{"name":"Users","description":"Endpoints for user management"},{"name":"Authentication","description":"Endpoints for login, refresh, and logout"}],"paths":{"/users/{username}":{"put":{"tags":["Users"],"summary":"Update a user","description":"Updates a user's data. Accessible by ADMIN or the user themselves.","operationId":"updateUser","parameters":[{"name":"username","in":"path","description":"Username of the user to update","required":true,"schema":{"type":"string"}}],"requestBody":{"description":"Updated user data","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserRequest"}}},"required":true},"responses":{"200":{"description":"User successfully updated","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}},"404":{"description":"User not found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}},"403":{"description":"Forbidden","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}}},"security":[{"bearerAuth":[]}]}},"/users":{"get":{"tags":["Users"],"summary":"Get all users","description":"Retrieves all users with pagination. Accessible by ADMIN and USER.","operationId":"getAllUsers","parameters":[{"name":"pageable","in":"query","description":"Pagination information","required":true,"schema":{"$ref":"#/components/schemas/Pageable"}}],"responses":{"200":{"description":"Users retrieved successfully","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageUserResponse"}}}},"403":{"description":"Forbidden, insufficient permissions","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageUserResponse"}}}}},"security":[{"bearerAuth":[]}]},"post":{"tags":["Users"],"summary":"Register a new user","description":"Creates a new user in the system. Only accessible by ADMIN.","operationId":"register","requestBody":{"description":"User data to create","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserRequest"}}},"required":true},"responses":{"201":{"description":"User successfully created","content":{"*/*":{"schema":{"type":"object"}}}},"400":{"description":"Invalid request data","content":{"*/*":{"schema":{"type":"object"}}}},"403":{"description":"Forbidden, insufficient permissions","content":{"*/*":{"schema":{"type":"object"}}}}},"security":[{"bearerAuth":[]}]}},"/auth/refresh":{"post":{"tags":["Authentication"],"summary":"Refresh token","description":"Refreshes authentication using a valid refresh token.\nValid refresh token → issues new access token and rotates refresh cookie.\nMissing or invalid token → returns 401 Unauthorized.","operationId":"refresh","responses":{"200":{"description":"New access token issued","content":{"*/*":{"schema":{"type":"object"}}}},"401":{"description":"Missing or invalid refresh token","content":{"*/*":{"schema":{"type":"object"}}}}},"security":[{"bearerAuth":[]}]}},"/auth/logout":{"post":{"tags":["Authentication"],"summary":"Logout","description":"Logs a user out by revoking refresh tokens and clearing the refresh cookie.","operationId":"logout","requestBody":{"description":"JSON body containing the username key","content":{"application/json":{"schema":{"type":"object","additionalProperties":{"type":"string"}}}},"required":true},"responses":{"204":{"description":"Logout successful, refresh cookie cleared","content":{"*/*":{"schema":{"type":"object"}}}},"404":{"description":"User not found or already logged out","content":{"*/*":{"schema":{"type":"object"}}}}},"security":[{"bearerAuth":[]}]}},"/auth/login":{"post":{"tags":["Authentication"],"summary":"Login","description":"Authenticates a user with username and password.\nValid credentials → returns JWT access token and sets refresh cookie.\nInvalid credentials → returns 401 Unauthorized.","operationId":"login","requestBody":{"description":"Authentication request containing username and password","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AuthRequest"}}},"required":true},"responses":{"200":{"description":"Login successful, access token returned","content":{"*/*":{"schema":{"type":"object"}}}},"401":{"description":"Invalid credentials","content":{"*/*":{"schema":{"type":"object"}}}}}}},"/users/{id}":{"get":{"tags":["Users"],"summary":"Get user by ID","description":"Retrieves a user by their ID. Accessible by ADMIN only.","operationId":"getUserById","parameters":[{"name":"id","in":"path","description":"ID of the user to retrieve","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"User found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}},"404":{"description":"User not found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}},"403":{"description":"Forbidden","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}}},"security":[{"bearerAuth":[]}]},"delete":{"tags":["Users"],"summary":"Delete a user","description":"Deletes a user by ID. Accessible by ADMIN only.","operationId":"deleteUser","parameters":[{"name":"id","in":"path","description":"ID of the user to delete","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"204":{"description":"User deleted successfully"},"404":{"description":"User not found"},"403":{"description":"Forbidden"}},"security":[{"bearerAuth":[]}]}},"/users/search":{"get":{"tags":["Users"],"summary":"Search users","description":"Searches users by username or role with pagination. Accessible by ADMIN and USER.","operationId":"searchUsers","parameters":[{"name":"username","in":"query","description":"Username filter","required":false,"schema":{"type":"string"}},{"name":"role","in":"query","description":"Role filter","required":false,"schema":{"type":"string","enum":["ADMIN","USER"]}},{"name":"pageable","in":"query","description":"Pagination information","required":true,"schema":{"$ref":"#/components/schemas/Pageable"}}],"responses":{"200":{"description":"Users retrieved successfully","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageUserResponse"}}}},"403":{"description":"Forbidden","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageUserResponse"}}}}},"security":[{"bearerAuth":[]}]}},"/users/mail/{email}":{"get":{"tags":["Users"],"summary":"Get user by email","description":"Retrieves a user by their email address. Accessible by ADMIN only.","operationId":"getUserByEmail","parameters":[{"name":"email","in":"path","description":"Email of the user to retrieve","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"User found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}},"404":{"description":"User not found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}},"403":{"description":"Forbidden","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UserResponse"}}}}},"security":[{"bearerAuth":[]}]}}},"components":{"schemas":{"UserRequest":{"type":"object","description":"Request DTO for creating or updating a user","properties":{"username":{"type":"string","description":"Username of the user","example":"yann"},"password":{"type":"string","description":"Password of the user","example":"P@ssw0rd123"},"email":{"type":"string","description":"Email address of the user","example":"yann@example.com"},"role":{"type":"string","description":"Role assigned to the user","enum":["ADMIN","USER"],"example":"ADMIN"},"status":{"type":"string","description":"Status of the user account","enum":["ACTIVE","INACTIVE"],"example":"ACTIVE"}},"required":["email","password","role","status","username"]},"UserResponse":{"type":"object","description":"Response DTO for user data","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the user","example":1},"username":{"type":"string","description":"Username of the user","example":"yann"},"email":{"type":"string","description":"Email address of the user","example":"yann@example.com"},"role":{"type":"string","description":"Role assigned to the user","enum":["ADMIN","USER"],"example":"ADMIN"},"status":{"type":"string","description":"Status of the user account","enum":["ACTIVE","INACTIVE"],"example":"ACTIVE"},"createdAt":{"type":"string","format":"date-time","description":"Timestamp when the user was created","example":"2025-11-25T13:45:30Z"},"createdBy":{"type":"string","description":"Username who created this user","example":"admin"},"updatedAt":{"type":"string","format":"date-time","description":"Timestamp of last update","example":"2025-11-25T14:20:00Z"},"updatedBy":{"type":"string","description":"Username who last updated this user","example":"admin"}}},"AuthRequest":{"type":"object","description":"Request object for user authentication","properties":{"username":{"type":"string","description":"Username of the user attempting to authenticate","example":"yann"},"password":{"type":"string","description":"Password of the user attempting to authenticate","example":"P@ssw0rd123"}}},"Pageable":{"type":"object","properties":{"page":{"type":"integer","format":"int32","minimum":0},"size":{"type":"integer","format":"int32","minimum":1},"sort":{"type":"array","items":{"type":"string"}}}},"PageUserResponse":{"type":"object","properties":{"totalElements":{"type":"integer","format":"int64"},"totalPages":{"type":"integer","format":"int32"},"size":{"type":"integer","format":"int32"},"content":{"type":"array","items":{"$ref":"#/components/schemas/UserResponse"}},"number":{"type":"integer","format":"int32"},"sort":{"$ref":"#/components/schemas/SortObject"},"numberOfElements":{"type":"integer","format":"int32"},"first":{"type":"boolean"},"last":{"type":"boolean"},"pageable":{"$ref":"#/components/schemas/PageableObject"},"empty":{"type":"boolean"}}},"PageableObject":{"type":"object","properties":{"offset":{"type":"integer","format":"int64"},"sort":{"$ref":"#/components/schemas/SortObject"},"pageSize":{"type":"integer","format":"int32"},"paged":{"type":"boolean"},"pageNumber":{"type":"integer","format":"int32"},"unpaged":{"type":"boolean"}}},"SortObject":{"type":"object","properties":{"empty":{"type":"boolean"},"sorted":{"type":"boolean"},"unsorted":{"type":"boolean"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}}}