use of io.helidon.common.Errors in project helidon by oracle.
the class MessagingCdiExtension method deploymentValidation.
private void deploymentValidation(@Observes AfterDeploymentValidation event) {
Errors.Collector errors = channelRouter.getErrors();
boolean hasFatal = errors.hasFatal();
Errors errorMessages = errors.collect();
if (hasFatal) {
throw new DeploymentException(errorMessages.toString());
} else {
errorMessages.log(LOGGER);
}
}
use of io.helidon.common.Errors in project helidon by oracle.
the class JwtTest method testOidcJwt.
@Test
public void testOidcJwt() {
String audience = "id_of_audience";
String subject = "54564645646465";
String username = "jarda@jarda.com";
String issuer = "I am issuer";
Instant now = Instant.now();
Instant expiration = now.plus(1, ChronoUnit.HOURS);
Instant notBefore = now.minus(2, ChronoUnit.SECONDS);
Jwt jwt = Jwt.builder().jwtId(UUID.randomUUID().toString()).addScope("link").addScope("lank").addScope("lunk").subject(subject).preferredUsername(username).algorithm(JwkRSA.ALG_RS256).audience(audience).issuer(issuer).issueTime(now).expirationTime(expiration).notBefore(notBefore).build();
assertThat(jwt.scopes(), is(Optional.of(List.of("link", "lank", "lunk"))));
assertThat(jwt.subject(), is(Optional.of(subject)));
assertThat(jwt.preferredUsername(), is(Optional.of(username)));
assertThat(jwt.issueTime(), is(Optional.of(now)));
assertThat(jwt.expirationTime(), is(Optional.of(expiration)));
assertThat(jwt.notBefore(), is(Optional.of(notBefore)));
// and this one should be valid
List<Validator<Jwt>> vals = Jwt.defaultTimeValidators();
Jwt.addIssuerValidator(vals, issuer, true);
Jwt.addAudienceValidator(vals, audience, true);
Errors errors = jwt.validate(vals);
errors.log(LOGGER);
errors.checkValid();
// another try with defaults
errors = jwt.validate(issuer, audience);
errors.log(LOGGER);
errors.checkValid();
}
use of io.helidon.common.Errors in project helidon by oracle.
the class SignedJwtTest method testParsingNoSignature.
@Test
public void testParsingNoSignature() {
SignedJwt signedJwt = SignedJwt.parseToken(NO_SIGNATURE_TOKEN);
assertThat(signedJwt.getSignature(), notNullValue());
assertThat(signedJwt.getSignedBytes(), notNullValue());
assertThat(signedJwt.getSignature(), is(new byte[0]));
assertThat(signedJwt.tokenContent(), is(NO_SIGNATURE_TOKEN));
Errors errors = signedJwt.verifySignature(null, Jwk.NONE_JWK);
assertThat(errors, notNullValue());
errors.log(LOGGER);
errors.checkValid();
}
use of io.helidon.common.Errors in project helidon by oracle.
the class SignedJwtTest method testSignature.
@Test
public void testSignature() {
Jwt jwt = Jwt.builder().algorithm("RS256").keyId("cc34c0a0-bd5a-4a3c-a50d-a2a7db7643df").issuer("unit-test").build();
SignedJwt signed = SignedJwt.sign(jwt, customKeys);
assertThat(signed, notNullValue());
assertThat(signed.getSignature(), notNullValue());
assertThat(signed.getSignature(), not(new byte[0]));
Errors errors = signed.verifySignature(customKeys);
assertThat(errors, notNullValue());
errors.checkValid();
}
use of io.helidon.common.Errors in project helidon by oracle.
the class SignedJwtTest method testSignatureNone.
@Test
public void testSignatureNone() {
Jwt jwt = Jwt.builder().algorithm("none").issuer("unit-test").build();
Jwk defaultJwk = Jwk.NONE_JWK;
SignedJwt signed = SignedJwt.sign(jwt, customKeys);
assertThat(signed, notNullValue());
assertThat(signed.getSignature(), notNullValue());
assertThat(signed.getSignature(), is(new byte[0]));
Errors errors = signed.verifySignature(customKeys, defaultJwk);
assertThat(errors, notNullValue());
errors.log(LOGGER);
errors.checkValid();
}
Aggregations