Spring Security Connection

Let's connect our User entity with Spring Security.

Establishing connection

We need two things to make the connection possible:

  • An implementation of the org.springframework.security.core.userdetails.UserDetailsService interface.

  • An implementation of the org.springframework.security.core.userdetails.UserDetails interface.

The UserDetailsService1 interface has a single method that takes a string. This parameter is the username or the email, depending on what users use to log on. The method returns an instance of UserDetails or throws an org.springframework.security.core.userdetails.UsernameNotFoundException if no user with the given username (or email) could be found:

Get hands-on with 1000+ tech skills courses.