aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/misc/src_checker.h
blob: bb99fe8884a8eb145f82f11491d7e333482b7aa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include "roles/roles.h"

#include <library/cpp/tvmauth/client/exception.h>

#include <library/cpp/tvmauth/checked_service_ticket.h>
#include <library/cpp/tvmauth/src/service_impl.h>
#include <library/cpp/tvmauth/src/utils.h>

namespace NTvmAuth {
    class TSrcChecker {
    public:
        /*!
         * Checking must be enabled in TClientSettings
         * Can throw exception if cache is out of date or wrong config
         * @param ticket
         */
        static TCheckedServiceTicket Check(TCheckedServiceTicket ticket, NRoles::TRolesPtr r) {
            Y_ENSURE_EX(r, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableRolesFetching()");
            NRoles::TConsumerRolesPtr roles = r->GetRolesForService(ticket);
            if (roles) {
                return ticket;
            }

            TServiceTicketImplPtr impl = THolder(NInternal::TCanningKnife::GetS(ticket));
            impl->SetStatus(ETicketStatus::NoRoles);
            return TCheckedServiceTicket(std::move(impl));
        }
    };
}