Spring Boot sécurity page login perso qui ne s'affiche pas
Bonjour a tous,
Je suis en train demettre en place une authentification sur mon back, mon authentifiaction fonctionne, mais je n'arrive pas à visualiser ma page de login perso.
C'est toujours la page par défaut qui s'afffiche.
J'ai suivi la documentation:
https://docs.spring.io/spring-securi...ords/form.html
mais cela ne fonctionne pas.
Voici mon code:
Ma class gerant la sécurité:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| @EnableWebSecurity
public class BackSecurityController {
@RequestMapping({"admin", "admin/index"})
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
http.authorizeHttpRequests((requests) -> requests
.antMatchers("/admin", "/admin/index").permitAll()
.anyRequest().authenticated()
);
http.formLogin((form) -> form
.loginPage("/login")
.permitAll()
)
.logout((logout) -> logout.permitAll());
return http.build();
}
@Bean
public UserDetailsService userDetailsService() {
UserDetails user =
User.withDefaultPasswordEncoder()
.username("user")
.password("pwd")
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
} |
ma page login.html qui est a la racine de template:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
<title>Spring Security Example </title>
</head>
<body>
<div th:if="${param.error}">
Invalid username and password.
</div>
<div th:if="${param.logout}">
You have been logged out.
</div>
<form th:action="@{/login}" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Sign In"/></div>
</form>
</body>
</html> |
Et mon @controller:
Code:
1 2 3
| @GetMapping("/login")
public String index(Model model){
return "login";} |
Je pense que je n'ai rien oublié, d’après la doc, c'est uniquement ce qu'il y a faire pour supprimer la page par défaut et utiliser une page perso.
Mais je dois certainement passer a coté de quelque chose