I set up a basic Spring Boot project with *.js and *.css resources. I activated Thymeleaf, Spring Web and Spring Security. Now:
- for the url: http://localhost:8080/ css and js files are being read properly
- for the url: http://localhost:8080/second css and js files are still being read properly
- for the url: http://localhost:8080/second/third the application does not load the css and js files
I'm guessing it has to do with Spring security. Can anyone point me to the right direction, how to I set up SecurityConfig.java class properly, so the application would read the files after additional "/" in the url? I am aware of those solutions, they don't work :( Isn't putting "/second/**" enough as antMatchers?
My classes:
HomeController.java
@Controller
public class HomeController {
@GetMapping("/")
public String goHome() {
return "index";
}
@GetMapping("/second")
public String goSecond() {
return "secondpage";
}
@GetMapping("/second/third")
public String goThird() {
return "thirdpage";
}
}
SecurityConfig.java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
throws Exception {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
auth.inMemoryAuthentication()
.withUser("demo")
.password(encoder.encode("demo"))
.roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/second", "second/**").access("hasRole('USER')")
.and()
.formLogin();
}
}
This is the project structure: