One Time Token with custom configuration

Here is the example of the one time token in spring security with custom configuration.

This is the custom one time token implementation with some own configurations.

  1. AppUser-

    1. Entity that stores the user basic information.

  2. OneTimeToken-

    1. Entity that stores one time token information, like name, expiration etc.

  3. CustomUserDetailsService-

    1. UserDetailsService implementation that fetches users from that database and returns a UserDetails (I) which has the implementation AppUser.

  4. SecurityConfig-

    1. The default submit page url and token generation urls are the same, but after token validation we are directing to /login/ott/success that returns the secure page.

  5. JDBCTokenGeneratorService-

    1. This is the custom token generation service, which is responsible for generating tokens and validating them.

    2. It is inspired from original JDBCTokenGeneratorService, just the expiry time has been increased from 5 to 15 minutes.

    3. It also has the cron jobs that clears token automatically.

  6. OneTimeTokenSuccessHandler-

    1. In this class, after token generation token are being sent to username, for that first user is being fetched from the database using a custom user details service

pom.xml

application.properties

AppUser entity

OneTimeToken entity

Security Configuration

OneTimeTokenSuccessHandler

UserDetailsService

rest of the details like controller and html pages are the same as previous one.

Last updated