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.
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() .withUser("user1").password("pwd").roles("USER") .and() .withUser("admin").password("admin_pwd").roles("USER", "ADMIN"); } }