30.2 WebFlux 보안

Spring MVC 애플리케이션과 마찬가지로, spring-boot-starter-security종속성 을 추가하여 WebFlux 애플리케이션을 보호 할 수 있습니다 . 기본 보안 구성은 ReactiveSecurityAutoConfigurationUserDetailsServiceAutoConfiguration에서 구현 됩니다. ReactiveSecurityAutoConfiguration은 웹 보안을 위해 WebFluxSecurityConfiguration 가져오고 UserDetailsServiceAutoConfiguration 인증을 구성하며 비 웹 응용 프로그램과도 관련이 있습니다. 기본 웹 응용 프로그램 보안 구성을 완전히 끄려면 WebFilterChainProxyUserDetailsService 유형의 빈을 추가하면됩니다 ( 구성 또는 액추에이터의 보안이 비활성화되지 않음 ).

또한 UserDetailsService설정을 끄려면, ReactiveUserDetailsService또는 ReactiveAuthenticationManager 타의 빈을 추가 할 수 있습니다.

액세스 규칙은 사용자 지정 SecurityWebFilterChain을 추가하여 구성 할 수 있습니다. 스프링 부트는 액츄에이터 끝점 및 정적 리소스에 대한 액세스 규칙을 무시하는 데 사용할 수있는 편리한 방법을 제공합니다. EndpointRequest을 사용하여 management.endpoints.web.base-path속성을 기반으로 하는 ServerWebExchangeMatcher를 작성할 수 있습니다.

PathRequest는 일반적으로 사용되는 위치의 리소스에 대한 ServerWebExchangeMatcher 를 만드는데 사용할 수 있습니다 .

예를 들어, 다음과 같이 추가하여 보안 구성을 사용자 정의 할 수 있습니다.

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
	return http
		.authorizeExchange()
			.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
			.pathMatchers("/foo", "/bar")
				.authenticated().and()
			.formLogin().and()
		.build();
}

Last updated