Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ public void setUserDetailsPasswordService(ReactiveUserDetailsPasswordService use
this.userDetailsPasswordService = userDetailsPasswordService;
}

/**
* Sets the strategy which will be used to validate the loaded <tt>UserDetails</tt>
* object before authentication occurs.
* @param preAuthenticationChecks The {@link UserDetailsChecker}
* @since 7.1
*/
public void setPreAuthenticationChecks(UserDetailsChecker preAuthenticationChecks) {
Assert.notNull(preAuthenticationChecks, "preAuthenticationChecks cannot be null");
this.preAuthenticationChecks = preAuthenticationChecks;
}

/**
* Sets the strategy which will be used to validate the loaded <tt>UserDetails</tt>
* object after authentication occurs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public class UserDetailsRepositoryReactiveAuthenticationManagerTests {
@Mock
private Scheduler scheduler;

@Mock
private UserDetailsChecker preAuthenticationChecks;

@Mock
private UserDetailsChecker postAuthenticationChecks;

Expand Down Expand Up @@ -149,6 +152,25 @@ public void authenticateWhenPasswordServiceAndUpgradeFalseThenNotUpdated() {
verifyNoMoreInteractions(this.userDetailsPasswordService);
}

@Test
public void setPreAuthenticationChecksWhenNullThenIllegalArgumentException() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> this.manager.setPreAuthenticationChecks(null));
}

@Test
public void authenticateWhenPreAuthenticationChecksFail() {
given(this.userDetailsService.findByUsername(any())).willReturn(Mono.just(this.user));
willThrow(new LockedException("account is locked")).given(this.preAuthenticationChecks).check(any());
this.manager.setPreAuthenticationChecks(this.preAuthenticationChecks);
assertThatExceptionOfType(LockedException.class)
.isThrownBy(() -> this.manager
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated(this.user, this.user.getPassword()))
.block())
.withMessage("account is locked");
verify(this.preAuthenticationChecks).check(eq(this.user));
}

@Test
public void authenticateWhenPostAuthenticationChecksFail() {
given(this.userDetailsService.findByUsername(any())).willReturn(Mono.just(this.user));
Expand Down
Loading