class TokenCertificateService {

    public void deleteCsr(String csrId) throws KeyNotFoundException, CsrNotFoundException,
            ActionNotPossibleException {

        // different audit fields for these events
        if (auditDataHelper.dataIsForEvent(RestApiAuditEvent.DELETE_ORPHANS)) {
            auditDataHelper.addListPropertyItem(CERT_REQUEST_IDS, csrId);
        } else if (auditDataHelper.dataIsForEvent(RestApiAuditEvent.DELETE_CSR)) {
            auditDataHelper.put(CSR_ID, csrId);
        }

        TokenInfoAndKeyId tokenInfoAndKeyId = tokenService.getTokenAndKeyIdForCertificateRequestId(csrId);
        TokenInfo tokenInfo = tokenInfoAndKeyId.getTokenInfo();
        KeyInfo keyInfo = tokenInfoAndKeyId.getKeyInfo();
        if (auditDataHelper.dataIsForEvent(RestApiAuditEvent.DELETE_CSR)) {
            auditDataHelper.put(tokenInfo);
            auditDataHelper.put(keyInfo);
        }
        CertRequestInfo certRequestInfo = getCsr(keyInfo, csrId);

        if (keyInfo.isForSigning()) {
            securityHelper.verifyAuthority("DELETE_SIGN_CERT");
        } else {
            securityHelper.verifyAuthority("DELETE_AUTH_CERT");
        }

        // check that delete is possible
        possibleActionsRuleEngine.requirePossibleCsrAction(
                PossibleActionEnum.DELETE, tokenInfo, keyInfo, certRequestInfo);

        try {
            signerProxyFacade.deleteCertRequest(csrId);
        } catch (CodedException e) {
            if (isCausedByCsrNotFound(e)) {
                throw new CsrNotFoundException(e);
            } else {
                throw e;
            }
        } catch (Exception other) {
            throw new SignerNotReachableException("deleting a csr failed", other);
        }
    }

    @Autowired @SuppressWarnings("checkstyle:ParameterNumber") public  TokenCertificateService(SignerProxyFacade signerProxyFacade, ClientService clientService,
            CertificateAuthorityService certificateAuthorityService, KeyService keyService, DnFieldHelper dnFieldHelper,
            GlobalConfService globalConfService, GlobalConfFacade globalConfFacade, ClientRepository clientRepository,
            ManagementRequestSenderService managementRequestSenderService, ServerConfService serverConfService,
            PossibleActionsRuleEngine possibleActionsRuleEngine, TokenService tokenService,
            SecurityHelper securityHelper, AuditDataHelper auditDataHelper,
            AuditEventHelper auditEventHelper);

}