package at.gv.egiz.asic.impl; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.asic.api.ASiC; import at.gv.egiz.asic.api.ASiCVerificationResult; import at.gv.egiz.asic.api.ASiCVerifier; import at.gv.egiz.asic.impl.verifier.ExtendedCAdESVerifier; import at.gv.egiz.asic.impl.verifier.ExtendedXAdESVerifier; import at.gv.egiz.asic.impl.verifier.SimpleCAdESVerifier; import at.gv.egiz.asic.impl.verifier.SimpleXAdESVerifier; import at.gv.egovernment.moa.spss.MOAException; import at.gv.egovernment.moa.spss.MOASystemException; /** * Created by Andreas Fitzek on 6/15/16. */ public class ASiCMOAVerifier implements ASiCVerifier { private static final Logger logger = LoggerFactory.getLogger(ASiCMOAVerifier.class); private final List verifierMap = new ArrayList<>(); public ASiCMOAVerifier() { verifierMap.add(new SimpleCAdESVerifier()); verifierMap.add(new SimpleXAdESVerifier()); verifierMap.add(new ExtendedCAdESVerifier()); verifierMap.add(new ExtendedXAdESVerifier()); } @Override public List verify(ASiC asic, String trustProfileID, Date date) throws MOAException { final List response = new ArrayList<>(); boolean handled = false; final Iterator verifierIterator = verifierMap.iterator(); while (verifierIterator.hasNext()) { final Verifier verifier = verifierIterator.next(); if (verifier.handles(asic)) { verifier.verify(asic, trustProfileID, date, response); handled = true; break; } } if (!handled) { logger.warn("Cannot handle ASiC: {}", asic); throw new MOASystemException("asic.0016", null); } return response; } }