Skip to content

Commit 8d0be7c

Browse files
feat(gateway): add requiresRedaction field to PolicyApprovalResult (#37)
* feat(gateway): add requiresRedaction field to PolicyApprovalResult Adds requiresRedaction boolean field and isRequiresRedaction() getter to PolicyApprovalResult for Issue #891. When true, PII was detected with redact action and the response should be processed for redaction before being shown to users. This supports the new detection defaults where PII defaults to redact instead of block, providing better UX while maintaining security. * fix: update test constructors for requiresRedaction parameter Updated PolicyApprovalResult constructor calls in tests to include the new requiresRedaction parameter added in the previous commit. Issue #891
1 parent 0806fe2 commit 8d0be7c

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- **Audit Log Reading**: Added `searchAuditLogs()` for searching audit logs with filters (user email, client ID, time range, request type)
1919
- **Tenant Audit Logs**: Added `getAuditLogsByTenant()` for retrieving audit logs scoped to a specific tenant
2020
- **Audit Types**: Added `AuditLogEntry`, `AuditSearchRequest`, `AuditQueryOptions`, and `AuditSearchResponse` types
21+
- **PII Redaction Support**: Added `isRequiresRedaction()` method to `PolicyApprovalResult` (Issue #891)
22+
- When `true`, PII was detected with redact action and response should be processed for redaction
23+
- Supports new detection defaults: PII defaults to redact instead of block
2124

2225
### Changed
2326

src/main/java/com/getaxonflow/sdk/types/PolicyApprovalResult.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public final class PolicyApprovalResult {
5656
@JsonProperty("approved")
5757
private final boolean approved;
5858

59+
@JsonProperty("requires_redaction")
60+
private final boolean requiresRedaction;
61+
5962
@JsonProperty("approved_data")
6063
private final Map<String, Object> approvedData;
6164

@@ -77,6 +80,7 @@ public final class PolicyApprovalResult {
7780
public PolicyApprovalResult(
7881
@JsonProperty("context_id") String contextId,
7982
@JsonProperty("approved") boolean approved,
83+
@JsonProperty("requires_redaction") boolean requiresRedaction,
8084
@JsonProperty("approved_data") Map<String, Object> approvedData,
8185
@JsonProperty("policies") List<String> policies,
8286
@JsonProperty("expires_at") Instant expiresAt,
@@ -85,6 +89,7 @@ public PolicyApprovalResult(
8589
@JsonProperty("processing_time") String processingTime) {
8690
this.contextId = contextId;
8791
this.approved = approved;
92+
this.requiresRedaction = requiresRedaction;
8893
this.approvedData = approvedData != null ? Collections.unmodifiableMap(approvedData) : Collections.emptyMap();
8994
this.policies = policies != null ? Collections.unmodifiableList(policies) : Collections.emptyList();
9095
this.expiresAt = expiresAt;
@@ -113,6 +118,18 @@ public boolean isApproved() {
113118
return approved;
114119
}
115120

121+
/**
122+
* Returns whether the response requires redaction.
123+
*
124+
* <p>When true, PII was detected with redact action and the response
125+
* should be processed for redaction before being shown to users.
126+
*
127+
* @return true if redaction is required
128+
*/
129+
public boolean isRequiresRedaction() {
130+
return requiresRedaction;
131+
}
132+
116133
/**
117134
* Returns data that has been approved/filtered by policies.
118135
*
@@ -213,6 +230,7 @@ public boolean equals(Object o) {
213230
if (o == null || getClass() != o.getClass()) return false;
214231
PolicyApprovalResult that = (PolicyApprovalResult) o;
215232
return approved == that.approved &&
233+
requiresRedaction == that.requiresRedaction &&
216234
Objects.equals(contextId, that.contextId) &&
217235
Objects.equals(approvedData, that.approvedData) &&
218236
Objects.equals(policies, that.policies) &&
@@ -224,7 +242,7 @@ public boolean equals(Object o) {
224242

225243
@Override
226244
public int hashCode() {
227-
return Objects.hash(contextId, approved, approvedData, policies, expiresAt,
245+
return Objects.hash(contextId, approved, requiresRedaction, approvedData, policies, expiresAt,
228246
blockReason, rateLimitInfo, processingTime);
229247
}
230248

@@ -233,6 +251,7 @@ public String toString() {
233251
return "PolicyApprovalResult{" +
234252
"contextId='" + contextId + '\'' +
235253
", approved=" + approved +
254+
", requiresRedaction=" + requiresRedaction +
236255
", policies=" + policies +
237256
", expiresAt=" + expiresAt +
238257
", blockReason='" + blockReason + '\'' +

src/test/java/com/getaxonflow/sdk/types/MoreTypesTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ void shouldCreateApprovedResult() {
10541054
Instant expiresAt = Instant.now().plusSeconds(300);
10551055

10561056
PolicyApprovalResult result = new PolicyApprovalResult(
1057-
"ctx-123", true, data, policies, expiresAt, null, null, "5.2ms"
1057+
"ctx-123", true, false, data, policies, expiresAt, null, null, "5.2ms"
10581058
);
10591059

10601060
assertThat(result.getContextId()).isEqualTo("ctx-123");
@@ -1070,7 +1070,7 @@ void shouldCreateApprovedResult() {
10701070
@DisplayName("should create blocked result")
10711071
void shouldCreateBlockedResult() {
10721072
PolicyApprovalResult result = new PolicyApprovalResult(
1073-
null, false, null, null, null,
1073+
null, false, false, null, null, null,
10741074
"Request blocked by policy: pii-detection", null, "3.1ms"
10751075
);
10761076

@@ -1085,13 +1085,13 @@ void shouldCheckExpiration() {
10851085
Instant past = Instant.now().minusSeconds(3600);
10861086

10871087
PolicyApprovalResult notExpired = new PolicyApprovalResult(
1088-
"ctx", true, null, null, future, null, null, null
1088+
"ctx", true, false, null, null, future, null, null, null
10891089
);
10901090
PolicyApprovalResult expired = new PolicyApprovalResult(
1091-
"ctx", true, null, null, past, null, null, null
1091+
"ctx", true, false, null, null, past, null, null, null
10921092
);
10931093
PolicyApprovalResult noExpiry = new PolicyApprovalResult(
1094-
"ctx", true, null, null, null, null, null, null
1094+
"ctx", true, false, null, null, null, null, null, null
10951095
);
10961096

10971097
assertThat(notExpired.isExpired()).isFalse();
@@ -1103,7 +1103,7 @@ void shouldCheckExpiration() {
11031103
@DisplayName("should extract blocking policy name - format 1")
11041104
void shouldExtractBlockingPolicyNameFormat1() {
11051105
PolicyApprovalResult result = new PolicyApprovalResult(
1106-
null, false, null, null, null,
1106+
null, false, false, null, null, null,
11071107
"Request blocked by policy: my-policy", null, null
11081108
);
11091109

@@ -1114,7 +1114,7 @@ void shouldExtractBlockingPolicyNameFormat1() {
11141114
@DisplayName("should extract blocking policy name - format 2")
11151115
void shouldExtractBlockingPolicyNameFormat2() {
11161116
PolicyApprovalResult result = new PolicyApprovalResult(
1117-
null, false, null, null, null,
1117+
null, false, false, null, null, null,
11181118
"Blocked by policy: another-policy", null, null
11191119
);
11201120

@@ -1125,7 +1125,7 @@ void shouldExtractBlockingPolicyNameFormat2() {
11251125
@DisplayName("should extract blocking policy name - bracket format")
11261126
void shouldExtractBlockingPolicyNameBracket() {
11271127
PolicyApprovalResult result = new PolicyApprovalResult(
1128-
null, false, null, null, null,
1128+
null, false, false, null, null, null,
11291129
"[policy-name] Description of violation", null, null
11301130
);
11311131

@@ -1136,7 +1136,7 @@ void shouldExtractBlockingPolicyNameBracket() {
11361136
@DisplayName("should return full reason when no pattern matches")
11371137
void shouldReturnFullReasonWhenNoPattern() {
11381138
PolicyApprovalResult result = new PolicyApprovalResult(
1139-
null, false, null, null, null,
1139+
null, false, false, null, null, null,
11401140
"Generic block reason", null, null
11411141
);
11421142

@@ -1147,7 +1147,7 @@ void shouldReturnFullReasonWhenNoPattern() {
11471147
@DisplayName("should return null for null block reason")
11481148
void shouldReturnNullForNullBlockReason() {
11491149
PolicyApprovalResult result = new PolicyApprovalResult(
1150-
"ctx", true, null, null, null, null, null, null
1150+
"ctx", true, false, null, null, null, null, null, null
11511151
);
11521152

11531153
assertThat(result.getBlockingPolicyName()).isNull();
@@ -1157,7 +1157,7 @@ void shouldReturnNullForNullBlockReason() {
11571157
@DisplayName("should handle null collections")
11581158
void shouldHandleNullCollections() {
11591159
PolicyApprovalResult result = new PolicyApprovalResult(
1160-
"ctx", true, null, null, null, null, null, null
1160+
"ctx", true, false, null, null, null, null, null, null
11611161
);
11621162

11631163
assertThat(result.getApprovedData()).isEmpty();
@@ -1167,9 +1167,9 @@ void shouldHandleNullCollections() {
11671167
@Test
11681168
@DisplayName("should implement equals and hashCode")
11691169
void shouldImplementEqualsAndHashCode() {
1170-
PolicyApprovalResult r1 = new PolicyApprovalResult("c1", true, null, null, null, null, null, null);
1171-
PolicyApprovalResult r2 = new PolicyApprovalResult("c1", true, null, null, null, null, null, null);
1172-
PolicyApprovalResult r3 = new PolicyApprovalResult("c2", true, null, null, null, null, null, null);
1170+
PolicyApprovalResult r1 = new PolicyApprovalResult("c1", true, false, null, null, null, null, null, null);
1171+
PolicyApprovalResult r2 = new PolicyApprovalResult("c1", true, false, null, null, null, null, null, null);
1172+
PolicyApprovalResult r3 = new PolicyApprovalResult("c2", true, false, null, null, null, null, null, null);
11731173

11741174
assertThat(r1).isEqualTo(r2);
11751175
assertThat(r1.hashCode()).isEqualTo(r2.hashCode());
@@ -1180,7 +1180,7 @@ void shouldImplementEqualsAndHashCode() {
11801180
@DisplayName("should have toString")
11811181
void shouldHaveToString() {
11821182
PolicyApprovalResult result = new PolicyApprovalResult(
1183-
"ctx-abc", true, null, Arrays.asList("p1"), null, null, null, "1ms"
1183+
"ctx-abc", true, false, null, Arrays.asList("p1"), null, null, null, "1ms"
11841184
);
11851185
assertThat(result.toString()).contains("PolicyApprovalResult").contains("ctx-abc");
11861186
}

0 commit comments

Comments
 (0)