package com.xfestudio.xfeservermanager.api.policy;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.List;
import java.util.Objects;
public record PolicyDecision(
DecisionEffect effect,
long policyVersion,
List<String> matchedRuleIds,
List<PolicyViolation> violations,
String explanation
) {
public PolicyDecision {
Objects.requireNonNull(effect, "effect");
if (policyVersion < 0) {
throw new IllegalArgumentException("policyVersion must be non-negative");
}
matchedRuleIds = ApiChecks.immutableList(matchedRuleIds, "matchedRuleIds");
violations = ApiChecks.immutableList(violations, "violations");
explanation = ApiChecks.notBlank(explanation, "explanation");
if (effect != DecisionEffect.DENY && !violations.isEmpty()) {
throw new IllegalArgumentException("only denied decisions may contain violations");
}
}
public boolean isDenied() {
return effect == DecisionEffect.DENY;
}
public boolean grantsPermission() {
return effect == DecisionEffect.GRANT;
}
public boolean requiresVanillaPermissionCheck() {
return effect == DecisionEffect.PASS_THROUGH || effect == DecisionEffect.CONSTRAIN;
}
/** Elevated commands require admission to the bounded audit writer before execution. */
public boolean requiresAuditAdmission() {
return effect == DecisionEffect.GRANT;
}
}
package com.xfestudio.xfeservermanager.api.policy;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.List;
import java.util.Objects;
public record PolicyDecision(
DecisionEffect effect,
long policyVersion,
List<String> matchedRuleIds,
List<PolicyViolation> violations,
String explanation
) {
public PolicyDecision {
Objects.requireNonNull(effect, "effect");
if (policyVersion < 0) {
throw new IllegalArgumentException("policyVersion must be non-negative");
}
matchedRuleIds = ApiChecks.immutableList(matchedRuleIds, "matchedRuleIds");
violations = ApiChecks.immutableList(violations, "violations");
explanation = ApiChecks.notBlank(explanation, "explanation");
if (effect != DecisionEffect.DENY && !violations.isEmpty()) {
throw new IllegalArgumentException("only denied decisions may contain violations");
}
}
public boolean isDenied() {
return effect == DecisionEffect.DENY;
}
public boolean grantsPermission() {
return effect == DecisionEffect.GRANT;
}
public boolean requiresVanillaPermissionCheck() {
return effect == DecisionEffect.PASS_THROUGH || effect == DecisionEffect.CONSTRAIN;
}
/** Elevated commands require admission to the bounded audit writer before execution. */
public boolean requiresAuditAdmission() {
return effect == DecisionEffect.GRANT;
}
}