Compare commits
3 Commits
281d88d8ae
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 75633b9456 | |||
| bd002fcbae | |||
| aa504dd881 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ target/
|
|||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
.kotlin
|
.kotlin
|
||||||
|
.env
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea/modules.xml
|
.idea/modules.xml
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@ -52,6 +52,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-oauth2-client</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
3
readme.md
Normal file
3
readme.md
Normal 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
|
||||||
@ -18,11 +18,13 @@ public class SecurityConfig {
|
|||||||
.requestMatchers("/add", "/delete/**").authenticated() // Seul l'admin ajoute/supprime
|
.requestMatchers("/add", "/delete/**").authenticated() // Seul l'admin ajoute/supprime
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.formLogin((form) -> form
|
.oauth2Login((oauth2) -> oauth2
|
||||||
.defaultSuccessUrl("/", true)
|
.defaultSuccessUrl("/", true)
|
||||||
.permitAll()
|
|
||||||
)
|
)
|
||||||
.logout((logout) -> logout.permitAll());
|
.logout((logout) -> logout
|
||||||
|
.logoutSuccessUrl("/")
|
||||||
|
.permitAll()
|
||||||
|
);
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
@ -16,8 +18,9 @@ public class ProductController {
|
|||||||
private ProductRepository productRepository; // Spring gère SQL tout seul !
|
private ProductRepository productRepository; // Spring gère SQL tout seul !
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String listProducts(Model model) {
|
public String listProducts(Model model, @AuthenticationPrincipal OidcUser user) {
|
||||||
model.addAttribute("products", productRepository.findAll());
|
model.addAttribute("products", productRepository.findAll());
|
||||||
|
model.addAttribute("username", user != null ? user.getPreferredUsername() : null);
|
||||||
return "index"; // Ça va chercher src/main/resources/templates/index.html
|
return "index"; // Ça va chercher src/main/resources/templates/index.html
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,4 +4,13 @@ spring.datasource.password=${DB_PASS}
|
|||||||
spring.jpa.hibernate.ddl-auto=validate
|
spring.jpa.hibernate.ddl-auto=validate
|
||||||
server.port=8083
|
server.port=8083
|
||||||
spring.security.user.name=admin
|
spring.security.user.name=admin
|
||||||
spring.security.user.password=${ADMIN_PASS}
|
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
|
||||||
@ -17,12 +17,31 @@
|
|||||||
</h1>
|
</h1>
|
||||||
<p class="text-gray-500 text-sm">Surveillance des prix en temps réel</p>
|
<p class="text-gray-500 text-sm">Surveillance des prix en temps réel</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-3 bg-gray-900 border border-gray-800 p-2 rounded-2xl shadow-inner">
|
<div class="flex items-center gap-3">
|
||||||
<span class="relative flex h-3 w-3">
|
<div class="flex items-center gap-3 bg-gray-900 border border-gray-800 p-2 rounded-2xl shadow-inner">
|
||||||
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span>
|
<span class="relative flex h-3 w-3">
|
||||||
<span class="relative inline-flex rounded-full h-3 w-3 bg-green-500"></span>
|
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span>
|
||||||
</span>
|
<span class="relative inline-flex rounded-full h-3 w-3 bg-green-500"></span>
|
||||||
<span class="text-xs font-mono text-gray-400 uppercase tracking-widest">System Active</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>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user