package com.tofly.feesapi.security.handler;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * @author Administrator
 * 认证失败的方法
 * @date 2019/9/10  11:10
 */
public abstract class AbstractAuthenticationFailureEvenHandler implements
        ApplicationListener<AbstractAuthenticationFailureEvent> {
    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent abstractAuthenticationFailureEvent) {
        AuthenticationException authenticationException = abstractAuthenticationFailureEvent.getException();
        Authentication authentication = (Authentication) abstractAuthenticationFailureEvent.getSource();

        handle(authenticationException, authentication);
    }

    /**
     * 处理登录失败方法
     * @param authenticationException 登录的authentication 对象
     * @param authentication          登录的authenticationException 对象
     */
    public abstract void handle(AuthenticationException authenticationException, Authentication authentication);
}
