UniqueServiceFilter implements TrustedServiceFilter { @Override public List<TrustedServiceWrapper> filter(List<TrustedServiceWrapper> trustServices) { TrustedServiceWrapper selectedTrustedService = null; if (Utils.collectionSize(trustServices) == 1) { selectedTrustedService = trustServices.get(0); } else if (Utils.isCollectionNotEmpty(trustServices)) { LOG.info("More than one selected trust services"); EnumMap<CertificateQualification, List<String>> qualificationResults = new EnumMap<>( CertificateQualification.class); for (TrustedServiceWrapper trustService : trustServices) { CertificateQualificationCalculation calculator = new CertificateQualificationCalculation(endEntityCert, trustService); CertificateQualification certQualification = calculator.getQualification(); if (!qualificationResults.containsKey(certQualification)) { qualificationResults.put(certQualification, trustService.getServiceNames()); } } if (qualificationResults.size() > 1) { LOG.warn("Unable to select the trust service ! Several possible conclusions {}", qualificationResults); } else { LOG.info("All trust services conclude with the same result"); selectedTrustedService = trustServices.get(0); } } if (selectedTrustedService != null) { return Collections.singletonList(selectedTrustedService); } else { return Collections.emptyList(); } } UniqueServiceFilter(CertificateWrapper endEntityCert); @Override List<TrustedServiceWrapper> filter(List<TrustedServiceWrapper> trustServices);  }
@Test public void testCanConcludeOneTrustService() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(AFTER_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionNotEmpty(filtered)); }
@Test public void testCanConclude() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setServiceNames(Arrays.asList("Test")); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(AFTER_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); TrustedServiceWrapper ts1 = new TrustedServiceWrapper(); ts1.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts1.setStatus(TrustedServiceStatus.GRANTED); ts1.setStartDate(AFTER_EIDAS_DATE); ts1.setCapturedQualifiers( Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_QSCD_MANAGED_ON_BEHALF, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts1); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionNotEmpty(filtered)); }
@Test public void testCannotConcludeServiceDateConflict() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setServiceNames(Arrays.asList("Test")); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(BEFORE_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); TrustedServiceWrapper ts1 = new TrustedServiceWrapper(); ts1.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts1.setStatus(TrustedServiceStatus.GRANTED); ts1.setStartDate(AFTER_EIDAS_DATE); ts1.setCapturedQualifiers( Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_QSCD_MANAGED_ON_BEHALF, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts1); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionEmpty(filtered)); }
@Test public void testCannotConcludeTypeConflict() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setServiceNames(Arrays.asList("Test")); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(AFTER_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); TrustedServiceWrapper ts1 = new TrustedServiceWrapper(); ts1.setServiceNames(Arrays.asList("Test")); ts1.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts1.setStatus(TrustedServiceStatus.GRANTED); ts1.setStartDate(AFTER_EIDAS_DATE); ts1.setCapturedQualifiers( Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESEAL)); trustServices.add(ts1); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionEmpty(filtered)); }
@Test public void testCannotConcludeConflictWithdrawn() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setServiceNames(Arrays.asList("Test")); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(AFTER_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); TrustedServiceWrapper ts1 = new TrustedServiceWrapper(); ts1.setServiceNames(Arrays.asList("Test")); ts1.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts1.setStatus(TrustedServiceStatus.WITHDRAWN); ts1.setStartDate(AFTER_EIDAS_DATE); ts1.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts1); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionEmpty(filtered)); }
@Test public void testCannotConcludeConflictQSCD() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setServiceNames(Arrays.asList("Test")); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(AFTER_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); TrustedServiceWrapper ts1 = new TrustedServiceWrapper(); ts1.setServiceNames(Arrays.asList("Test")); ts1.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts1.setStatus(TrustedServiceStatus.GRANTED); ts1.setStartDate(AFTER_EIDAS_DATE); ts1.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_NO_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts1); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionEmpty(filtered)); }
@Test public void testCannotConcludeConflictQualified() { CertificateWrapper emptyCert = getCertificate(AFTER_EIDAS_DATE); UniqueServiceFilter filter = new UniqueServiceFilter(emptyCert); List<TrustedServiceWrapper> trustServices = new ArrayList<>(); TrustedServiceWrapper ts0 = new TrustedServiceWrapper(); ts0.setServiceNames(Arrays.asList("Test")); ts0.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts0.setStatus(TrustedServiceStatus.GRANTED); ts0.setStartDate(AFTER_EIDAS_DATE); ts0.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_STATEMENT, ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts0); TrustedServiceWrapper ts1 = new TrustedServiceWrapper(); ts1.setServiceNames(Arrays.asList("Test")); ts1.setType(ServiceTypeIdentifier.CA_QC.getUri()); ts1.setStatus(TrustedServiceStatus.GRANTED); ts1.setStartDate(AFTER_EIDAS_DATE); ts1.setCapturedQualifiers(Arrays.asList(ServiceQualification.QC_WITH_QSCD, ServiceQualification.QC_FOR_ESIG)); trustServices.add(ts1); List<TrustedServiceWrapper> filtered = filter.filter(trustServices); assertTrue(Utils.isCollectionEmpty(filtered)); }