У меня есть приложение с несколькими конечными точками REST и веб-страницами.
/products -- REST endpoint
/cutomers -- REST endpoint
/ui/catalog -- Web
/ui/admin -- Web
Я хочу настроить безопасность, чтобы все веб-страницы, начиная с /ui/**
, перенаправлялись на страницу входа и все другие (REST) вызывают 401 и WWW-Authenticate
.
При следующих настройках страница входа не разрешается, и отправляется 401 с заголовком:
@Configuration
@Order(20)
@RequiredArgsConstructor
class RestConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.requestMatcher(AnyRequestMatcher.INSTANCE)
.authorizeRequests().anyRequest().fullyAuthenticated();
httpSecurity.
requiresChannel().
requestMatchers(AnyRequestMatcher.INSTANCE).
requiresSecure();
}
}
@Configuration
@Order(10)
@RequiredArgsConstructor
class WebUIConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.antMatcher("/ui/**")
.authorizeRequests().anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().permitAll();
}
}
Почему это не так? т работаешь? Я ожидаю, что будет перенаправлен на страницу входа (это работает) и страница входа будет 200 (это не работает).