【问题标题】:spring security core plugin 4.0.3 recording the failed attemptsspring security core plugin 4.0.3 记录失败的尝试
【发布时间】:2021-06-21 19:09:17
【问题描述】:

我正在使用Grails 4.0.9spring security core grails plugin 4.0.3,我搜索了一种方法来捕获用户失败和成功的登录尝试,但我没有达到任何目标,有没有办法做到这一点?

【问题讨论】:

  • 您要保留这些数量并将它们保存在某个地方吗?
  • @JeffScottBrown 是的,我打算使用Google Guava github.com/google/guava

标签: grails spring-security


【解决方案1】:

您可以注册ApplicationListener,它监听AbstractAuthenticationFailureEvent 来处理失败的尝试,并在grails-app/conf/spring/resources.groovy 中注册相同的内容。如:

package com.objectcomputing.example

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.context.ApplicationListener
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent

@Slf4j
@CompileStatic
class LoginFailedAuthEventListener implements ApplicationListener<AbstractAuthenticationFailureEvent> {

    @Override
    void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
        final Object username = event.authentication.principal
        log.warn("Failed login attempt for username {}", username)
    }
}

https://grails-plugins.github.io/grails-spring-security-core/4.0.x/index.html#registeringEventListener阅读更多信息

请注意,上面的监听器非常基础,只记录信息,但你可以写任何你需要做的事情。

示例应用程序:https://github.com/puneetbehl/grails-spring-security-demo

【讨论】:

  • 我按照上面提到的做了,我能够捕获失败的尝试
猜你喜欢
  • 2013-11-21
  • 2016-08-12
  • 1970-01-01
  • 1970-01-01
  • 2020-08-31
  • 2014-07-14
  • 2014-11-26
  • 1970-01-01
相关资源
最近更新 更多