package com.xfestudio.xfeservermanager.api.policy;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.Objects;
public record PolicyRule(
String id,
boolean enabled,
RuleTier tier,
SubjectMatcher subject,
CommandMatcher command,
DecisionEffect effect,
CommandConstraints constraints,
String reason,
String groupId,
String groupName,
Boolean groupEnabled
) {
public static final String DEFAULT_GROUP_ID = "default";
public static final String DEFAULT_GROUP_NAME = "Default policy group";
public PolicyRule {
id = ApiChecks.notBlank(id, "id");
Objects.requireNonNull(tier, "tier");
Objects.requireNonNull(subject, "subject");
Objects.requireNonNull(command, "command");
Objects.requireNonNull(effect, "effect");
Objects.requireNonNull(constraints, "constraints");
reason = ApiChecks.notBlank(reason, "reason");
groupId = groupId == null || groupId.isBlank() ? DEFAULT_GROUP_ID : groupId.strip();
groupName = groupName == null || groupName.isBlank() ? DEFAULT_GROUP_NAME : groupName.strip();
groupEnabled = groupEnabled == null ? Boolean.TRUE : groupEnabled;
}
/** Backward-compatible constructor for rules created before named policy groups. */
public PolicyRule(
String id,
boolean enabled,
RuleTier tier,
SubjectMatcher subject,
CommandMatcher command,
DecisionEffect effect,
CommandConstraints constraints,
String reason
) {
this(id, enabled, tier, subject, command, effect, constraints, reason,
DEFAULT_GROUP_ID, DEFAULT_GROUP_NAME, Boolean.TRUE);
}
public int specificity() {
return subject.specificity() + command.specificity();
}
public boolean effectiveEnabled() {
return enabled && groupEnabled;
}
}
package com.xfestudio.xfeservermanager.api.policy;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.Objects;
public record PolicyRule(
String id,
boolean enabled,
RuleTier tier,
SubjectMatcher subject,
CommandMatcher command,
DecisionEffect effect,
CommandConstraints constraints,
String reason,
String groupId,
String groupName,
Boolean groupEnabled
) {
public static final String DEFAULT_GROUP_ID = "default";
public static final String DEFAULT_GROUP_NAME = "Default policy group";
public PolicyRule {
id = ApiChecks.notBlank(id, "id");
Objects.requireNonNull(tier, "tier");
Objects.requireNonNull(subject, "subject");
Objects.requireNonNull(command, "command");
Objects.requireNonNull(effect, "effect");
Objects.requireNonNull(constraints, "constraints");
reason = ApiChecks.notBlank(reason, "reason");
groupId = groupId == null || groupId.isBlank() ? DEFAULT_GROUP_ID : groupId.strip();
groupName = groupName == null || groupName.isBlank() ? DEFAULT_GROUP_NAME : groupName.strip();
groupEnabled = groupEnabled == null ? Boolean.TRUE : groupEnabled;
}
/** Backward-compatible constructor for rules created before named policy groups. */
public PolicyRule(
String id,
boolean enabled,
RuleTier tier,
SubjectMatcher subject,
CommandMatcher command,
DecisionEffect effect,
CommandConstraints constraints,
String reason
) {
this(id, enabled, tier, subject, command, effect, constraints, reason,
DEFAULT_GROUP_ID, DEFAULT_GROUP_NAME, Boolean.TRUE);
}
public int specificity() {
return subject.specificity() + command.specificity();
}
public boolean effectiveEnabled() {
return enabled && groupEnabled;
}
}