Включил WebSecurity, добавив следующий класс.
@EnableWebSecurity
@Configuration
public class AppWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user")
.password("user").roles("USER").and().withUser("admin")
.password("admin").roles("ADMIN", "USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/public/**").permitAll().anyRequest()
.fullyAuthenticated().and().formLogin().loginPage("/login").defaultSuccessUrl("/home")
.failureUrl("/login?error").permitAll().and().logout().permitAll();
}
Добавлен новый контроллер входа
@Controller
public class SecurityLoginController {
@GetMapping(value = "/login")
public String loginPage(Model model) {
return "login";
}
/**
*
* @param model
* @return String
*/
@GetMapping("/home")
public String showHome(Model model) {
return "index";
}
}
Когда я захожу в приложение, страница входа отображается правильно.Когда я ввожу действительный идентификатор пользователя и пароль, вместо индекса / домашней страницы отображается следующий URL
http://localhost:8080/webjars/momentjs/2.13.0/min/moment.min.js
Когда я возвращаюсь и снова нажимаю на URL http://localhost:9100,показывает правильный индекс / домашнюю страницу (вход выполнен успешно)