So I am trying to route spring security to my login page using the following config. It did try to route to /login, however I got that error page not found.
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest()
.authenticated()
.and()
.httpBasic()
.and().formLogin().loginPage("/login");
}
}
To make sure that the server always serves index.html to display the angular pages, I did the following config:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**/*.css", "/**/*.html", "/**/*.js")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("/", "/**")
.addResourceLocations("classpath:/static/index.html")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
if (resourcePath.startsWith("/api") || resourcePath.startsWith("/api".substring(1))) {
return null;
}
return location.exists() && location.isReadable() ? location : null;
}
});;
}
This time around, the server didn't route to login page. Instead, it pops up a default dialog to input user/password.