Compare commits

...

3 Commits

Author SHA1 Message Date
75633b9456 fix: reverse proxy conf 2026-03-16 12:36:21 +01:00
bd002fcbae feat: add readme 2026-03-16 11:57:32 +01:00
aa504dd881 feat: use oauth 2026-03-16 11:51:46 +01:00
7 changed files with 53 additions and 12 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin
.env
### IntelliJ IDEA ###
.idea/modules.xml

View File

@ -52,6 +52,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
</dependencies>
<build>

3
readme.md Normal file
View File

@ -0,0 +1,3 @@
# TODO
- When trying to add a product while not logged, it redirects to the login page but product infos aren't restored

View File

@ -18,11 +18,13 @@ public class SecurityConfig {
.requestMatchers("/add", "/delete/**").authenticated() // Seul l'admin ajoute/supprime
.anyRequest().authenticated()
)
.formLogin((form) -> form
.defaultSuccessUrl("/", true)
.permitAll()
.oauth2Login((oauth2) -> oauth2
.defaultSuccessUrl("/", true)
)
.logout((logout) -> logout.permitAll());
.logout((logout) -> logout
.logoutSuccessUrl("/")
.permitAll()
);
return http.build();
}

View File

@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import java.util.List;
@ -16,8 +18,9 @@ public class ProductController {
private ProductRepository productRepository; // Spring gère SQL tout seul !
@GetMapping("/")
public String listProducts(Model model) {
public String listProducts(Model model, @AuthenticationPrincipal OidcUser user) {
model.addAttribute("products", productRepository.findAll());
model.addAttribute("username", user != null ? user.getPreferredUsername() : null);
return "index"; // Ça va chercher src/main/resources/templates/index.html
}

View File

@ -5,3 +5,12 @@ spring.jpa.hibernate.ddl-auto=validate
server.port=8083
spring.security.user.name=admin
spring.security.user.password=${ADMIN_PASS}
spring.security.oauth2.client.registration.keycloak.client-id=${KEYCLOAK_CLIENT_ID}
spring.security.oauth2.client.registration.keycloak.client-secret=${KEYCLOAK_CLIENT_SECRET}
spring.security.oauth2.client.provider.keycloak.issuer-uri=${KEYCLOAK_ISSUER_URI}
spring.security.oauth2.client.registration.keycloak.scope=openid,profile
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.redirect-uri={baseUrl}/login/oauth2/code/keycloak
spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username
server.forward-headers-strategy=native

View File

@ -17,12 +17,31 @@
</h1>
<p class="text-gray-500 text-sm">Surveillance des prix en temps réel</p>
</div>
<div class="flex items-center gap-3 bg-gray-900 border border-gray-800 p-2 rounded-2xl shadow-inner">
<span class="relative flex h-3 w-3">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-green-500"></span>
</span>
<span class="text-xs font-mono text-gray-400 uppercase tracking-widest">System Active</span>
<div class="flex items-center gap-3">
<div class="flex items-center gap-3 bg-gray-900 border border-gray-800 p-2 rounded-2xl shadow-inner">
<span class="relative flex h-3 w-3">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-green-500"></span>
</span>
<span class="text-xs font-mono text-gray-400 uppercase tracking-widest">System Active</span>
</div>
<!-- Not logged in -->
<a th:if="${username == null}" href="/oauth2/authorization/keycloak"
class="bg-blue-600 hover:bg-blue-500 text-white font-bold py-2 px-4 rounded-2xl shadow-lg text-xs uppercase tracking-widest transition-colors">
Login
</a>
<!-- Logged in -->
<div th:if="${username != null}" class="flex items-center gap-2">
<span class="bg-gray-900 border border-gray-800 text-gray-300 font-bold py-2 px-4 rounded-2xl text-xs uppercase tracking-widest"
th:text="${username}">
</span>
<a href="/logout"
class="bg-red-600 hover:bg-red-500 text-white font-bold py-2 px-4 rounded-2xl shadow-lg text-xs uppercase tracking-widest transition-colors">
Logout
</a>
</div>
</div>
</header>