Страница Login в Spring Security не вызывается для входящего USER
Дорогие форумчане Java Не могу понять логику регистрации в Spring Security Я делаю так:
1. Создаю класс реализующий WebSecurityConfigurerAdapter
@Configuration
@EnableWebSecurity
//@EnableGlobalMethodSecurity (prePostEnabled=true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user") // #1
.password("password")
.roles("USER")
.and()
.withUser("admin") // #2
.password("password")
.roles("ADMIN","USER");
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**"); // #3
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/login.html")
.failureUrl("/login-error.html")
.and()
.logout()
.logoutSuccessUrl("/index.html");
}
}
2. Регистрирую данный класс
public class SpringWebAppInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {DaraServisConfig.class, WebSecurityConfig.class};
//return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {ASdf.class};
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
3. Представление вывожу так
@Configuration
@ComponentScan(basePackages = { "com.vokmar" })
@EnableWebMvc
public class ASdf implements WebMvcConfigurer {
@Autowired
ApplicationContext applicationContext;
//1. Creating SpringResourceTemplateResolver
@Bean
public SpringResourceTemplateResolver springTemplateResolver(){
SpringResourceTemplateResolver springTemplateResolver = new SpringResourceTemplateResolver();
springTemplateResolver.setApplicationContext(this.applicationContext);
springTemplateResolver.setPrefix("/WEB-INF/pages/");
springTemplateResolver.setSuffix(".html");
springTemplateResolver.setTemplateMode(TemplateMode.HTML);
springTemplateResolver.setCharacterEncoding("UTF-8");
return springTemplateResolver;
}
//2. Creating SpringTemplateEngine
@Bean
public SpringTemplateEngine springTemplateEngine(){
SpringTemplateEngine springTemplateEngine = new SpringTemplateEngine();
springTemplateEngine.setTemplateResolver(springTemplateResolver());
return springTemplateEngine;
}
//3. Registering ThymeleafViewResolver
@Bean
public ViewResolver viewResolver(){
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(springTemplateEngine());
viewResolver.setCharacterEncoding("UTF-8");
viewResolver.setContentType("text/html; charset=UTF-8");
return viewResolver;
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//registry.addViewController("/login").setViewName("login");
}
}
4. Главная страница
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8" />
<title>Welcome</title>
</head>
<body>
<h1>Приветствую!</h1>
<div th:replace="~{fragment/meny :: meny}"></div> // тут ссылка на закрытый раздел
</body>
</html>
5. Закрытый раздел /ок
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>ОК</h1>
<div th:replace="~{fragment/meny :: meny}">
ДАварпвыиdfbdfbd
</div>
<div th:each="v : ${vendor}">
<a th:href="@{'/edit?id='+${v.id}}"> <div th:text=${v.name}></div></a>
</div>
</body>
</html>
6. Контроллер
@Controller
public class HelloWorldController {
@Autowired
private VendorServise sv;
@RequestMapping("/login.html")
public String log() {
return "login";
}
@RequestMapping("/login-error.html")
public String loginError(Model model) {
model.addAttribute("loginError", true);
return "login.html";
}
Что я делаю не так, почему при нажатии на ссылку ведущую на закрытый раздел сайта страница login не выводится.