Instantiate exceptions lazily

Add lazy Exception instantiation to reduce allocations

Fixes gh-7995
This commit is contained in:
Roman Matiushchenko 2020-02-20 14:59:37 +02:00 committed by Josh Cummings
parent 727fee1e12
commit 04e671fb4d
1 changed files with 2 additions and 2 deletions

View File

@ -121,7 +121,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
return this.issuerConverter.convert(exchange)
.flatMap(issuer ->
this.issuerAuthenticationManagerResolver.resolve(issuer).switchIfEmpty(
Mono.error(new InvalidBearerTokenException("Invalid issuer " + issuer)))
Mono.error(() -> new InvalidBearerTokenException("Invalid issuer " + issuer)))
);
}
@ -142,7 +142,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
try {
String issuer = JWTParser.parse(token.getToken()).getJWTClaimsSet().getIssuer();
return Mono.justOrEmpty(issuer).switchIfEmpty(
Mono.error(new InvalidBearerTokenException("Missing issuer")));
Mono.error(() -> new InvalidBearerTokenException("Missing issuer")));
} catch (Exception e) {
return Mono.error(new InvalidBearerTokenException(e.getMessage()));
}