I used this one for login scenario using Spring Security for OTP based login.
https://stacknowledge.in/blogs/spring-security-custom-authencation-with-otp-based-login/