I would like to set browser cookie value after login successfully. I am able to detect success login event with following code.
@Component
@Slf4j
public class LoginEventListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {
@Override
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
log.info("hahaha: " + event.toString());
}
}
答案 0 :(得分:2)
尝试将HttpServletRequest
对象自动装配到LoginEventListener
组件中,前提是您的组件在servlet容器中运行。
@Component
@Slf4j
public class LoginEventListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {
@Autowired
private HttpServletRequest request;
@Override
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
log.info("hahaha: " + event.toString());
log.info("Request Object: " + request); // You now have access to the HTTP request object.
}
}
答案 1 :(得分:1)
Tks,只是分享另一种方式来获得它。
foo