Authenticating users using the default login page

Spring makes it easy to quickly add a login page to your web application; just define some user credentials (usernames and passwords) in the security configuration class. To access any page, the user will have to go through Spring's default login page first.

Authenticating users using the default login page

How to do it…

In your security configuration class, add a configureUsers() method containing the hardcoded user credentials:

@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureUsers(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.