Fix ReCAPTCHA Enterprise failing due to new properties in response

The assessment response added a new field called accountDefenderAssessment.
This commit adds the new property, and also ensures new properties won't be
problematic next time by ignoring unknown properties on the top level object.

Closes: #30917

Signed-off-by: Lucy Linder <lucy.derlin@gmail.com>
This commit is contained in:
Lucy Linder 2024-07-07 12:03:23 +02:00 committed by Alexander Schwartz
parent 57a2990ae5
commit b4f7487dd3

View file

@ -24,6 +24,7 @@ import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public class RecaptchaAssessmentResponse {
@JsonProperty("name")
@ -38,9 +39,14 @@ public class RecaptchaAssessmentResponse {
@JsonProperty("event")
private Event event;
@JsonProperty("accountDefenderAssessment")
private AccountDefenderAssessment accountDefenderAssessment;
public String toString() {
return format("RecaptchaAssessmentResponse(name=%s, riskAnalysis=%s, tokenProperties=%s, event=%s)",
this.getName(), this.getRiskAnalysis(), this.getTokenProperties(), this.getEvent());
return format(
"RecaptchaAssessmentResponse(name=%s, riskAnalysis=%s, tokenProperties=%s, event=%s, accountDefenderAssessment=%s)",
this.getName(), this.getRiskAnalysis(), this.getTokenProperties(), this.getEvent(),
this.getAccountDefenderAssessment());
}
public String getName() {
@ -75,6 +81,14 @@ public class RecaptchaAssessmentResponse {
this.event = event;
}
public AccountDefenderAssessment getAccountDefenderAssessment() {
return accountDefenderAssessment;
}
public void setAccountDefenderAssessment(AccountDefenderAssessment accountDefenderAssessment) {
this.accountDefenderAssessment = accountDefenderAssessment;
}
@JsonIgnoreProperties(ignoreUnknown = true)
public static class RiskAnalysis {
@JsonProperty("score")
@ -241,7 +255,26 @@ public class RecaptchaAssessmentResponse {
public void setUserIpAddress(String userIpAddress) {
this.userIpAddress = userIpAddress;
}
}
@JsonIgnoreProperties(ignoreUnknown = true)
public static class AccountDefenderAssessment {
@JsonProperty("labels")
private String[] labels;
public String toString() {
return format("AccountDefenderAssessment(labels=%s)",
this.getLabels() != null ? Arrays.toString(this.getLabels()) : "[]");
}
public String[] getLabels() {
return labels;
}
public void setLabels(String[] labels) {
this.labels = labels;
}
}
}