use of org.demoiselle.signer.policy.engine.exception.PolicyException in project signer by demoiselle.
the class PolicyValidator method validate.
public boolean validate() {
try {
boolean valid = true;
Date dateNotBefore = this.sp.getSignPolicyInfo().getSignatureValidationPolicy().getSigningPeriod().getNotBefore().getDate();
Date dateNotAfter = this.sp.getSignPolicyInfo().getSignatureValidationPolicy().getSigningPeriod().getNotAfter().getDate();
Date actualDate = new GregorianCalendar().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy - hh:mm:ss");
if (actualDate.before(dateNotBefore) || actualDate.after(dateNotAfter)) {
throw new PolicyException(policyMessagesBundle.getString("error.policy.valid.period", sdf.format(dateNotBefore), sdf.format(dateNotBefore)));
}
PolicyFactory factory = PolicyFactory.getInstance();
LPA tempListOfPolicies = null;
if (policyName.contains("CADES")) {
tempListOfPolicies = factory.loadLPACAdES();
listOfPolicies = tempListOfPolicies;
Date nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
LOGGER.info(policyMessagesBundle.getString("info.lpa.load.local"));
tempListOfPolicies = factory.loadLPACAdESLocal();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.local.not.updated", LPARepository.FULL_PATH_FOLDER_SIGNER.toString() + "LPA_CAdES.der", sdf.format(nextUpdate)));
tempListOfPolicies = factory.loadLPACAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
}
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
tempListOfPolicies = factory.loadLPACAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
LOGGER.warn(policyMessagesBundle.getString("error.lpa.not.found"));
}
}
}
for (PolicyInfo policyInfo : listOfPolicies.getPolicyInfos()) {
if (policyInfo.getPolicyOID().getValue().contentEquals(sp.getSignPolicyInfo().getSignPolicyIdentifier().getValue())) {
GeneralizedTime revocationDate = policyInfo.getRevocationDate();
if (revocationDate != null) {
throw new PolicyException(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
}
}
}
} else {
if (policyName.contains("PADES")) {
tempListOfPolicies = factory.loadLPAPAdES();
listOfPolicies = tempListOfPolicies;
Date nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
LOGGER.info(policyMessagesBundle.getString("info.lpa.load.local"));
tempListOfPolicies = factory.loadLPAPAdESLocal();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.local.not.updated", LPARepository.FULL_PATH_FOLDER_SIGNER.toString() + "LPA_PAdES.der", sdf.format(nextUpdate)));
tempListOfPolicies = factory.loadLPAPAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
}
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
tempListOfPolicies = factory.loadLPAPAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
LOGGER.warn(policyMessagesBundle.getString("error.lpa.not.found"));
}
}
}
for (PolicyInfo policyInfo : listOfPolicies.getPolicyInfos()) {
if (policyInfo.getPolicyOID().getValue().contentEquals(sp.getSignPolicyInfo().getSignPolicyIdentifier().getValue())) {
GeneralizedTime revocationDate = policyInfo.getRevocationDate();
if (revocationDate != null) {
throw new PolicyException(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
}
}
}
} else {
if (policyName.contains("XADES")) {
// TODO verificar como é procesado em XML
listOfPolicies = factory.loadLPAXAdES();
} else {
throw new PolicyException(policyMessagesBundle.getString("error.policy.not.recognized", policyName));
}
}
}
return valid;
} catch (Exception ex) {
throw new PolicyException(ex.getMessage(), ex);
}
}
Aggregations