Search in sources :

Example 1 with ReactiveUserDetailsService

use of org.springframework.security.core.userdetails.ReactiveUserDetailsService in project spring-security by spring-projects.

the class ServerHttpSecurityConfigurationBuilder method httpWithDefaultAuthentication.

public static ServerHttpSecurity httpWithDefaultAuthentication() {
    ReactiveUserDetailsService reactiveUserDetailsService = ReactiveAuthenticationTestConfiguration.userDetailsService();
    ReactiveAuthenticationManager authenticationManager = new UserDetailsRepositoryReactiveAuthenticationManager(reactiveUserDetailsService);
    return http().authenticationManager(authenticationManager);
}
Also used : ReactiveAuthenticationManager(org.springframework.security.authentication.ReactiveAuthenticationManager) UserDetailsRepositoryReactiveAuthenticationManager(org.springframework.security.authentication.UserDetailsRepositoryReactiveAuthenticationManager) UserDetailsRepositoryReactiveAuthenticationManager(org.springframework.security.authentication.UserDetailsRepositoryReactiveAuthenticationManager) ReactiveUserDetailsService(org.springframework.security.core.userdetails.ReactiveUserDetailsService)

Example 2 with ReactiveUserDetailsService

use of org.springframework.security.core.userdetails.ReactiveUserDetailsService in project spring-security by spring-projects.

the class EnableWebFluxSecurityTests method passwordUpdateManagerUsed.

@Test
public void passwordUpdateManagerUsed() {
    this.spring.register(MapReactiveUserDetailsServiceConfig.class).autowire();
    // @formatter:off
    WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.springSecurityFilterChain).build();
    client.get().uri("/").headers((h) -> h.setBasicAuth("user", "password")).exchange().expectStatus().isOk();
    // @formatter:on
    ReactiveUserDetailsService users = this.spring.getContext().getBean(ReactiveUserDetailsService.class);
    assertThat(users.findByUsername("user").block().getPassword()).startsWith("{bcrypt}");
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AuthenticationPrincipalArgumentResolver(org.springframework.security.web.reactive.result.method.annotation.AuthenticationPrincipalArgumentResolver) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) User(org.springframework.security.core.userdetails.User) ServerHttpSecurity(org.springframework.security.config.web.server.ServerHttpSecurity) ReactiveSecurityContextHolder(org.springframework.security.core.context.ReactiveSecurityContextHolder) ReactiveUserDetailsService(org.springframework.security.core.userdetails.ReactiveUserDetailsService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) WebFilter(org.springframework.web.server.WebFilter) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) WebSessionServerSecurityContextRepository(org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository) ReactiveAuthenticationTestConfiguration(org.springframework.security.config.users.ReactiveAuthenticationTestConfiguration) MediaType(org.springframework.http.MediaType) RestController(org.springframework.web.bind.annotation.RestController) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) SecurityContext(org.springframework.security.core.context.SecurityContext) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BodyInserters(org.springframework.web.reactive.function.BodyInserters) Authentication(org.springframework.security.core.Authentication) CsrfRequestDataValueProcessor(org.springframework.security.web.reactive.result.view.CsrfRequestDataValueProcessor) Ordered(org.springframework.core.Ordered) SecurityMockServerConfigurers.csrf(org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) EnableWebFlux(org.springframework.web.reactive.config.EnableWebFlux) PathPatternParserServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher) UserDetails(org.springframework.security.core.userdetails.UserDetails) GetMapping(org.springframework.web.bind.annotation.GetMapping) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) WebTestClientBuilder(org.springframework.security.test.web.reactive.server.WebTestClientBuilder) MockServletContext(org.springframework.mock.web.MockServletContext) Order(org.springframework.core.annotation.Order) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) SecurityTestExecutionListeners(org.springframework.security.test.context.annotation.SecurityTestExecutionListeners) Import(org.springframework.context.annotation.Import) MultiValueMap(org.springframework.util.MultiValueMap) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) WebFilterChainProxy(org.springframework.security.web.server.WebFilterChainProxy) DelegatingWebFluxConfiguration(org.springframework.web.reactive.config.DelegatingWebFluxConfiguration) FluxExchangeResult(org.springframework.test.web.reactive.server.FluxExchangeResult) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) SecurityWebFilterChain(org.springframework.security.web.server.SecurityWebFilterChain) MapReactiveUserDetailsService(org.springframework.security.core.userdetails.MapReactiveUserDetailsService) SpringTestContext(org.springframework.security.config.test.SpringTestContext) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) SpringTestContextExtension(org.springframework.security.config.test.SpringTestContextExtension) AbstractView(org.springframework.web.reactive.result.view.AbstractView) Bean(org.springframework.context.annotation.Bean) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) ReactiveUserDetailsService(org.springframework.security.core.userdetails.ReactiveUserDetailsService) MapReactiveUserDetailsService(org.springframework.security.core.userdetails.MapReactiveUserDetailsService) Test(org.junit.jupiter.api.Test)

Aggregations

ReactiveUserDetailsService (org.springframework.security.core.userdetails.ReactiveUserDetailsService)2 StandardCharsets (java.nio.charset.StandardCharsets)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 Import (org.springframework.context.annotation.Import)1 Ordered (org.springframework.core.Ordered)1 Order (org.springframework.core.annotation.Order)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)1 MediaType (org.springframework.http.MediaType)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 ReactiveAuthenticationManager (org.springframework.security.authentication.ReactiveAuthenticationManager)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 UserDetailsRepositoryReactiveAuthenticationManager (org.springframework.security.authentication.UserDetailsRepositoryReactiveAuthenticationManager)1 SpringTestContext (org.springframework.security.config.test.SpringTestContext)1