Browse Source

Instantiate exceptions lazily

Add lazy Exception instantiation to reduce allocations

Fixes gh-7995
pull/8032/head
Roman Matiushchenko 6 years ago committed by Josh Cummings
parent
commit
04e671fb4d
  1. 4
      oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/JwtIssuerReactiveAuthenticationManagerResolver.java

4
oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/JwtIssuerReactiveAuthenticationManagerResolver.java

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

Loading…
Cancel
Save