aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/src/user_impl.h
blob: 7be3b9b4ea89ec8d51d4dd815aa59737dd31cbc8 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> 
#include <library/cpp/tvmauth/src/protos/tvm_keys.pb.h> 
#include <library/cpp/tvmauth/src/rw/keys.h> 

#include <library/cpp/tvmauth/deprecated/user_context.h> 

#include <library/cpp/charset/ci_string.h> 

#include <unordered_map>

namespace NTvmAuth { 
    using TUserTicketImplPtr = THolder<TCheckedUserTicket::TImpl>; 
    class TCheckedUserTicket::TImpl { 
    public:
        explicit operator bool() const;

        TUid GetDefaultUid() const;
        time_t GetExpirationTime() const;
        const TScopes& GetScopes() const;
        bool HasScope(TStringBuf scopeName) const;
        ETicketStatus GetStatus() const; 
        const TUids& GetUids() const;

        TString DebugInfo() const;

        EBlackboxEnv GetEnv() const; 
 
        void SetStatus(ETicketStatus status); 
 
        /*!
     * Constructor for creation invalid ticket storing error status in TServiceContext
     * @param status
     * @param protobufTicket
     */
        TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket); 

        static TUserTicketImplPtr CreateTicketForTests(ETicketStatus status, 
                                                       TUid defaultUid, 
                                                       TScopes scopes, 
                                                       TUids uids, 
                                                       EBlackboxEnv env = EBlackboxEnv::Test); 
 
    private:
        static const int MaxUserCount = 15;

        ETicketStatus Status_; 
        ticket2::Ticket ProtobufTicket_; 
        mutable TScopes CachedScopes_; 
        mutable TUids CachedUids_; 
        mutable TString CachedDebugInfo_; 
    };

    class TUserContext::TImpl {
    public:
        TImpl(EBlackboxEnv env, TStringBuf tvmKeysResponse);
        void ResetKeys(TStringBuf tvmKeysResponse);

        TUserTicketImplPtr Check(TStringBuf ticketBody) const;
        const NRw::TPublicKeys& GetKeys() const;

        bool IsAllowed(tvm_keys::BbEnvType env) const; 

    private:
        ETicketStatus CheckProtobufUserTicket(const ticket2::Ticket& ticket) const; 

        NRw::TPublicKeys Keys_; 
        EBlackboxEnv Env_; 
        ::google::protobuf::LogSilencer LogSilencer_; 
    };
}