Получение RemoteAddress из AuthenticationSuccessEvent - PullRequest
0 голосов
/ 22 февраля 2019

Я пытаюсь получить удаленный адрес от клиента и получаю casterror

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...