33import static io .f1 .backend .domain .user .constants .SessionKeys .ADMIN ;
44import static io .f1 .backend .global .util .SecurityUtils .getCurrentAdminPrincipal ;
55
6+ import io .f1 .backend .domain .admin .dao .AdminRepository ;
67import io .f1 .backend .domain .admin .dto .AdminPrincipal ;
8+ import io .f1 .backend .domain .admin .entity .Admin ;
79import jakarta .servlet .http .HttpServletRequest ;
810import jakarta .servlet .http .HttpServletResponse ;
911import jakarta .servlet .http .HttpSession ;
12+ import java .time .LocalDateTime ;
1013import lombok .RequiredArgsConstructor ;
1114import org .springframework .security .core .Authentication ;
1215import org .springframework .security .web .authentication .AuthenticationSuccessHandler ;
1619@ RequiredArgsConstructor
1720public class AdminLoginSuccessHandler implements AuthenticationSuccessHandler {
1821
22+ private final AdminRepository adminRepository ;
1923 private final HttpSession httpSession ;
2024
2125 @ Override
@@ -25,6 +29,11 @@ public void onAuthenticationSuccess(
2529 Authentication authentication ) {
2630
2731 AdminPrincipal principal = getCurrentAdminPrincipal ();
32+ Admin admin = adminRepository .findByUsername (principal .getUsername ())
33+ .orElseThrow (() -> new RuntimeException ("E404007: 존재하지 않는 관리자입니다." ));
34+
35+ admin .updateLastLogin (LocalDateTime .now ());
36+ adminRepository .save (admin );
2837 httpSession .setAttribute (ADMIN , principal .getAuthenticationAdmin ());
2938
3039 response .setStatus (HttpServletResponse .SC_OK ); // 200
0 commit comments