package top.imwork.window.silos.security.handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Copyright (C), 2015-2025
 * FileName: SecurityAuthenticationFailureHandler
 * Author<作者姓名>:   stars
 * CreateTime<创建时间>:   2025/12/10 14:18
 * UpdateTime<修改时间>:   2025/12/10 14:18
 * Description〈功能简述〉: 登录失败处理器
 * History<历史描述>:
 * Since<版本号>: 1.0.0
 */
@Component
public class SecurityAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        request.getSession().setAttribute("message", "用户名或密码错误!");
        response.sendRedirect("/login.html");
    }
}