if (pap.isRemote()) {
throw new XACMLPolicyManagementServiceException("Forbidden operation for a remote PAP");
}
PapContainer papContainer = new PapContainer(pap);
PolicySetType targetPolicySet = getTargetPolicySet(papContainer);
if (targetPolicySet == null) {
targetPolicySet = (new PolicySetWizard(resourceAttributeWizard)).getXACML();
} else {
updateOperationForPolicySet = true;
}
String policyId = null;
PolicyWizard targetPolicyWizard;
PolicyType candidatePolicy = getTargetPolicy(papContainer, targetPolicySet);
if (candidatePolicy == null) {
targetPolicyWizard = new PolicyWizard(actionAttributeWizard);
targetPolicyWizard.setPrivate(!isPublic);
policyId = targetPolicyWizard.getPolicyId();
PolicySetHelper.addPolicyReference(targetPolicySet, 0, policyId);
} else {
targetPolicyWizard = new PolicyWizard(candidatePolicy);
if (targetPolicyWizard.denyRuleForAttributeExists(banAttributeWizard)) {
// ban policy already exists
return null;
}
policyId = candidatePolicy.getPolicyId();
updateOperationForPolicy = true;
policySetNeedToBeSaved = false;
}
targetPolicyWizard.addRule(0, banAttributeWizard, EffectType.Deny);
// Store the ban policy and the policy set in which it is contained
// (only if needed)
if (policySetNeedToBeSaved) {
if (updateOperationForPolicySet) {
String oldVersion = targetPolicySet.getVersion();
PolicySetWizard.increaseVersion(targetPolicySet);
papContainer.updatePolicySet(oldVersion, targetPolicySet);
} else {
papContainer.addPolicySet(0, targetPolicySet);
}
} else {
TypeStringUtils.releaseUnneededMemory(targetPolicySet);
}
if (updateOperationForPolicy) {
String oldVersion = targetPolicyWizard.getVersionString();
targetPolicyWizard.increaseVersion();
papContainer.updatePolicy(oldVersion, targetPolicyWizard.getXACML());
} else {
papContainer.storePolicy(targetPolicyWizard.getXACML());
}
targetPolicyWizard.releaseChildrenDOM();
targetPolicyWizard.releaseDOM();