Поэтому я пытаюсь перенаправить Spring Security на мою страницу входа в систему, используя следующую конфигурацию.Он попытался перенаправить на / login, однако я обнаружил, что страница с ошибкой не найдена.
@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");
}
}
Чтобы убедиться, что сервер всегда использует index.html для отображения угловых страниц, я выполнил следующую конфигурацию:
@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;
}
});;
}
На этот раз сервер не перенаправил на страницу входа.Вместо этого появляется диалоговое окно по умолчанию для ввода имени пользователя и пароля.