Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public class OpaAuthorizer implements Authorizer {
private static final Logger LOG = new Logger(OpaAuthorizer.class);
private final String opaUri;
private final ObjectMapper objectMapper;
private final HttpClient httpClient;

@JsonCreator
public OpaAuthorizer(@JsonProperty("name") String name, @JsonProperty("opaUri") String opaUri) {
this.opaUri = opaUri;
this.httpClient = HttpClient.newHttpClient();
objectMapper =
new ObjectMapper()
// https://github.com/stackabletech/druid-opa-authorizer/issues/72
Expand All @@ -53,8 +55,7 @@ public Access authorize(
return new Access(false, "Failed to create the OPA request JSON: " + e);
}

LOG.trace("Creating HTTP Client and executing post.");
var client = HttpClient.newHttpClient();
LOG.trace("Executing post.");
try {
var request =
HttpRequest.newBuilder()
Expand All @@ -63,7 +64,7 @@ public Access authorize(
.POST(HttpRequest.BodyPublishers.ofString(msgJson))
.build();

var response = client.send(request, HttpResponse.BodyHandlers.ofString());
var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

LOG.debug("OPA Response code: %s - %s", response.statusCode(), response.body());
LOG.trace("Parsing OPA response.");
Expand Down
Loading