t
This commit is contained in:
@@ -38,9 +38,4 @@ public class AccueilController {
|
|||||||
return "accueil";
|
return "accueil";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/login")
|
|
||||||
public String login(Model modele) {
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ProfileController {
|
|||||||
// Obtenez les détails de l'utilisateur authentifié
|
// Obtenez les détails de l'utilisateur authentifié
|
||||||
String username = authentication.getName();
|
String username = authentication.getName();
|
||||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||||
UserProfil userProfile = userService.utilisateurByName("Jojo");
|
UserProfil userProfile = userService.userByName("Jojo");
|
||||||
// Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML
|
// Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML
|
||||||
model.addAttribute("user", new UserProfil());
|
model.addAttribute("user", new UserProfil());
|
||||||
model.addAttribute("userProfile", userProfile);
|
model.addAttribute("userProfile", userProfile);
|
||||||
@@ -47,7 +47,7 @@ public class ProfileController {
|
|||||||
// Obtenez les détails de l'utilisateur authentifié
|
// Obtenez les détails de l'utilisateur authentifié
|
||||||
String username = authentication.getName();
|
String username = authentication.getName();
|
||||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||||
UserProfil userProfile = userService.utilisateurByName("Jojo");
|
UserProfil userProfile = userService.userByName("Jojo");
|
||||||
System.out.println(userProfile.getId());
|
System.out.println(userProfile.getId());
|
||||||
//Supprimer le compte
|
//Supprimer le compte
|
||||||
userService.deleteUtilisateur(userProfile.getId());
|
userService.deleteUtilisateur(userProfile.getId());
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
|
|
||||||
@@ -13,18 +16,28 @@ public class WebSecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http.authorizeHttpRequests((requests) -> requests
|
http.authorizeHttpRequests((requests) -> requests.requestMatchers("/", "/accueil").permitAll()
|
||||||
.requestMatchers("/", "/accueil").permitAll()
|
.requestMatchers("/login").permitAll()
|
||||||
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/profile/**").permitAll()
|
|
||||||
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
||||||
|
.requestMatchers("/article/**").authenticated()
|
||||||
.requestMatchers("/admin").hasRole("ADMIN")
|
.requestMatchers("/admin").hasRole("ADMIN")
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
||||||
.logout((logout) -> logout.clearAuthentication(true).invalidateHttpSession(true)
|
.logout((logout) -> logout.clearAuthentication(true).invalidateHttpSession(true).deleteCookies("JSESSIONID").logoutSuccessUrl("/filmLogout")
|
||||||
.deleteCookies("JSESSIONID").logoutSuccessUrl("/logout")
|
|
||||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll());
|
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll());
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public PasswordEncoder passwordEncoder() {
|
||||||
|
// return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user