Logging in new users using SecurityContextHolder
A common requirement is to allow users to create a new account and then automatically log them into the application. In this section, we’ll describe the simplest method for indicating that a user is authenticated, by utilizing SecurityContextHolder
.
Managing users in Spring Security
The application provided in Chapter 1, Anatomy of an Unsafe Application, provides a mechanism for creating a new CalendarUser
object, so it should be fairly easy to create our CalendarUser
object after a user signs up. However, Spring Security has no knowledge of CalendarUser
. This means that we will need to add a new user in Spring Security, too. Don’t worry, we will remove the need for the dual maintenance of users later in this chapter.
Spring Security provides an o.s.s.provisioning.UserDetailsManager
interface for managing users. Remember our in-memory Spring Security configuration?
auth.inMemoryAuthentication(). withUser("...