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++;
}
}
if ((ruleId == null) && (after)) {
index = -1;
}
PolicyHelper.addRule(actionPolicy, index, ruleWizard.getXACML());
String version = actionPolicy.getVersion();
PolicyWizard.increaseVersion(actionPolicy);
TypeStringUtils.releaseUnneededMemory(actionPolicy);
papContainer.updatePolicy(version, actionPolicy);
return ruleWizard.getRuleId();
}