@Test public void buildPath() { X509Certificate certificate = CertificateTestUtils.getMockAuthCertificate(); String subject = MOCK_AUTH_CERT_SUBJECT; String issuer = MOCK_AUTH_CERT_ISSUER; assertEquals(subject, certificate.getSubjectDN().getName()); assertEquals(issuer, certificate.getIssuerDN().getName()); Map<String, String> subjectsToIssuers = new HashMap<>(); subjectsToIssuers.put(subject, issuer); subjectsToIssuers.put(issuer, "a"); subjectsToIssuers.put("a", "b"); subjectsToIssuers.put("b", "c"); subjectsToIssuers.put("c", "c"); List<String> path = certificateAuthorityService.buildPath(certificate, subjectsToIssuers); assertEquals(Arrays.asList("c", "b", "a", issuer, subject), path); subjectsToIssuers = new HashMap<>(); subjectsToIssuers.put(subject, issuer); subjectsToIssuers.put(issuer, "a"); subjectsToIssuers.put("a", "b"); subjectsToIssuers.put("b", "c"); path = certificateAuthorityService.buildPath(certificate, subjectsToIssuers); assertEquals(Arrays.asList("b", "a", issuer, subject), path); subjectsToIssuers = new HashMap<>(); subjectsToIssuers.put(subject, issuer); subjectsToIssuers.put(issuer, issuer); path = certificateAuthorityService.buildPath(certificate, subjectsToIssuers); assertEquals(Arrays.asList(issuer, subject), path); subjectsToIssuers = new HashMap<>(); subjectsToIssuers.put(subject, issuer); path = certificateAuthorityService.buildPath(certificate, subjectsToIssuers); assertEquals(Collections.singletonList(subject), path); certificate = CertificateTestUtils.getMockCertificate(); subject = "CN=N/A"; issuer = "CN=N/A"; assertEquals(subject, certificate.getSubjectDN().getName()); assertEquals(issuer, certificate.getIssuerDN().getName()); subjectsToIssuers = new HashMap<>(); subjectsToIssuers.put(subject, issuer); subjectsToIssuers.put(issuer, "a"); subjectsToIssuers.put("a", "b"); subjectsToIssuers.put("b", "c"); path = certificateAuthorityService.buildPath(certificate, subjectsToIssuers); assertEquals(Collections.singletonList(subject), path); }
List<String> buildPath(X509Certificate certificate, Map<String, String> subjectsToIssuers) { ArrayList<String> pathElements = new ArrayList<>(); String current = certificate.getSubjectDN().getName(); String issuer = certificate.getIssuerDN().getName(); pathElements.add(current); while (!current.equals(issuer) && subjectsToIssuers.containsKey(issuer)) { pathElements.add(0, issuer); current = issuer; issuer = subjectsToIssuers.get(current); } return pathElements; }
CertificateAuthorityService { List<String> buildPath(X509Certificate certificate, Map<String, String> subjectsToIssuers) { ArrayList<String> pathElements = new ArrayList<>(); String current = certificate.getSubjectDN().getName(); String issuer = certificate.getIssuerDN().getName(); pathElements.add(current); while (!current.equals(issuer) && subjectsToIssuers.containsKey(issuer)) { pathElements.add(0, issuer); current = issuer; issuer = subjectsToIssuers.get(current); } return pathElements; } }
CertificateAuthorityService { List<String> buildPath(X509Certificate certificate, Map<String, String> subjectsToIssuers) { ArrayList<String> pathElements = new ArrayList<>(); String current = certificate.getSubjectDN().getName(); String issuer = certificate.getIssuerDN().getName(); pathElements.add(current); while (!current.equals(issuer) && subjectsToIssuers.containsKey(issuer)) { pathElements.add(0, issuer); current = issuer; issuer = subjectsToIssuers.get(current); } return pathElements; } @Autowired  CertificateAuthorityService(GlobalConfService globalConfService,
            GlobalConfFacade globalConfFacade,
            ClientService clientService,
            SignerProxyFacade signerProxyFacade,
            CurrentSecurityServerId currentSecurityServerId); }
CertificateAuthorityService { List<String> buildPath(X509Certificate certificate, Map<String, String> subjectsToIssuers) { ArrayList<String> pathElements = new ArrayList<>(); String current = certificate.getSubjectDN().getName(); String issuer = certificate.getIssuerDN().getName(); pathElements.add(current); while (!current.equals(issuer) && subjectsToIssuers.containsKey(issuer)) { pathElements.add(0, issuer); current = issuer; issuer = subjectsToIssuers.get(current); } return pathElements; } @Autowired  CertificateAuthorityService(GlobalConfService globalConfService,
            GlobalConfFacade globalConfFacade,
            ClientService clientService,
            SignerProxyFacade signerProxyFacade,
            CurrentSecurityServerId currentSecurityServerId); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo,
            boolean includeIntermediateCas); CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId,
            boolean isNewMember); ApprovedCAInfo getCertificateAuthorityInfo(String caName); }
CertificateAuthorityService { List<String> buildPath(X509Certificate certificate, Map<String, String> subjectsToIssuers) { ArrayList<String> pathElements = new ArrayList<>(); String current = certificate.getSubjectDN().getName(); String issuer = certificate.getIssuerDN().getName(); pathElements.add(current); while (!current.equals(issuer) && subjectsToIssuers.containsKey(issuer)) { pathElements.add(0, issuer); current = issuer; issuer = subjectsToIssuers.get(current); } return pathElements; } @Autowired  CertificateAuthorityService(GlobalConfService globalConfService,
            GlobalConfFacade globalConfFacade,
            ClientService clientService,
            SignerProxyFacade signerProxyFacade,
            CurrentSecurityServerId currentSecurityServerId); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo,
            boolean includeIntermediateCas); CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId,
            boolean isNewMember); ApprovedCAInfo getCertificateAuthorityInfo(String caName); static final String OCSP_RESPONSE_NOT_AVAILABLE; }