我的应用程序使用 spring cloud oauth2 rest 和 angular 。
我的目标是使用spring server来限制登录失败的最大次数
angular2登录代码:
const body = "username=" + encodeURI(username) + "&password=" + encodeURI(password) +
"&grant_type=password&client_id=" + encodeURI(this.clientId);
this.http.post("/oauth/token",body,{headers:authHeaders}).map{
...
}
spring auth-server 网络安全代码:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeRequests()
.anyRequest().authenticated();
}
我尝试了这两个事件:
public class AuthenticationFailureListener
implements ApplicationListener<AuthenticationFailureBadCredentialsEvent>{
@Override
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent e) {
//...
}
}
和:
public class AuthenticationSuccessListener
implements ApplicationListener<AuthenticationSuccessEvent> {
@Override
public void onApplicationEvent(AuthenticationSuccessEvent e) {
//...
}
}
但它不起作用
如何收听“登录失败和成功”?