Search in sources :

Example 1 with Errors

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);
    }
}
Also used : Errors(io.helidon.common.Errors) DeploymentException(jakarta.enterprise.inject.spi.DeploymentException)

Example 2 with Errors

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();
}
Also used : Errors(io.helidon.common.Errors) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 3 with Errors

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();
}
Also used : Errors(io.helidon.common.Errors) Test(org.junit.jupiter.api.Test)

Example 4 with Errors

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();
}
Also used : Errors(io.helidon.common.Errors) Test(org.junit.jupiter.api.Test)

Example 5 with Errors

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();
}
Also used : Errors(io.helidon.common.Errors) Jwk(io.helidon.security.jwt.jwk.Jwk) Test(org.junit.jupiter.api.Test)

Aggregations

Errors (io.helidon.common.Errors)12 Test (org.junit.jupiter.api.Test)6 Jwk (io.helidon.security.jwt.jwk.Jwk)4 Jwt (io.helidon.security.jwt.Jwt)2 SignedJwt (io.helidon.security.jwt.SignedJwt)2 LinkedList (java.util.LinkedList)2 HelidonServiceLoader (io.helidon.common.serviceloader.HelidonServiceLoader)1 Config (io.helidon.config.Config)1 Configured (io.helidon.config.metadata.Configured)1 ConfiguredOption (io.helidon.config.metadata.ConfiguredOption)1 AuthorizationResponse (io.helidon.security.AuthorizationResponse)1 EndpointConfig (io.helidon.security.EndpointConfig)1 ProviderRequest (io.helidon.security.ProviderRequest)1 SecurityLevel (io.helidon.security.SecurityLevel)1 SecurityResponse (io.helidon.security.SecurityResponse)1 Subject (io.helidon.security.Subject)1 JwtException (io.helidon.security.jwt.JwtException)1 JwkEC (io.helidon.security.jwt.jwk.JwkEC)1 JwkRSA (io.helidon.security.jwt.jwk.JwkRSA)1 AbacValidator (io.helidon.security.providers.abac.spi.AbacValidator)1