if(PolicyTypeUtil.signaturePolicy(actualPol)){
SignaturePolicy actualSignPolicy = (SignaturePolicy)actualPol;
boolean isEndorsing = ((SignaturePolicy.FeatureBinding)actualSignPolicy.getFeatureBinding()).isEndorsingSignature();
boolean isPrimary = ((SignaturePolicy.FeatureBinding)actualSignPolicy.getFeatureBinding()).isPrimarySignature();
int nth = 0;
WSSPolicy pol = getFirstPrimaryPolicy(inferredSecurityPolicy, isEndorsing, nth++);
if(pol == null && isOptionalPolicy(actualSignPolicy) == true){
return;
}
if(pol == null){
log.log(Level.SEVERE, LogStringsMessages.WSS_0268_ERROR_POLICY_VERIFICATION());
throw new XWSSecurityException("Policy verification error:" +
"Missing Signature Element");
}
if(PolicyTypeUtil.signaturePolicy(pol)){
SignaturePolicy inferredPol = (SignaturePolicy)pol;
// verify key binding
boolean isKBTrue = verifyKeyBinding(actualSignPolicy.getKeyBinding(), inferredPol.getKeyBinding(),
false);
while(!isKBTrue && !isPrimary){
pol = getFirstPrimaryPolicy(inferredSecurityPolicy, isEndorsing, nth++);
if (pol == null && isOptionalPolicy(actualSignPolicy) == true) {
return;
}
if(pol == null){
log.log(Level.SEVERE, LogStringsMessages.WSS_0268_ERROR_POLICY_VERIFICATION());
throw new XWSSecurityException("Policy verification error:" +
"Missing Signature Element - perhaps a second supporting signature or " +
"Incorrect Key types or references were used in Signature");
}
inferredPol = (SignaturePolicy)pol;
isKBTrue = verifyKeyBinding(actualSignPolicy.getKeyBinding(), inferredPol.getKeyBinding(),
false);
//nth++;
}
// verify target binding
boolean isTBTrue = verifySignTargetBinding((SignaturePolicy.FeatureBinding)actualSignPolicy.getFeatureBinding(),
(SignaturePolicy.FeatureBinding)inferredPol.getFeatureBinding());
inferredSecurityPolicy.remove(pol);
if(!isKBTrue){
log.log(Level.SEVERE, LogStringsMessages.WSS_0206_POLICY_VIOLATION_EXCEPTION());
throw new XWSSecurityException("Policy verification error: " +
"Incorrect Key types or references were used in Signature");
}
if(!isTBTrue){
log.log(Level.SEVERE, LogStringsMessages.WSS_0206_POLICY_VIOLATION_EXCEPTION());
throw new XWSSecurityException("Policy verification error: " +
"One or more Signed Parts could not be validated");
}
checkTargets(actualPol, pol);
} else{
//It could be a case of Extra Security, an Encrypted Signature
//when the policy just requires a Signature
if (!isEncryptedSignature(actualPol, pol)) {
//check to see for the case when no Signature Target present in message
//The incoming message will not have Signature policy in that case.
if (checkTargetPresence(actualPol)) {
log.log(Level.SEVERE, LogStringsMessages.WSS_0206_POLICY_VIOLATION_EXCEPTION());
throw new XWSSecurityException("Signature Policy verification error: Looking for a Signature Element " + " in Security header, but found " + pol + ".");
}
} else {
inferredSecurityPolicy.remove(pol);
}
}
} else if(PolicyTypeUtil.encryptionPolicy(actualPol)){
EncryptionPolicy actualEncryptionPolicy = (EncryptionPolicy)actualPol;
WSSPolicy pol = getFirstPrimaryPolicy(inferredSecurityPolicy, false, 0);
if(pol == null){
log.log(Level.SEVERE, LogStringsMessages.WSS_0269_ERROR_ENCRYPTIONPOLICY_VERIFICATION());
throw new XWSSecurityException("Encryption Policy verification error:" +
"Missing encryption element");
}
if(PolicyTypeUtil.encryptionPolicy(pol)){
EncryptionPolicy inferredPol = (EncryptionPolicy)pol;
//verify key binding
boolean isKBTrue = verifyKeyBinding(actualEncryptionPolicy.getKeyBinding(),
inferredPol.getKeyBinding(), true);
// verify target binding
boolean isTBTrue = verifyEncTargetBinding((EncryptionPolicy.FeatureBinding)actualEncryptionPolicy.getFeatureBinding(),
(EncryptionPolicy.FeatureBinding)inferredPol.getFeatureBinding());
inferredSecurityPolicy.remove(pol);
if(!isKBTrue){
log.log(Level.SEVERE, LogStringsMessages.WSS_0206_POLICY_VIOLATION_EXCEPTION());
throw new XWSSecurityException("Encryption Policy verification error: " +
"Incorrect Key types or references were used in encryption");
}
if(!isTBTrue){
log.log(Level.SEVERE, LogStringsMessages.WSS_0206_POLICY_VIOLATION_EXCEPTION());
throw new XWSSecurityException("Policy verification error: " +
"One or more encrypted parts could not be validated");
}
List<Target> inferredList = ((EncryptionPolicy.FeatureBinding)pol.getFeatureBinding()).getTargetBindings();
List<Target> actualList = ((EncryptionPolicy.FeatureBinding)actualPol.getFeatureBinding()).getTargetBindings();
if(actualList.size() > inferredList.size()){
int nthEncrypt = 0;
EncryptionPolicy inferredPol2 = getNthEncryptionPolicy(inferredSecurityPolicy, nthEncrypt);
while(inferredPol2 != null){