}
Pap pap = PapManager.getInstance().getPap(alias);
if (pap.isRemote()) {
throw new XACMLPolicyManagementServiceException("You cannot add rules to a remote PAP!");
}
if ((actionId == null) && (actionValue == null)) {
throw new XACMLPolicyManagementServiceException("Action id and action value are both unspecified.");
}
RuleWizard ruleWizard = new RuleWizard(attributeWizardList, effect);
PapContainer papContainer = new PapContainer(pap);
if (actionId == null) {
actionId = getActionId(papContainer, actionValue, resourceValue, after);
}
PolicyType actionPolicy = papContainer.getPolicy(actionId);
if (obligationValue!= null){
if (ObligationScopeType.action.equals(obligationScope)){
if (!PolicyHelper.hasObligationWithId(actionPolicy, obligationValue)){
ObligationWizard owiz = new ObligationWizard(obligationValue);
ObligationsType obligations = ObligationsHelper.build();
obligations.getObligations().add(owiz.getXACML());
actionPolicy.setObligations(obligations);
}
}else{
PolicySetType resourcePolicySet = findResourcePolicySet(papContainer);
if (!PolicySetHelper.hasObligationWithId(resourcePolicySet, obligationValue)){
ObligationWizard owiz = new ObligationWizard(obligationValue);
ObligationsType obligations = ObligationsHelper.build();
obligations.getObligations().add(owiz.getXACML());
resourcePolicySet.setObligations(obligations);
}
}
}
int index = 0;
if (ruleId != null) {
index = PolicyHelper.indexOfRule(actionPolicy, ruleId);
if (index == -1) {
throw new XACMLPolicyManagementServiceException("ruleId not found: " + ruleId);
}
if (after) {
index++;
}