Compare commits
2 Commits
281d88d8ae
...
bd002fcbae
| Author | SHA1 | Date | |
|---|---|---|---|
| bd002fcbae | |||
| aa504dd881 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ target/
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
.kotlin
|
||||
.env
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
|
||||
4
pom.xml
4
pom.xml
@ -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
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
|
||||
.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();
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -5,3 +5,11 @@ 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
|
||||
@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user