package com.ytpm.config.auth;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AuthListenerConfig {
    @EventListener
    public void onSuccess(AuthenticationSuccessEvent successEvent){
        log.error(successEvent.getAuthentication().getName()+"认证成功");
    }

    @EventListener
    public void onFailure(AbstractAuthenticationFailureEvent failureDisabledEvent){
        log.error(failureDisabledEvent.getAuthentication().getName()+"认证失败，失败原因："+failureDisabledEvent.getException().getMessage());
    }
}
