use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.
the class CAdESChecker method setSignaturePolicy.
private void setSignaturePolicy(PolicyFactory.Policies signaturePolicy) {
this.setPolicyName(signaturePolicy.name());
PolicyFactory policyFactory = PolicyFactory.getInstance();
org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy sp = policyFactory.loadPolicy(signaturePolicy);
this.signaturePolicy = sp;
}
use of org.demoiselle.signer.policy.engine.factory.PolicyFactory 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);
}
}
use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.
the class PolicyFactoryTest method testLoadPolicy.
// @Test
public void testLoadPolicy() {
PolicyFactory factory = PolicyFactory.getInstance();
Policies[] policies = PolicyFactory.Policies.values();
for (Policies policy : policies) {
// TODO - falta implentar policy para XADES
if (policy.toString().contains("CADES") || policy.toString().contains("PADES")) {
logger.info(factory.loadPolicy(policy).toString());
}
}
}
use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.
the class CAdESSigner method setSignaturePolicy.
@Override
public void setSignaturePolicy(PolicyFactory.Policies signaturePolicy) {
this.setPolicyName(signaturePolicy.name());
PolicyFactory policyFactory = PolicyFactory.getInstance();
org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy sp = policyFactory.loadPolicy(signaturePolicy);
this.signaturePolicy = sp;
}
use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.
the class CAdESTimeStampSigner method setSignaturePolicy.
@Override
public void setSignaturePolicy(PolicyFactory.Policies signaturePolicy) {
PolicyFactory policyFactory = PolicyFactory.getInstance();
org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy sp = policyFactory.loadPolicy(signaturePolicy);
this.signaturePolicy = sp;
}
Aggregations