class KeyService {

    public KeyInfo updateKeyFriendlyName(String id, String friendlyName) throws KeyNotFoundException,
            ActionNotPossibleException {

        // check that updating friendly name is possible
        TokenInfo tokenInfo = tokenService.getTokenForKeyId(id);

        KeyInfo keyInfo = getKey(tokenInfo, id);
        auditDataHelper.put(KEY_ID, keyInfo.getId());
        auditDataHelper.put(KEY_FRIENDLY_NAME, friendlyName);
        possibleActionsRuleEngine.requirePossibleKeyAction(PossibleActionEnum.EDIT_FRIENDLY_NAME,
                tokenInfo, keyInfo);

        try {
            signerProxyFacade.setKeyFriendlyName(id, friendlyName);
            keyInfo = getKey(id);
        } catch (KeyNotFoundException e) {
            throw e;
        } catch (CodedException e) {
            if (isCausedByKeyNotFound(e)) {
                throw new KeyNotFoundException(e);
            } else {
                throw e;
            }
        } catch (Exception e) {
            throw new SignerNotReachableException("Update key friendly name failed", e);
        }

        return keyInfo;
    }

    @Autowired public  KeyService(TokenService tokenService, SignerProxyFacade signerProxyFacade,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            ManagementRequestSenderService managementRequestSenderService,
            SecurityHelper securityHelper,
            AuditDataHelper auditDataHelper,
            AuditEventHelper auditEventHelper,
            AuditEventLoggingFacade auditEventLoggingFacade);

}