I have the following form:
<form th:action="@{/login}" method="post" th:object="${usuario}">
<!-- This is the hidden which give troubles -->
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
<label for="username">Usuario</label>
<input type="text" th:field="*{username}"/>
<label for="password">Contrasenia</label>
<input type="password" th:field="*{password}"/>
<input type="submit" value="Login"/>
</form>
I have configured the security with the next configuration:
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
http
.authorizeExchange()
.pathMatchers("/login").permitAll()
.pathMatchers("/api/alumnos/getAlumnos","/listar","/","/index").hasRole("USER")
.pathMatchers("/api/alumnos/saveAlumno","/saveAlumno").hasRole("FUNCIONAL")
.anyExchange().authenticated()
.and().csrf(csrf -> csrf.csrfTokenRepository(CookieServerCsrfTokenRepository.withHttpOnlyFalse()))
.httpBasic() // Usamos autenticación básica HTTP (puedes configurarlo con JWT si lo prefieres)
.and()
.formLogin()
.loginPage("/login"); // Si usas autenticación OAuth2 también puedes configurarlo aquí
return http.build();
}
But when I run it. It gives me the next message: EL1007E: Property or field 'parameterName' cannot be found on null
So the problem is that SpringBoot isnt injecting the _csrm to thymeleaf. I can delete that line and it will work but sending the form will give me an error saying that csrf cant be found and it will leave.
I have this on the controller. I dont think its relevant.
@PreAuthorize("hasRole('USER')")
@GetMapping({"/listar","/","/index"})
public Mono<String> getAlumnosActivos(Model model) {
Flux<Alumno> alumnos=alumnoService.getActiveAlumnos();
alumnos.subscribe(al->log.info(String.format("Alumno: %s", al.getNombre())));
model.addAttribute("alumnos", alumnos);
model.addAttribute("titulo","Listado de Alumnos");
return Mono.just("index");
}
And other data which may be relevant is that Im using Spring Web Flux. Thank you for your help.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744133007a4559925.html
评论列表(0条)