我在百里香应用中使用弹簧靴2
我创建了一个用于身份验证的类配置
@Configuration
public class AuthenticationConfig {
@Bean
public AuthenticationSuccessEventListener asel() {
return new AuthenticationSuccessEventListener();
}
@Bean
public AuthenticationFailureListener afel() {
return new AuthenticationFailureListener();
}
}
我为这些bean创建了两个类
@Component
public class AuthenticationFailureListener implements ApplicationListener<AuthenticationFailureBadCredentialsEvent> {
@Autowired
private LoginAttemptService loginAttemptService;
@Override
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent e) {
...
}
}
@Component
public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> {
@Autowired
private LoginAttemptService loginAttemptService;
@Override
public void onApplicationEvent(AuthenticationSuccessEvent e) {
...
}
}
从不调用两个侦听器(成功或失败)
有什么遗失的吗?
然后做同样的事情: http://www.baeldung.com/spring-security-block-brute-force-authentication-attempts