- : REST API с несколькими сопоставлениями запросов с выводом JSON.
Код: Выделить всё
/app/endpoint - : Сопоставление HTML-страницы входа в систему (пока только фиктивный контент, для тестирования).
Код: Выделить всё
/app/login - : Сопоставление главной страницы HTML (пока только фиктивный контент для тестирования).
Код: Выделить всё
/app/index
Код: Выделить всё
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager =
new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("admin").
password("{noop}admin").roles("ADMIN")
.build());
manager.createUser(User.withUsername("user").
password("{noop}user").roles("USER")
.build());
return manager;
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring()
.requestMatchers("/app/endpoint/**");
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http)
throws Exception {
http.authorizeHttpRequests((a) ->
a.requestMatchers("/app/endpoint/**").permitAll()
.requestMatchers("/app/login", "/app/index")
.hasAnyRole("ADMIN", "USER")
.anyRequest().authenticated()
).httpBasic(withDefaults());
return http.build();
}
}
Код: Выделить всё
/app/endpoint/**Код: Выделить всё
$ curl -k -I https://localhost:8443/app/login
HTTP/1.1 401
WWW-Authenticate: Basic realm="Realm"
(... other headers...)
$ curl -k -I https://localhost:8443/app/endpoint/list
HTTP/1.1 401
WWW-Authenticate: Basic realm="Realm"
(... other headers...)
Подробнее здесь: https://stackoverflow.com/questions/798 ... urls-and-p
Мобильная версия