aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Access/ContextAccessParams.h
blob: 8b68fa44ed4e0a3388bcc6b5b60b0015fd775147 (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
#pragma once

#include <Interpreters/ClientInfo.h>
#include <Core/UUID.h>
#include <optional>
#include <vector>


namespace DB
{
struct Settings;

/// Parameters which are used to calculate access rights and some related stuff like roles or constraints.
class ContextAccessParams
{
public:
    ContextAccessParams(
        const std::optional<UUID> user_id_,
        bool full_access_,
        bool use_default_roles_,
        const std::shared_ptr<const std::vector<UUID>> & current_roles_,
        const Settings & settings_,
        const String & current_database_,
        const ClientInfo & client_info_);

    const std::optional<UUID> user_id;

    /// Full access to everything without any limitations.
    /// This is used for the global context.
    const bool full_access;

    const bool use_default_roles;
    const std::shared_ptr<const std::vector<UUID>> current_roles;

    const UInt64 readonly;
    const bool allow_ddl;
    const bool allow_introspection;

    const String current_database;

    const ClientInfo::Interface interface;
    const ClientInfo::HTTPMethod http_method;
    const Poco::Net::IPAddress address;

    /// The last entry from comma separated list of X-Forwarded-For addresses.
    /// Only the last proxy can be trusted (if any).
    const String forwarded_address;

    const String quota_key;

    /// Initial user is used to combine row policies with.
    const String initial_user;

    /// Outputs `ContextAccessParams` to string for logging.
    String toString() const;

    friend bool operator <(const ContextAccessParams & left, const ContextAccessParams & right);
    friend bool operator ==(const ContextAccessParams & left, const ContextAccessParams & right);
    friend bool operator !=(const ContextAccessParams & left, const ContextAccessParams & right) { return !(left == right); }
    friend bool operator >(const ContextAccessParams & left, const ContextAccessParams & right) { return right < left; }
    friend bool operator <=(const ContextAccessParams & left, const ContextAccessParams & right) { return !(right < left); }
    friend bool operator >=(const ContextAccessParams & left, const ContextAccessParams & right) { return !(left < right); }

    static bool dependsOnSettingName(std::string_view setting_name);
};

}