add security

This commit is contained in:
Σlie *
2026-02-28 14:11:43 +01:00
parent 58e5a2b67a
commit 5246ed5560
4 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,29 @@
package fr.tetelie.crawler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/", "/api/**", "/css/**", "/js/**").permitAll() // Tout le monde voit le dashboard
.requestMatchers("/add", "/delete/**").authenticated() // Seul l'admin ajoute/supprime
.anyRequest().authenticated()
)
.formLogin((form) -> form
.defaultSuccessUrl("/", true)
.permitAll()
)
.logout((logout) -> logout.permitAll());
return http.build();
}
}

View File

@ -2,4 +2,6 @@ spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASS}
spring.jpa.hibernate.ddl-auto=validate
server.port=8083
server.port=8083
spring.security.user.name=admin
spring.security.user.password=${ADMIN_PASS}

View File

@ -28,6 +28,7 @@
<section class="bg-gray-900 p-1 rounded-3xl border border-gray-800 shadow-2xl mb-12">
<form th:action="@{/add}" method="POST" class="flex flex-col md:flex-row gap-2 p-2">
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
<input type="text" name="name" required placeholder="Nom de l'objet..."
class="flex-1 p-4 rounded-2xl bg-gray-800 border-none text-white placeholder-gray-500 focus:ring-2 focus:ring-blue-600 outline-none transition-all">
<input type="url" name="link" required placeholder="Lien Amazon..."