Set<AbstractPolicy> applicablePolicies =
getApplicablePolicies(context, matchedPolicies);
for (AbstractPolicy policy : applicablePolicies) {
Result result = policy.evaluate(context);
int effect = result.getDecision();
if (effect == Result.DECISION_DENY) {
denyObligations.addAll(result.getObligations());
return new Result(Result.DECISION_DENY, context.getResourceId()
.encode(), denyObligations);
}
if (effect == Result.DECISION_PERMIT) {
atLeastOnePermit = true;
} else if (effect == Result.DECISION_INDETERMINATE) {
atLeastOneError = true;
// keep track of the first error, regardless of cause
if (firstIndeterminateStatus == null) {
firstIndeterminateStatus = result.getStatus();
}
}
}
// if we got a PERMIT, return it
if (atLeastOnePermit) {
return new Result(Result.DECISION_PERMIT, context.getResourceId()
.encode());
}
// if we got an INDETERMINATE, return it
if (atLeastOneError) {
return new Result(Result.DECISION_INDETERMINATE,
firstIndeterminateStatus,
context.getResourceId().encode());
}
// if we got here, then nothing applied to us
return new Result(Result.DECISION_NOT_APPLICABLE, context
.getResourceId().encode());
}