@Test @WithMockUser(authorities = { "DELETE_AUTH_KEY", "DELETE_SIGN_KEY", "DELETE_KEY" }) public void cantDeleteOrphansForDifferentReasons() throws Exception { try { orphanRemovalService.deleteOrphans(NON_DELETED_CLIENT_ID_O1); fail("should throw exception"); } catch (OrphanRemovalService.OrphansNotFoundException expected) { } try { orphanRemovalService.deleteOrphans(DELETED_CLIENT_ID_WITH_SIBLINGS_O3); fail("should throw exception"); } catch (OrphanRemovalService.OrphansNotFoundException expected) { } try { orphanRemovalService.deleteOrphans(DELETED_CLIENT_ID_WITHOUT_ORPHAN_ITEMS_O4); fail("should throw exception"); } catch (OrphanRemovalService.OrphansNotFoundException expected) { } }
public void deleteOrphans(ClientId clientId) throws OrphansNotFoundException, ActionNotPossibleException, GlobalConfOutdatedException { auditDataHelper.put(clientId); if (isAlive(clientId) || hasAliveSiblings(clientId)) { throw new OrphansNotFoundException(); } Orphans orphans = findOrphans(clientId); if (orphans.isEmpty()) { throw new OrphansNotFoundException(); } try { for (KeyInfo keyInfo : orphans.getKeys()) { keyService.deleteKeyAndIgnoreWarnings(keyInfo.getId()); } tokenCertificateService.deleteCertificates(orphans.getCerts()); for (CertRequestInfo certRequestInfo : orphans.getCsrs()) { tokenCertificateService.deleteCsr(certRequestInfo.getId()); } } catch (KeyNotFoundException | CsrNotFoundException | CertificateNotFoundException e) { throw new RuntimeException(e); } }
OrphanRemovalService { public void deleteOrphans(ClientId clientId) throws OrphansNotFoundException, ActionNotPossibleException, GlobalConfOutdatedException { auditDataHelper.put(clientId); if (isAlive(clientId) || hasAliveSiblings(clientId)) { throw new OrphansNotFoundException(); } Orphans orphans = findOrphans(clientId); if (orphans.isEmpty()) { throw new OrphansNotFoundException(); } try { for (KeyInfo keyInfo : orphans.getKeys()) { keyService.deleteKeyAndIgnoreWarnings(keyInfo.getId()); } tokenCertificateService.deleteCertificates(orphans.getCerts()); for (CertRequestInfo certRequestInfo : orphans.getCsrs()) { tokenCertificateService.deleteCsr(certRequestInfo.getId()); } } catch (KeyNotFoundException | CsrNotFoundException | CertificateNotFoundException e) { throw new RuntimeException(e); } } }
OrphanRemovalService { public void deleteOrphans(ClientId clientId) throws OrphansNotFoundException, ActionNotPossibleException, GlobalConfOutdatedException { auditDataHelper.put(clientId); if (isAlive(clientId) || hasAliveSiblings(clientId)) { throw new OrphansNotFoundException(); } Orphans orphans = findOrphans(clientId); if (orphans.isEmpty()) { throw new OrphansNotFoundException(); } try { for (KeyInfo keyInfo : orphans.getKeys()) { keyService.deleteKeyAndIgnoreWarnings(keyInfo.getId()); } tokenCertificateService.deleteCertificates(orphans.getCerts()); for (CertRequestInfo certRequestInfo : orphans.getCsrs()) { tokenCertificateService.deleteCsr(certRequestInfo.getId()); } } catch (KeyNotFoundException | CsrNotFoundException | CertificateNotFoundException e) { throw new RuntimeException(e); } } @Autowired  OrphanRemovalService(TokenService tokenService,
            TokenCertificateService tokenCertificateService,
            ClientService clientService,
            KeyService keyService,
            AuditDataHelper auditDataHelper); }
OrphanRemovalService { public void deleteOrphans(ClientId clientId) throws OrphansNotFoundException, ActionNotPossibleException, GlobalConfOutdatedException { auditDataHelper.put(clientId); if (isAlive(clientId) || hasAliveSiblings(clientId)) { throw new OrphansNotFoundException(); } Orphans orphans = findOrphans(clientId); if (orphans.isEmpty()) { throw new OrphansNotFoundException(); } try { for (KeyInfo keyInfo : orphans.getKeys()) { keyService.deleteKeyAndIgnoreWarnings(keyInfo.getId()); } tokenCertificateService.deleteCertificates(orphans.getCerts()); for (CertRequestInfo certRequestInfo : orphans.getCsrs()) { tokenCertificateService.deleteCsr(certRequestInfo.getId()); } } catch (KeyNotFoundException | CsrNotFoundException | CertificateNotFoundException e) { throw new RuntimeException(e); } } @Autowired  OrphanRemovalService(TokenService tokenService,
            TokenCertificateService tokenCertificateService,
            ClientService clientService,
            KeyService keyService,
            AuditDataHelper auditDataHelper); boolean orphansExist(ClientId clientId); void deleteOrphans(ClientId clientId); }
OrphanRemovalService { public void deleteOrphans(ClientId clientId) throws OrphansNotFoundException, ActionNotPossibleException, GlobalConfOutdatedException { auditDataHelper.put(clientId); if (isAlive(clientId) || hasAliveSiblings(clientId)) { throw new OrphansNotFoundException(); } Orphans orphans = findOrphans(clientId); if (orphans.isEmpty()) { throw new OrphansNotFoundException(); } try { for (KeyInfo keyInfo : orphans.getKeys()) { keyService.deleteKeyAndIgnoreWarnings(keyInfo.getId()); } tokenCertificateService.deleteCertificates(orphans.getCerts()); for (CertRequestInfo certRequestInfo : orphans.getCsrs()) { tokenCertificateService.deleteCsr(certRequestInfo.getId()); } } catch (KeyNotFoundException | CsrNotFoundException | CertificateNotFoundException e) { throw new RuntimeException(e); } } @Autowired  OrphanRemovalService(TokenService tokenService,
            TokenCertificateService tokenCertificateService,
            ClientService clientService,
            KeyService keyService,
            AuditDataHelper auditDataHelper); boolean orphansExist(ClientId clientId); void deleteOrphans(ClientId clientId);  }