Securityconfig.java
@Bean
public AuthenticationFailureHandler authenticationFailureHandler() {
return new SimpleUrlAuthenticationFailureHandler("/member/login?error=true");
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http,
AuthenticationFailureHandler failureHandler) throws Exception {
// -> CSRF 기능 비활성화
http.csrf((csrf) -> csrf.disable());
// 로그인 페이지 커스터마이징
http.formLogin((formLogin) -> formLogin
.loginProcessingUrl("/member/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/")
.failureHandler(failureHandler));
// 로그아웃 이후 이동할 페이지
http.logout((logout) -> logout.logoutSuccessUrl("/"));
return http.build();
}
formLogin에서 .successHandler
가 계속 에러남;;
login.html
<div class="my-2 card" style="padding: 0 30px 0 30px;">
<div class="my-5 text-center">
<h1>Sign In</h1>
<div class="card-body">
<form method="post" th:action="@{/member/login}">
<div class="my-2">
<div class="form-floating mb-4">
<input type="text" class="form-control" name="username" placeholder="ID" required />
<label for="floatingInput">ID</label>
</div>
<div class="form-floating mb-4">
<input type="password" class="form-control" name="password" placeholder="PASSWORD" required />
<label for="floatingPassword">PASSWORD</label>
</div>
</div>
<div class="mt-5 d-grid gap-2 d-md-flex justify-content-md-center">
<input class="btn btn-info" type="submit" value="sign in" />
</div>
</form>
</div>
</div>
</div>
로그인 잘 된다