Skip to content

Commit f48a6e4

Browse files
Add public to setClock method in InMemoryOneTimeTokenService
Closes gh-15863
1 parent 9ba2435 commit f48a6e4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/src/main/java/org/springframework/security/authentication/ott/InMemoryOneTimeTokenService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ private boolean isExpired(OneTimeToken ott) {
7575
return this.clock.instant().isAfter(ott.getExpiresAt());
7676
}
7777

78-
void setClock(Clock clock) {
78+
/**
79+
* Sets the {@link Clock} used when generating one-time token and checking token
80+
* expiry.
81+
* @param clock the clock
82+
*/
83+
public void setClock(Clock clock) {
7984
Assert.notNull(clock, "clock cannot be null");
8085
this.clock = clock;
8186
}

core/src/test/java/org/springframework/security/authentication/ott/InMemoryOneTimeTokenServiceTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.junit.jupiter.api.Test;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3132
import static org.assertj.core.api.Assertions.assertThatNoException;
3233

3334
/**
@@ -100,6 +101,15 @@ void generateWhenMoreThan100TokensThenClearExpired() {
100101
// @formatter:on
101102
}
102103

104+
@Test
105+
void setClockWhenNullThenThrowIllegalArgumentException() {
106+
// @formatter:off
107+
assertThatIllegalArgumentException()
108+
.isThrownBy(() -> this.oneTimeTokenService.setClock(null))
109+
.withMessage("clock cannot be null");
110+
// @formatter:on
111+
}
112+
103113
private List<OneTimeToken> generate(int howMany) {
104114
List<OneTimeToken> generated = new ArrayList<>(howMany);
105115
for (int i = 0; i < howMany; i++) {

0 commit comments

Comments
 (0)