Skip to content

Commit b26f2af

Browse files
committed
Polish
Formatting as well as adding a missing defer Issue gh-15699
1 parent 2ca2e56 commit b26f2af

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

config/src/test/java/org/springframework/security/config/web/server/OneTimeTokenLoginSpecTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
292292
http
293293
.authorizeExchange((authorize) -> authorize
294294
.anyExchange()
295-
.authenticated())
295+
.authenticated()
296+
)
296297
.oneTimeTokenLogin((ott) -> ott
297298
.generatedOneTimeTokenHandler(new TestServerGeneratedOneTimeTokenHandler())
298299
);
@@ -314,7 +315,8 @@ SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) {
314315
http
315316
.authorizeExchange((authorize) -> authorize
316317
.anyExchange()
317-
.authenticated())
318+
.authenticated()
319+
)
318320
.oneTimeTokenLogin((ott) -> ott
319321
.generateTokenUrl("/generateurl")
320322
.generatedOneTimeTokenHandler(new TestServerGeneratedOneTimeTokenHandler("/redirected"))
@@ -339,7 +341,8 @@ SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) {
339341
http
340342
.authorizeExchange((authorize) -> authorize
341343
.anyExchange()
342-
.authenticated())
344+
.authenticated()
345+
)
343346
.formLogin(Customizer.withDefaults())
344347
.oneTimeTokenLogin((ott) -> ott
345348
.generatedOneTimeTokenHandler(new TestServerGeneratedOneTimeTokenHandler())
@@ -362,7 +365,8 @@ SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) {
362365
http
363366
.authorizeExchange((authorize) -> authorize
364367
.anyExchange()
365-
.authenticated())
368+
.authenticated()
369+
)
366370
.oneTimeTokenLogin(Customizer.withDefaults());
367371
// @formatter:on
368372
return http.build();

core/src/main/java/org/springframework/security/authentication/ott/reactive/OneTimeTokenReactiveAuthenticationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Mono<Authentication> authenticate(Authentication authentication) {
5454
return Mono.empty();
5555
}
5656
return this.oneTimeTokenService.consume(otpAuthenticationToken)
57-
.switchIfEmpty(Mono.error(new InvalidOneTimeTokenException("Invalid token")))
57+
.switchIfEmpty(Mono.defer(() -> Mono.error(new InvalidOneTimeTokenException("Invalid token"))))
5858
.flatMap((consumed) -> this.userDetailsService.findByUsername(consumed.getUsername()))
5959
.map(onSuccess(otpAuthenticationToken));
6060
}

web/src/main/java/org/springframework/security/web/server/authentication/ott/GenerateOneTimeTokenWebFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
5858
// @formatter:off
5959
return this.matcher.matches(exchange)
6060
.filter(ServerWebExchangeMatcher.MatchResult::isMatch)
61-
.flatMap((mathResult) -> exchange.getFormData())
62-
.flatMap((data) -> Mono.justOrEmpty(data.getFirst(USERNAME)))
61+
.switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
62+
.then(exchange.getFormData())
63+
.mapNotNull((data) -> data.getFirst(USERNAME))
6364
.switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
6465
.flatMap((username) -> this.oneTimeTokenService.generate(new GenerateOneTimeTokenRequest(username)))
6566
.flatMap((token) -> this.generatedOneTimeTokenHandler.handle(exchange, token));

0 commit comments

Comments
 (0)