@Test @WithMockUser(authorities = { "DELETE_AUTH_KEY", "DELETE_SIGN_KEY", "DELETE_KEY" }) public void deleteOrphanCertKey() throws Exception { orphanRemovalService.deleteOrphans(DELETED_CLIENT_ID_WITH_ORPHAN_CERT_O6); verify(signerProxyFacade, atLeast(0)).getTokens(); verify(signerProxyFacade, atLeast(0)).getTokenForKeyId(any()); verify(signerProxyFacade, times(1)) .deleteKey(KEY_06_ID, true); verify(signerProxyFacade, times(1)) .deleteKey(KEY_06_ID, false); verifyNoMoreInteractions(signerProxyFacade); }
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);  }