From 8ddbb767de88bb8b329aec131ee1dd66334ae2b6 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Fri, 29 Nov 2024 19:14:24 +0000 Subject: [PATCH] Remove use of Json in JWT and OIDC test security --- .../jwt/JwtTestSecurityIdentityAugmentor.java | 7 ++++--- .../oidc/OidcTestSecurityIdentityAugmentor.java | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test-framework/security-jwt/src/main/java/io/quarkus/test/security/jwt/JwtTestSecurityIdentityAugmentor.java b/test-framework/security-jwt/src/main/java/io/quarkus/test/security/jwt/JwtTestSecurityIdentityAugmentor.java index 76ffc96107f76..37daec6611321 100644 --- a/test-framework/security-jwt/src/main/java/io/quarkus/test/security/jwt/JwtTestSecurityIdentityAugmentor.java +++ b/test-framework/security-jwt/src/main/java/io/quarkus/test/security/jwt/JwtTestSecurityIdentityAugmentor.java @@ -1,5 +1,7 @@ package io.quarkus.test.security.jwt; +import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider; + import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collections; @@ -7,7 +9,6 @@ import java.util.Set; import java.util.stream.Collectors; -import jakarta.json.Json; import jakarta.json.JsonValue; import org.eclipse.microprofile.jwt.Claims; @@ -79,9 +80,9 @@ private Object wrapValue(Claim claim, Object convertedClaimValue) { Claims claimType = getClaimType(claim.key()); if (Claims.UNKNOWN == claimType) { if (convertedClaimValue instanceof Long) { - return Json.createValue((Long) convertedClaimValue); + return jsonProvider().createValue((Long) convertedClaimValue); } else if (convertedClaimValue instanceof Integer) { - return Json.createValue((Integer) convertedClaimValue); + return jsonProvider().createValue((Integer) convertedClaimValue); } else if (convertedClaimValue instanceof Boolean) { return (Boolean) convertedClaimValue ? JsonValue.TRUE : JsonValue.FALSE; } diff --git a/test-framework/security-oidc/src/main/java/io/quarkus/test/security/oidc/OidcTestSecurityIdentityAugmentor.java b/test-framework/security-oidc/src/main/java/io/quarkus/test/security/oidc/OidcTestSecurityIdentityAugmentor.java index 482300394a8a5..e5d9d805a32bb 100644 --- a/test-framework/security-oidc/src/main/java/io/quarkus/test/security/oidc/OidcTestSecurityIdentityAugmentor.java +++ b/test-framework/security-oidc/src/main/java/io/quarkus/test/security/oidc/OidcTestSecurityIdentityAugmentor.java @@ -1,5 +1,7 @@ package io.quarkus.test.security.oidc; +import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider; + import java.lang.annotation.Annotation; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; @@ -8,7 +10,6 @@ import java.util.UUID; import java.util.stream.Collectors; -import jakarta.json.Json; import jakarta.json.JsonArray; import jakarta.json.JsonObjectBuilder; @@ -63,10 +64,10 @@ public SecurityIdentity augment(final SecurityIdentity identity, final Annotatio if (!introspectionRequired) { // JsonWebToken - JsonObjectBuilder claims = Json.createObjectBuilder(); + JsonObjectBuilder claims = jsonProvider().createObjectBuilder(); claims.add(Claims.preferred_username.name(), identity.getPrincipal().getName()); claims.add(Claims.groups.name(), - Json.createArrayBuilder(identity.getRoles().stream().collect(Collectors.toList())).build()); + jsonProvider().createArrayBuilder(identity.getRoles().stream().collect(Collectors.toList())).build()); if (oidcSecurity != null && oidcSecurity.claims() != null) { for (Claim claim : oidcSecurity.claims()) { Object claimValue = convertClaimValue(claim); @@ -99,7 +100,7 @@ public SecurityIdentity augment(final SecurityIdentity identity, final Annotatio builder.addCredential(idToken); builder.addCredential(accessToken); } else { - JsonObjectBuilder introspectionBuilder = Json.createObjectBuilder(); + JsonObjectBuilder introspectionBuilder = jsonProvider().createObjectBuilder(); introspectionBuilder.add(OidcConstants.INTROSPECTION_TOKEN_ACTIVE, true); introspectionBuilder.add(OidcConstants.INTROSPECTION_TOKEN_USERNAME, identity.getPrincipal().getName()); introspectionBuilder.add(OidcConstants.TOKEN_SCOPE, @@ -118,7 +119,7 @@ public SecurityIdentity augment(final SecurityIdentity identity, final Annotatio // UserInfo if (oidcSecurity != null && oidcSecurity.userinfo() != null) { - JsonObjectBuilder userInfoBuilder = Json.createObjectBuilder(); + JsonObjectBuilder userInfoBuilder = jsonProvider().createObjectBuilder(); for (UserInfo userinfo : oidcSecurity.userinfo()) { userInfoBuilder.add(userinfo.key(), userinfo.value()); }