@Test public void isOrphanKey() { ClientId orphanMember = TestUtils.getClientId("FI:GOV:ORPHAN"); ClientId orphanSubsystemDeleted = TestUtils.getClientId("FI:GOV:ORPHAN:DELETED"); ClientId orphanSubsystemAlive = TestUtils.getClientId("FI:GOV:ORPHAN:ALIVE"); ClientId aliveMember = TestUtils.getClientId("FI:GOV:ALIVE"); CertificateInfo orphanMemberCert = new CertificateInfoBuilder().clientId(orphanMember).build(); CertRequestInfo orphanMemberCsr = new CertRequestInfoBuilder().clientId(orphanMember).build(); CertificateInfo orphanSubstemAliveCert = new CertificateInfoBuilder().clientId(orphanSubsystemAlive).build(); CertificateInfo aliveMemberCert = new CertificateInfoBuilder().clientId(aliveMember).build(); assertTrue(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder().cert(orphanMemberCert).build(), orphanSubsystemDeleted)); assertFalse(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder().cert(orphanMemberCert).build(), aliveMember)); assertTrue(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder().csr(orphanMemberCsr).build(), orphanSubsystemDeleted)); assertFalse(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder().build(), orphanSubsystemDeleted)); assertTrue(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder() .cert(orphanMemberCert) .cert(orphanSubstemAliveCert) .csr(orphanMemberCsr) .build(), orphanSubsystemDeleted)); assertFalse(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder() .cert(orphanMemberCert) .cert(orphanSubstemAliveCert) .cert(aliveMemberCert) .csr(orphanMemberCsr) .build(), orphanSubsystemDeleted)); assertFalse(orphanRemovalService.isOrphanKey( new TokenTestUtils.KeyInfoBuilder() .keyUsageInfo(KeyUsageInfo.AUTHENTICATION) .cert(new CertificateInfoBuilder().clientId(null).build()) .build(), orphanSubsystemDeleted)); }
boolean isOrphanKey(KeyInfo keyInfo, ClientId clientId) { List<CertificateInfo> orphanCerts = getCerts(keyInfo, clientId); List<CertRequestInfo> orphanCsrs = getCsrs(keyInfo, clientId); if (!orphanCerts.isEmpty() || !orphanCsrs.isEmpty()) { List<CertificateInfo> otherCerts = new ArrayList<>(keyInfo.getCerts()); otherCerts.removeAll(orphanCerts); List<CertRequestInfo> otherCsrs = new ArrayList<>(keyInfo.getCertRequests()); otherCsrs.removeAll(orphanCsrs); if (otherCerts.isEmpty() && otherCsrs.isEmpty()) { return true; } } return false; }
OrphanRemovalService { boolean isOrphanKey(KeyInfo keyInfo, ClientId clientId) { List<CertificateInfo> orphanCerts = getCerts(keyInfo, clientId); List<CertRequestInfo> orphanCsrs = getCsrs(keyInfo, clientId); if (!orphanCerts.isEmpty() || !orphanCsrs.isEmpty()) { List<CertificateInfo> otherCerts = new ArrayList<>(keyInfo.getCerts()); otherCerts.removeAll(orphanCerts); List<CertRequestInfo> otherCsrs = new ArrayList<>(keyInfo.getCertRequests()); otherCsrs.removeAll(orphanCsrs); if (otherCerts.isEmpty() && otherCsrs.isEmpty()) { return true; } } return false; } }
OrphanRemovalService { boolean isOrphanKey(KeyInfo keyInfo, ClientId clientId) { List<CertificateInfo> orphanCerts = getCerts(keyInfo, clientId); List<CertRequestInfo> orphanCsrs = getCsrs(keyInfo, clientId); if (!orphanCerts.isEmpty() || !orphanCsrs.isEmpty()) { List<CertificateInfo> otherCerts = new ArrayList<>(keyInfo.getCerts()); otherCerts.removeAll(orphanCerts); List<CertRequestInfo> otherCsrs = new ArrayList<>(keyInfo.getCertRequests()); otherCsrs.removeAll(orphanCsrs); if (otherCerts.isEmpty() && otherCsrs.isEmpty()) { return true; } } return false; } @Autowired  OrphanRemovalService(TokenService tokenService,
            TokenCertificateService tokenCertificateService,
            ClientService clientService,
            KeyService keyService,
            AuditDataHelper auditDataHelper); }
OrphanRemovalService { boolean isOrphanKey(KeyInfo keyInfo, ClientId clientId) { List<CertificateInfo> orphanCerts = getCerts(keyInfo, clientId); List<CertRequestInfo> orphanCsrs = getCsrs(keyInfo, clientId); if (!orphanCerts.isEmpty() || !orphanCsrs.isEmpty()) { List<CertificateInfo> otherCerts = new ArrayList<>(keyInfo.getCerts()); otherCerts.removeAll(orphanCerts); List<CertRequestInfo> otherCsrs = new ArrayList<>(keyInfo.getCertRequests()); otherCsrs.removeAll(orphanCsrs); if (otherCerts.isEmpty() && otherCsrs.isEmpty()) { return true; } } return false; } @Autowired  OrphanRemovalService(TokenService tokenService,
            TokenCertificateService tokenCertificateService,
            ClientService clientService,
            KeyService keyService,
            AuditDataHelper auditDataHelper); boolean orphansExist(ClientId clientId); void deleteOrphans(ClientId clientId); }
OrphanRemovalService { boolean isOrphanKey(KeyInfo keyInfo, ClientId clientId) { List<CertificateInfo> orphanCerts = getCerts(keyInfo, clientId); List<CertRequestInfo> orphanCsrs = getCsrs(keyInfo, clientId); if (!orphanCerts.isEmpty() || !orphanCsrs.isEmpty()) { List<CertificateInfo> otherCerts = new ArrayList<>(keyInfo.getCerts()); otherCerts.removeAll(orphanCerts); List<CertRequestInfo> otherCsrs = new ArrayList<>(keyInfo.getCertRequests()); otherCsrs.removeAll(orphanCsrs); if (otherCerts.isEmpty() && otherCsrs.isEmpty()) { return true; } } return false; } @Autowired  OrphanRemovalService(TokenService tokenService,
            TokenCertificateService tokenCertificateService,
            ClientService clientService,
            KeyService keyService,
            AuditDataHelper auditDataHelper); boolean orphansExist(ClientId clientId); void deleteOrphans(ClientId clientId);  }