Анонимные запросы с помощью Spring Webflux Security - PullRequest
0 голосов
/ 02 июня 2018

Я пытаюсь использовать Spring Webfux Security для защиты пути в SPA.Защищаемый путь - «/ ** / orderbook», а все остальные пути должны быть открыты для анонимного доступа.Как мне настроить Spring Security для этого?В настоящее время он всегда запрашивает логин, а не только защищаемый путь.

My Webflux Config:

@Bean       
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception {     

    return http
            .csrf().disable()
            .httpBasic().disable()
            .formLogin().disable()
            .logout().disable()
            .securityContextRepository(this.jwtSecContextRepository)
            .authorizeExchange()
            .pathMatchers("/**/orderbook").authenticated()
            .anyExchange().permitAll()
            .and().build();
     }
}

JwtSecContextRepository выглядит следующим образом:

    @Component
public class JwtSecurityContextRepository implements ServerSecurityContextRepository {

    @Override
    public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
        return null;
    }

    @Override
    public Mono<SecurityContext> load(ServerWebExchange exchange) {
        LinkedList<SimpleGrantedAuthority> linkedList = new LinkedList<>();
        linkedList.add(new SimpleGrantedAuthority("USERS"));
        Authentication auth = new JwtAuthenticationToken("user", "password", linkedList);           
        return Mono.just(new SecurityContextImpl(auth));
    }

}

Мне не хватает такой функции, как анонимный доступ.SecurityContextRepository пытается обеспечить это, но безуспешно.Мне кажется, что SecurityContextRepository не имеет никакого эффекта вообще.

У кого-нибудь есть идеи?

...