Rename userDetailsRepository to userDetailsService
This commit is contained in:
parent
a4701bcd52
commit
f3830eec7d
|
@ -38,7 +38,7 @@ import java.lang.annotation.Target;
|
|||
* public class MyMinimalSecurityConfiguration {
|
||||
*
|
||||
* @Bean
|
||||
* public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
* public MapReactiveUserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
|
@ -66,7 +66,7 @@ import java.lang.annotation.Target;
|
|||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
* public MapReactiveUserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
|
|
|
@ -212,7 +212,7 @@ public class EnableWebFluxSecurityTests {
|
|||
@EnableWebFluxSecurity
|
||||
static class CustomPasswordEncoderConfig {
|
||||
@Bean
|
||||
public ReactiveUserDetailsService userDetailsRepository(PasswordEncoder encoder) {
|
||||
public ReactiveUserDetailsService userDetailsService(PasswordEncoder encoder) {
|
||||
return new MapReactiveUserDetailsService(User.withUsername("user")
|
||||
.password(encoder.encode("password"))
|
||||
.roles("USER")
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ServerHttpSecurityConfigurationBuilder {
|
|||
|
||||
public static ServerHttpSecurity httpWithDefaultAuthentication() {
|
||||
ReactiveUserDetailsService reactiveUserDetailsService = ReactiveAuthenticationTestConfiguration
|
||||
.userDetailsRepository();
|
||||
.userDetailsService();
|
||||
ReactiveAuthenticationManager authenticationManager = new UserDetailsRepositoryReactiveAuthenticationManager(
|
||||
reactiveUserDetailsService);
|
||||
return http()
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
|
|||
@Configuration
|
||||
public class ReactiveAuthenticationTestConfiguration {
|
||||
@Bean
|
||||
public static ReactiveUserDetailsService userDetailsRepository() {
|
||||
public static ReactiveUserDetailsService userDetailsService() {
|
||||
return new MapReactiveUserDetailsService(PasswordEncodedUser.user(), PasswordEncodedUser.admin());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,19 +30,19 @@ import reactor.core.scheduler.Schedulers;
|
|||
* @since 5.0
|
||||
*/
|
||||
public class UserDetailsRepositoryReactiveAuthenticationManager implements ReactiveAuthenticationManager {
|
||||
private final ReactiveUserDetailsService repository;
|
||||
private final ReactiveUserDetailsService userDetailsService;
|
||||
|
||||
private PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
|
||||
public UserDetailsRepositoryReactiveAuthenticationManager(ReactiveUserDetailsService reactiveUserDetailsService) {
|
||||
Assert.notNull(reactiveUserDetailsService, "userDetailsRepository cannot be null");
|
||||
this.repository = reactiveUserDetailsService;
|
||||
public UserDetailsRepositoryReactiveAuthenticationManager(ReactiveUserDetailsService userDetailsService) {
|
||||
Assert.notNull(userDetailsService, "userDetailsService cannot be null");
|
||||
this.userDetailsService = userDetailsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Authentication> authenticate(Authentication authentication) {
|
||||
final String username = authentication.getName();
|
||||
return this.repository.findByUsername(username)
|
||||
return this.userDetailsService.findByUsername(username)
|
||||
.publishOn(Schedulers.parallel())
|
||||
.filter( u -> this.passwordEncoder.matches((String) authentication.getCredentials(), u.getPassword()))
|
||||
.switchIfEmpty( Mono.error(new BadCredentialsException("Invalid Credentials")) )
|
||||
|
|
|
@ -56,9 +56,9 @@ public class ReactiveUserDetailsServiceAuthenticationManagerTests {
|
|||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullUserDetailsRepository() {
|
||||
ReactiveUserDetailsService udr = null;
|
||||
new UserDetailsRepositoryReactiveAuthenticationManager(udr);
|
||||
public void constructorNullUserDetailsService() {
|
||||
ReactiveUserDetailsService userDetailsService = null;
|
||||
new UserDetailsRepositoryReactiveAuthenticationManager(userDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -825,7 +825,7 @@ You can find a minimal WebFlux Security configuration below:
|
|||
public class HelloWebfluxSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("user")
|
||||
.password("user")
|
||||
|
@ -850,7 +850,7 @@ You can find an explicit version of the minimal WebFlux Security configuration b
|
|||
public class HelloWebfluxSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("user")
|
||||
.password("user")
|
||||
|
@ -1750,7 +1750,7 @@ Below is a minimal method security configuration when using method security in r
|
|||
@EnableReactiveMethodSecurity
|
||||
public class SecurityConfig {
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
User.UserBuilder userBuilder = User.withDefaultPasswordEncoder();
|
||||
UserDetails rob = userBuilder.username("rob").password("rob").roles("USER").build();
|
||||
UserDetails admin = userBuilder.username("admin").password("admin").roles("USER","ADMIN").build();
|
||||
|
@ -1798,7 +1798,7 @@ public class SecurityConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
MapReactiveUserDetailsService userDetailsRepository() {
|
||||
MapReactiveUserDetailsService userDetailsService() {
|
||||
User.UserBuilder userBuilder = User.withDefaultPasswordEncoder();
|
||||
UserDetails rob = userBuilder.username("rob").password("rob").roles("USER").build();
|
||||
UserDetails admin = userBuilder.username("admin").password("admin").roles("USER","ADMIN").build();
|
||||
|
|
|
@ -46,7 +46,7 @@ public class SecurityConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
User.UserBuilder userBuilder = User.withDefaultPasswordEncoder();
|
||||
UserDetails rob = userBuilder.username("rob").password("rob").roles("USER").build();
|
||||
UserDetails admin = userBuilder.username("admin").password("admin").roles("USER", "ADMIN").build();
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||
public class HelloWebfluxSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("user")
|
||||
.password("user")
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||
public class HelloWebfluxFnSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("user")
|
||||
.password("user")
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.springframework.security.web.server.SecurityWebFilterChain;
|
|||
public class WebfluxFormSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
public MapReactiveUserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("user")
|
||||
.password("password")
|
||||
|
|
Loading…
Reference in New Issue