Skip to content

Commit

Permalink
Merge pull request #44836 from sberyozkin/remove_json_in_test_security
Browse files Browse the repository at this point in the history
Remove use of Json in JWT and OIDC test security
  • Loading branch information
sberyozkin authored Nov 29, 2024
2 parents ca98b70 + 8ddbb76 commit e3ab6bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import jakarta.json.Json;
import jakarta.json.JsonValue;

import org.eclipse.microprofile.jwt.Claims;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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());
}
Expand Down

0 comments on commit e3ab6bd

Please sign in to comment.