从AuthenticationSuccessEvent

时间:2019-02-22 17:56:38

标签: java spring spring-security oauth-2.0

我正在尝试从客户端获取远程地址,并且出现强制错误

2019-02-22 18:54:05.104  WARN 21028 --- [nio-8080-exec-1] o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: ClassCastException, class java.util.LinkedHashMap cannot be cast to class org.springframework.security.web.authentication.WebAuthenticationDetails (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.springframework.security.web.authentication.WebAuthenticationDetails is in unnamed module of loader 'app')

方法是这样的:

@Autowired
private LoginAttemptService loginAttemptService;

public void onApplicationEvent(AuthenticationSuccessEvent e){
    WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
    loginAttemptService.loginSucceeded(auth.getRemoteAddress());
}

.getDetails()方法仅返回用户名和grant_type。 该对象中没有远程地址。 我在这里遵循此指南:https://www.baeldung.com/spring-security-block-brute-force-authentication-attempts

0 个答案:

没有答案