Skip to content

About

Stateless REST API on Spring Boot 3 and Spring Security 6 with JWT auth, JPA, MapStruct and OpenAPI

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

HitCheck API

Stateless REST API for HitCheck: users register, send points (x, y, r) and get back whether each point falls inside a composite area on the plane, with a personal history of attempts. Authentication is JWT-based on Spring Security 6.

HitCheck screenshot

Stack: Java 17 · Spring Boot 3.2 · Spring Security 6 · JWT (jjwt 0.12) · Spring Data JPA · Hibernate · PostgreSQL · MapStruct · springdoc-openapi · Gradle

API

Method Path Auth Description
POST /auth/register — Create an account, returns a JWT
POST /auth/login — Log in, returns a JWT
GET /my-shots Bearer History of the current user's points
POST /my-shots Bearer Check a point and save the result

Swagger UI is available at /swagger-ui/index.html.

Authentication flow

sequenceDiagram
    participant C as Client
    participant F as JwtAuthenticationFilter
    participant A as AuthenticationController
    participant S as Spring Security

    C->>A: POST /auth/login {username, password}
    A->>S: AuthenticationManager (DaoAuthenticationProvider + BCrypt)
    S-->>A: authenticated
    A-->>C: JWT (subject, user id, roles, expiry)
    C->>F: GET /my-shots, Authorization: Bearer <token>
    F->>F: verify signature and expiry, load user
    F->>S: set SecurityContext
    S-->>C: 200 with the user's shots only
Loading
  • Sessions are disabled (STATELESS), CSRF is off because there are no cookies, CORS is open for the SPA frontend.
  • Passwords are hashed with BCrypt.
  • The token carries the user id and roles as claims, so a request needs no session lookup.
  • Validation errors and auth failures are turned into consistent JSON responses by an @ControllerAdvice.
  • The hit check lives in the Shot entity itself, so the rule is applied the same way wherever a shot is created.

Run locally

# PostgreSQL on localhost:5432, settings in src/main/resources/application.properties
./gradlew bootRun

Related repositories


Built as coursework for the Web Programming course at ITMO University, 2024.

About

Stateless REST API on Spring Boot 3 and Spring Security 6 with JWT auth, JPA, MapStruct and OpenAPI

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages