package com.tofly.feesapi.security.handler;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;

/**
 * @author Administrator
 * 认证成功事件
 * @date 2019/9/10  11:07
 */
public abstract class AbstractAuthenticationSuccessEventHandler implements ApplicationListener<AuthenticationSuccessEvent> {
    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent authenticationSuccessEvent) {
        Authentication authentication = (Authentication) authenticationSuccessEvent.getSource();
        if (CollectionUtils.isNotEmpty(authentication.getAuthorities())) {
            handle(authentication);
        }
    }


    /**
     * 处理登录成功方法
     * 获取到登录的authentication 对象
     * @param authentication 登录对象
     */
    public abstract void handle(Authentication authentication);
}
