use of org.springframework.security.oauth2.core.OAuth2TokenValidatorResult in project spring-security by spring-projects.
the class NimbusJwtDecoder method validateJwt.
private Jwt validateJwt(Jwt jwt) {
OAuth2TokenValidatorResult result = this.jwtValidator.validate(jwt);
if (result.hasErrors()) {
Collection<OAuth2Error> errors = result.getErrors();
String validationErrorString = getJwtValidationExceptionMessage(errors);
throw new JwtValidationException(validationErrorString, errors);
}
return jwt;
}
use of org.springframework.security.oauth2.core.OAuth2TokenValidatorResult in project spring-security by spring-projects.
the class NimbusReactiveJwtDecoderTests method decodeWhenReadingErrorPickTheFirstErrorMessage.
@Test
public void decodeWhenReadingErrorPickTheFirstErrorMessage() {
OAuth2TokenValidator<Jwt> jwtValidator = mock(OAuth2TokenValidator.class);
this.decoder.setJwtValidator(jwtValidator);
OAuth2Error errorEmpty = new OAuth2Error("mock-error", "", "mock-uri");
OAuth2Error error = new OAuth2Error("mock-error", "mock-description", "mock-uri");
OAuth2Error error2 = new OAuth2Error("mock-error-second", "mock-description-second", "mock-uri-second");
OAuth2TokenValidatorResult result = OAuth2TokenValidatorResult.failure(errorEmpty, error, error2);
given(jwtValidator.validate(any(Jwt.class))).willReturn(result);
// @formatter:off
assertThatExceptionOfType(JwtValidationException.class).isThrownBy(() -> this.decoder.decode(this.messageReadToken).block()).withMessageContaining("mock-description");
// @formatter:on
}
use of org.springframework.security.oauth2.core.OAuth2TokenValidatorResult in project spring-security by spring-projects.
the class JwtIssuerValidatorTests method validateWhenIssuerUrlMismatchesThenReturnsError.
@Test
public void validateWhenIssuerUrlMismatchesThenReturnsError() throws MalformedURLException {
Jwt jwt = TestJwts.jwt().claim(JwtClaimNames.ISS, new URL("https://other")).build();
OAuth2TokenValidatorResult result = this.validator.validate(jwt);
assertThat(result.getErrors()).isNotEmpty();
}
use of org.springframework.security.oauth2.core.OAuth2TokenValidatorResult in project spring-security by spring-projects.
the class JwtIssuerValidatorTests method validateWhenJwtHasNoIssuerThenReturnsError.
@Test
public void validateWhenJwtHasNoIssuerThenReturnsError() {
Jwt jwt = TestJwts.jwt().claim(JwtClaimNames.AUD, "https://aud").build();
OAuth2TokenValidatorResult result = this.validator.validate(jwt);
assertThat(result.getErrors()).isNotEmpty();
}
use of org.springframework.security.oauth2.core.OAuth2TokenValidatorResult in project spring-security by spring-projects.
the class JwtIssuerValidatorTests method validateWhenIssuerMismatchesThenReturnsError.
@Test
public void validateWhenIssuerMismatchesThenReturnsError() {
Jwt jwt = TestJwts.jwt().claim(JwtClaimNames.ISS, "https://other").build();
OAuth2TokenValidatorResult result = this.validator.validate(jwt);
assertThat(result.getErrors()).isNotEmpty();
}
Aggregations