【♣부트 캠프♣】/▷부캠- 에러 모음
[로그인에러]
아딜렛
2025. 4. 3. 15:32
에러
Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "login_form" - line 39, col 40)
문제 파악
th:field 가 작동을 안함
스프링 시큐리티의 UsernamePasswordAuthenticationFilter가 요청을 가져감request.getParameter("username")과 request.getParameter("password")로 값을 추출
이 값들을 사용해 인증을 시도
왜 th가 작동하지 않는가?
로그인 폼에서 th:field를 사용하려면:
컨트롤러에서 모델에 객체를 추가해야 합니다.
이 객체는 membername과 password 필드를 가지고 있어야 합니다.
폼에 th:object를 사용해 객체를 바인딩해야 합니다.
해결:
하지만 스프링 시큐리티의 로그인 처리는 이런 방식으로 작동하지 않음. 로그인 폼을 보여주는 컨트롤러는 단순히 뷰 이름만 반환하고 모델 객체는 추가하지 x.
th:field가 참조할 객체가 없어서 오류가 발생
public class SecurityConfig {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
http
...
.formLogin((form) -> form
.loginPage("/member/login")
.defaultSuccessUrl("/")
.usernameParameter("membername") // username 파라미터명 변경
.passwordParameter("password") // password는 기본값 그대로 사용
.permitAll()
)