Skip to content

Commit

Permalink
Merge pull request quarkusio#44339 from geoand/oidc-json
Browse files Browse the repository at this point in the history
Remove use of Json in OIDC
  • Loading branch information
geoand authored Nov 6, 2024
2 parents 4865eae + b7e58d6 commit 4bb81a2
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@defaultMessage Don't jakarta.json.Json as it is ridiculously slow (see https://github.com/quarkusio/quarkus/issues/42748)
jakarta.json.Json
14 changes: 14 additions & 0 deletions extensions/oidc-client-registration/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<executions>
<execution>
<id>verify-forbidden-apis</id>
<configuration>
<signaturesFiles>
<signaturesFile>./banned-signatures.txt</signaturesFile>
</signaturesFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.quarkus.oidc.client.registration;

import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider;

import java.util.List;
import java.util.Map;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;

Expand Down Expand Up @@ -66,11 +67,11 @@ public static class Builder {
boolean built = false;

Builder() {
builder = Json.createObjectBuilder();
builder = jsonProvider().createObjectBuilder();
}

Builder(JsonObject json) {
builder = Json.createObjectBuilder(json);
builder = jsonProvider().createObjectBuilder(json);
}

public Builder clientName(String clientName) {
Expand All @@ -86,7 +87,7 @@ public Builder redirectUri(String redirectUri) {
throw new IllegalStateException();
}
builder.add(OidcConstants.CLIENT_METADATA_REDIRECT_URIS,
Json.createArrayBuilder().add(redirectUri).build());
jsonProvider().createArrayBuilder().add(redirectUri).build());
return this;
}

Expand All @@ -95,15 +96,15 @@ public Builder postLogoutUri(String postLogoutUri) {
throw new IllegalStateException();
}
builder.add(OidcConstants.CLIENT_METADATA_POST_LOGOUT_URIS,
Json.createArrayBuilder().add(postLogoutUri).build());
jsonProvider().createArrayBuilder().add(postLogoutUri).build());
return this;
}

public Builder extraProps(Map<String, String> extraProps) {
if (built) {
throw new IllegalStateException();
}
builder.addAll(Json.createObjectBuilder(extraProps));
builder.addAll(jsonProvider().createObjectBuilder(extraProps));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.quarkus.oidc.client.registration.runtime;

import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider;

import java.io.IOException;
import java.net.ConnectException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

import jakarta.json.Json;
import jakarta.json.JsonObjectBuilder;

import org.jboss.logging.Logger;
Expand Down Expand Up @@ -250,17 +251,17 @@ static class ClientRegistrationHelper {
}

static ClientMetadata createMetadata(Metadata metadata) {
JsonObjectBuilder json = Json.createObjectBuilder();
JsonObjectBuilder json = jsonProvider().createObjectBuilder();
if (metadata.clientName.isPresent()) {
json.add(OidcConstants.CLIENT_METADATA_CLIENT_NAME, metadata.clientName.get());
}
if (metadata.redirectUri.isPresent()) {
json.add(OidcConstants.CLIENT_METADATA_REDIRECT_URIS,
Json.createArrayBuilder().add(metadata.redirectUri.get()));
jsonProvider().createArrayBuilder().add(metadata.redirectUri.get()));
}
if (metadata.postLogoutUri.isPresent()) {
json.add(OidcConstants.POST_LOGOUT_REDIRECT_URI,
Json.createArrayBuilder().add(metadata.postLogoutUri.get()));
jsonProvider().createArrayBuilder().add(metadata.postLogoutUri.get()));
}
for (Map.Entry<String, String> entry : metadata.extraProps.entrySet()) {
json.add(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.quarkus.oidc.client.registration.runtime;

import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider;

import java.io.IOException;
import java.net.ConnectException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonValue;
Expand Down Expand Up @@ -94,7 +95,7 @@ public Uni<RegisteredClient> update(ClientMetadata newMetadata) {
throw new OidcClientRegistrationException("Client secret can not be modified");
}

JsonObjectBuilder builder = Json.createObjectBuilder();
JsonObjectBuilder builder = jsonProvider().createObjectBuilder();

JsonObject newJsonObject = newMetadata.getJsonObject();
JsonObject currentJsonObject = registeredMetadata.getJsonObject();
Expand Down
2 changes: 2 additions & 0 deletions extensions/oidc-common/runtime/banned-signatures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@defaultMessage Don't jakarta.json.Json as it is ridiculously slow (see https://github.com/quarkusio/quarkus/issues/42748)
jakarta.json.Json
14 changes: 14 additions & 0 deletions extensions/oidc-common/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<executions>
<execution>
<id>verify-forbidden-apis</id>
<configuration>
<signaturesFiles>
<signaturesFile>./banned-signatures.txt</signaturesFile>
</signaturesFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.quarkus.oidc.common.runtime;

import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonNumber;
import jakarta.json.JsonObject;
Expand All @@ -20,7 +21,7 @@ public abstract class AbstractJsonObject {
private JsonObject json;

protected AbstractJsonObject() {
json = Json.createObjectBuilder().build();
json = jsonProvider().createObjectBuilder().build();
}

protected AbstractJsonObject(String jsonString) {
Expand Down Expand Up @@ -54,7 +55,7 @@ public JsonObject getObject(String name) {
}

public JsonObject getJsonObject() {
return Json.createObjectBuilder(json).build();
return jsonProvider().createObjectBuilder(json).build();
}

public Object get(String name) {
Expand Down Expand Up @@ -91,7 +92,7 @@ protected List<String> getListOfStrings(String prop) {
}

public static JsonObject toJsonObject(String json) {
try (JsonReader jsonReader = Json.createReader(new StringReader(json))) {
try (JsonReader jsonReader = jsonProvider().createReader(new StringReader(json))) {
return jsonReader.readObject();
}
}
Expand Down
2 changes: 2 additions & 0 deletions extensions/oidc/runtime/banned-signatures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@defaultMessage Don't jakarta.json.Json as it is ridiculously slow (see https://github.com/quarkusio/quarkus/issues/42748)
jakarta.json.Json
14 changes: 14 additions & 0 deletions extensions/oidc/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<executions>
<execution>
<id>verify-forbidden-apis</id>
<configuration>
<signaturesFiles>
<signaturesFile>./banned-signatures.txt</signaturesFile>
</signaturesFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.quarkus.oidc.runtime.providers;

import static io.quarkus.jsonp.JsonProviderHolder.jsonProvider;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
import jakarta.json.Json;
import jakarta.json.JsonObject;

import io.quarkus.oidc.OIDCException;
Expand All @@ -24,7 +25,7 @@ public JsonObject customizeHeaders(JsonObject headers) {
if (nonce != null) {
byte[] nonceSha256 = OidcUtils.getSha256Digest(nonce.getBytes(StandardCharsets.UTF_8));
byte[] newNonceBytes = Base64.getUrlEncoder().withoutPadding().encode(nonceSha256);
return Json.createObjectBuilder(headers)
return jsonProvider().createObjectBuilder(headers)
.add(OidcConstants.NONCE, new String(newNonceBytes, StandardCharsets.UTF_8)).build();
}
return null;
Expand Down

0 comments on commit 4bb81a2

Please sign in to comment.