I have controller which handles request to / and returns corresponding jsp. After switching to annotation based configuration and adding Spring security I got HTTP 404 when log in is successful. It seems to me like all config is in place. What's wrong?
AppConfig
@EnableWebMvc
@Configuration
@ComponentScan({"app.controller.*"})
@Import({SecurityConfig.class})
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class AppConfig {
@Bean
public InternalResourceViewResolver viewResolver(){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/pages");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");
}
SecurityConfig
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers("/**").access("hasRole('ROLE_ADMIN')")
.and().formLogin();
}
}
SpringMvcInitializer
public class SpringMvcInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{AppConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
Controller
@Controller
@RequestMapping("/")
public class AppController {
@RequestMapping(value = "/", method= RequestMethod.GET)
public String getRequestPage(Model model){ .....}
}
UPDATE
changing in SpringMvcInitializer to following code didn't help:
@Override
protected String[] getServletMappings() {
return new String[]{"/*"};
}
UPDATE2:
for some reason IntelliJ shows that it cannot autowire bean AuthenticationManager in SecurityConfig class
UPDATE3
I removed any Deployment descriptors in Facets (it still suggests to create web.xml but I think I don't need it since I configure Spring only by code). Right?