From 2286e501db5d07c8f5f35d7fa292d2561b61786e Mon Sep 17 00:00:00 2001 From: Ismael Neto <114830206+otaldoneto@users.noreply.github.com> Date: Wed, 23 Sep 2026 15:56:25 -0300 Subject: [PATCH] feat: add a public landing page at the root --- README.md | 2 +- .../management/config/SecurityConfig.java | 2 + src/main/resources/static/index.html | 155 ++++++++++++++++++ .../controllers/LandingPageTest.java | 50 ++++++ 4 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/static/index.html create mode 100644 src/test/java/com/serviceorder/management/controllers/LandingPageTest.java diff --git a/README.md b/README.md index df1fae3..754a6f3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ REST API for managing clients, technicians and service orders (help desk style), ## Live demo -- API: https://service-order-management-nxil.onrender.com +- Home page: https://service-order-management-nxil.onrender.com - Swagger UI: https://service-order-management-nxil.onrender.com/swagger-ui.html The demo runs on free tiers ([Render](https://render.com) for the API and [Neon](https://neon.com) for PostgreSQL), so diff --git a/src/main/java/com/serviceorder/management/config/SecurityConfig.java b/src/main/java/com/serviceorder/management/config/SecurityConfig.java index 786ff87..546bab9 100644 --- a/src/main/java/com/serviceorder/management/config/SecurityConfig.java +++ b/src/main/java/com/serviceorder/management/config/SecurityConfig.java @@ -37,6 +37,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // The first matching rule wins, so the specific rules come before anyRequest(). .authorizeHttpRequests(auth -> auth + .requestMatchers(HttpMethod.GET, "/", "/index.html").permitAll() + .requestMatchers(HttpMethod.HEAD, "/", "/index.html").permitAll() .requestMatchers("/auth/login", "/auth/refresh", "/auth/logout").permitAll() .requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**").permitAll() .requestMatchers(HttpMethod.PUT, "/users/me/password").authenticated() diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html new file mode 100644 index 0000000..668914c --- /dev/null +++ b/src/main/resources/static/index.html @@ -0,0 +1,155 @@ + + + + + + Service Order Management API + + + + +
+

Service Order Management API

+

+ A REST API for managing clients, technicians and service orders, help desk style. + Built with Spring Boot, secured with JWT and covered by automated tests. +

+ +
+ Try it in Swagger UI + View the source on GitHub +
+ +

What it does

+
+
+

Service order lifecycle

+

Orders move through enforced status transitions, and finishing one requires a root cause report.

+
+
+

Authentication and roles

+

JWT access tokens, rotating refresh tokens, ADMIN and USER roles, and login rate limiting.

+
+
+

Audit trail

+

Every order records who created it and who changed it last, and concurrent edits never overwrite each other silently.

+
+
+

PDF reports

+

Download a report for any service order, and filter and paginate the list by status, priority, client, technician or title.

+
+
+ +

Order lifecycle

+
+ OPEN assign → + IN_PROGRESS finish → + FINISHED + (or cancel from OPEN / IN_PROGRESS to CANCELED) +
+ +

Main endpoints

+
+ + + + + + + + + + +
Method and pathDescription
POST /auth/loginLog in and receive an access token and a refresh token
POST /auth/refreshExchange a refresh token for a new pair
GET /ordersList service orders with filters and pagination
POST /ordersCreate a service order for a client
PUT /orders/{id}/assign/{technicianId}Assign a technician
GET /orders/{id}/reportDownload the order report as PDF
+
+

+ Every endpoint except login needs a token, so the interactive docs are the best place to start. +

+ +

Built with

+ + + +
+ + diff --git a/src/test/java/com/serviceorder/management/controllers/LandingPageTest.java b/src/test/java/com/serviceorder/management/controllers/LandingPageTest.java new file mode 100644 index 0000000..7491908 --- /dev/null +++ b/src/test/java/com/serviceorder/management/controllers/LandingPageTest.java @@ -0,0 +1,50 @@ +package com.serviceorder.management.controllers; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithAnonymousUser; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.head; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WithAnonymousUser +class LandingPageTest extends ApiTestSupport { + + @Test + @DisplayName("GET / should forward to the public landing page without a token") + void rootShouldForwardToTheLandingPage() throws Exception { + // MockMvc does not follow forwards, so the forward itself is what proves the welcome page is mapped and public + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(forwardedUrl("index.html")); + } + + @Test + @DisplayName("GET /index.html should serve the landing page without a token") + void landingPageShouldBePublic() throws Exception { + mockMvc.perform(get("/index.html")) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)) + .andExpect(content().string(containsString("Service Order Management API"))); + } + + @Test + @DisplayName("HEAD / should also be public, for uptime checks and link previews") + void headRequestShouldBePublic() throws Exception { + mockMvc.perform(head("/index.html")).andExpect(status().isOk()); + } + + @Test + @DisplayName("Opening the landing page must not make the rest of the API public") + void apiShouldStayProtected() throws Exception { + mockMvc.perform(get("/clients")).andExpect(status().isUnauthorized()); + mockMvc.perform(get("/orders")).andExpect(status().isUnauthorized()); + mockMvc.perform(post("/")).andExpect(status().isUnauthorized()); + } +}