Spring AbstractAuthenticationEvent 详解

org.springframework.security.authentication.event.AbstractAuthenticationEvent


summary

先来看一段 Type  hierarchy

  • java.lang.Object

    • java.util.EventObject

      • org.springframework.context.ApplicationEvent

        • AbstractAuthenticationEvent(org.springframework.security.authentication.event)

          • AbstractAuthenticationFailureEvent,

            • AuthenticationFailureBadCredentialsEvent, 

            • AuthenticationFailureCredentialsExpiredEvent, 

            • AuthenticationFailureDisabledEvent,

            • AuthenticationFailureExpiredEvent,

            • AuthenticationFailureLockedEvent,

            • AuthenticationFailureProviderNotFoundEvent,

            • AuthenticationFailureProxyUntrustedEvent, 

            • AuthenticationFailureServiceExceptionEvent

          • AuthenticationSuccessEvent, 

          • AuthenticationSwitchUserEvent, 

          • InteractiveAuthenticationSuccessEvent, 

          • SessionFixationProtectionEvent


Spring Security 继承的Spring Framework的优良品质,设计了多种的扩展点,因此我们可以使用事件监听器来获知验证和授权事件,从而做一些日志记录操作。


import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationEvent;
public class AuthenticationEventLogger implements
        ApplicationListener<AbstractAuthenticationEvent> {
    @Override
    public void onApplicationEvent(AbstractAuthenticationEvent event) {
        System.out.println(event);
    }
}


事件详解


不同的事件类型代表了不同的验证情况,从事件的设计上也能够看出Spring Security在设计时考虑周到。


org.springframework.security.authentication.event.AbstractAuthenticationEvent是共同的基础类型,代表了验证授权事件用于和其他种类的事件区别开来。


AbstractAuthenticationFailureEvent 在验证过程中发生异常会触发此类事件(抽象类型),

AuthenticationFailureBadCredentialsEvent(提供的凭据是错误的,用户名或者密码错误) 

AuthenticationFailureCredentialsExpiredEvent(验证通过了,但是密码已经过期) 

AuthenticationFailureDisabledEvent(验证过了但是账户被禁用)

AuthenticationFailureExpiredEvent(账户过期),

AuthenticationFailureLockedEvent(账户被锁定),

AuthenticationFailureProviderNotFoundEvent(配置错误,没有合适的AuthenticationProvider来处理登录验证)

AuthenticationFailureProxyUntrustedEvent(代理不受信任,用于Oauth、CAS这类三方验证的情形,多属于配置错误), 

AuthenticationFailureServiceExceptionEvent(其他任何在AuthenticationManager中发生的异常都会被封装成此类,表示服务器500错误)

AuthenticationSuccessEvent(用户通过输入用户名和密码登录成功), 

AuthenticationSwitchUserEvent(通过切换用户的手段来登录), 

InteractiveAuthenticationSuccessEvent,(同样是登录成功,但表示通过自动交互的手段来登录成功,比如cookie自动登录) 

SessionFixationProtectionEvent(当发生session fixation 攻击时触发的事件)


转载于:https://my.oschina.net/lxbzj/blog/325186

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值