@Override public APIMessage intercept(APIMessage msg) throws ApiMessageInterceptionException { // login, logout if (msg.getSession() == null) { return msg; } // skip admin. if needed, another quota check will be issued in AccountManagerImpl if (new QuotaUtil().isAdminAccount(msg.getSession().getAccountUuid())) { return msg; } List<Quota> quotas = acntMgr.getMessageQuotaMap().get(msg.getClass()); if (quotas == null || quotas.size() == 0) { return msg; } for (Quota q : quotas) { check(msg, q); } return msg; }
@Override public void beforeDeliveryMessage(Message msg) { if (msg instanceof NeedQuotaCheckMessage) { if (((NeedQuotaCheckMessage) msg).getAccountUuid() == null || ((NeedQuotaCheckMessage) msg).getAccountUuid().equals("")) { // skip admin scheduler return; } List<Quota> quotas = acntMgr.getMessageQuotaMap().get(msg.getClass()); if (quotas == null || quotas.size() == 0) { return; } Map<String, Quota.QuotaPair> pairs = new QuotaUtil(). makeQuotaPairs(((NeedQuotaCheckMessage) msg).getAccountUuid()); for (Quota quota : quotas) { quota.getOperator().checkQuota((NeedQuotaCheckMessage) msg, pairs); } } } }, VolumeCreateSnapshotMsg.class, CreateVolumeSnapshotMsg.class);
@Override public void check(RBACEntity entity) { if (acntMgr.isAdmin(entity.getApiMessage().getSession())) { return; } List<Quota> quotas = acntMgr.getMessageQuotaMap().get(entity.getApiMessage().getClass()); if (quotas == null || quotas.isEmpty()) { return; } quotas.forEach(quota -> { Map<String, Quota.QuotaPair> pairs = new QuotaUtil().makeQuotaPairs(entity.getApiMessage().getSession().getAccountUuid()); quota.getOperator().checkQuota(entity.getApiMessage(), pairs); if (quota.getQuotaValidators() != null) { for (Quota.QuotaValidator q : quota.getQuotaValidators()) { q.checkQuota(entity.getApiMessage(), pairs); } } }); } }