OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SessionInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SESSION_INFO_H
18 #define SESSION_INFO_H
19 
20 #include <atomic>
21 #include <cstdint>
22 #include <ctime>
23 #include <limits>
24 #include <list>
25 #include <map>
26 #include <memory>
27 #include <mutex>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include "Catalog/SysCatalog.h"
34 #include "Shared/Restriction.h"
36 
37 #include "LeafHostInfo.h"
38 
39 namespace Catalog_Namespace {
40 
41 class Catalog;
42 
43 /*
44  * @type SessionInfo
45  * @brief a user session
46  */
47 class SessionInfo {
48  public:
49  SessionInfo(std::shared_ptr<Catalog> cat,
50  const UserMetadata& user,
51  const ExecutorDeviceType t,
52  const std::string& sid)
53  : catalog_(cat)
54  , currentUser_(user)
56  , session_id_(sid)
57  , last_used_time_(time(0))
58  , start_time_(time(0))
61  : catalog_(s.catalog_)
67  Catalog& getCatalog() const {
68  CHECK(catalog_);
69  return *catalog_;
70  }
71  std::shared_ptr<Catalog> get_catalog_ptr() const { return catalog_; }
72  void set_catalog_ptr(std::shared_ptr<Catalog> c) { catalog_ = c; }
73  const UserMetadata& get_currentUser() const { return currentUser_; }
75  return executor_device_type_;
76  }
78  std::string get_session_id() const { return session_id_; }
79  time_t get_last_used_time() const { return last_used_time_; }
80  void update_last_used_time() { last_used_time_ = time(0); }
81  bool checkDBAccessPrivileges(const DBObjectType& permissionType,
82  const AccessPrivileges& privs,
83  const std::string& objectName = "") const;
84  time_t get_start_time() const { return start_time_; }
85  std::string const& get_public_session_id() const { return public_session_id_; }
86  operator std::string() const { return public_session_id_; }
87  std::string const& get_connection_info() const { return connection_info_; }
88  void set_connection_info(const std::string& connection) {
89  connection_info_ = connection;
90  }
91  void set_restriction(std::shared_ptr<Restriction> r) { restriction_ = r; }
92  std::shared_ptr<Restriction> get_restriction_ptr() const { return restriction_; }
93 
94  private:
95  std::shared_ptr<Catalog> catalog_;
97  std::atomic<ExecutorDeviceType> executor_device_type_;
98  const std::string session_id_;
99  std::atomic<time_t> last_used_time_; // for tracking active session duration
100  std::atomic<time_t> start_time_; // for invalidating session after tolerance period
101  const std::string public_session_id_;
102  std::shared_ptr<Restriction> restriction_;
103  std::string
104  connection_info_; // String containing connection protocol (tcp/http) and address
105  std::string public_session_id() const;
106 };
107 
108 std::ostream& operator<<(std::ostream& os, const SessionInfo& session_info);
109 
110 } // namespace Catalog_Namespace
111 
112 #endif /* SESSION_INFO_H */
std::shared_ptr< Catalog > catalog_
Definition: SessionInfo.h:95
const std::string session_id_
Definition: SessionInfo.h:98
std::string cat(Ts &&...args)
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:111
std::string const & get_public_session_id() const
Definition: SessionInfo.h:85
DBObjectType
Definition: DBObject.h:42
ExecutorDeviceType
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
const std::string public_session_id_
Definition: SessionInfo.h:101
std::atomic< time_t > last_used_time_
Definition: SessionInfo.h:99
SessionInfo(const SessionInfo &s)
Definition: SessionInfo.h:60
std::string public_session_id() const
Definition: SessionInfo.cpp:43
std::atomic< time_t > start_time_
Definition: SessionInfo.h:100
std::atomic< ExecutorDeviceType > executor_device_type_
Definition: SessionInfo.h:97
This file contains the class specification and related data structures for SysCatalog.
SessionInfo(std::shared_ptr< Catalog > cat, const UserMetadata &user, const ExecutorDeviceType t, const std::string &sid)
Definition: SessionInfo.h:49
std::string const & get_connection_info() const
Definition: SessionInfo.h:87
void set_restriction(std::shared_ptr< Restriction > r)
Definition: SessionInfo.h:91
std::shared_ptr< Catalog > get_catalog_ptr() const
Definition: SessionInfo.h:71
std::string get_session_id() const
Definition: SessionInfo.h:78
std::shared_ptr< Restriction > get_restriction_ptr() const
Definition: SessionInfo.h:92
Catalog & getCatalog() const
Definition: SessionInfo.h:67
time_t get_start_time() const
Definition: SessionInfo.h:84
#define CHECK(condition)
Definition: Logger.h:209
char * t
std::shared_ptr< Restriction > restriction_
Definition: SessionInfo.h:102
void set_executor_device_type(ExecutorDeviceType t)
Definition: SessionInfo.h:77
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
void set_catalog_ptr(std::shared_ptr< Catalog > c)
Definition: SessionInfo.h:72
time_t get_last_used_time() const
Definition: SessionInfo.h:79
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:74
void set_connection_info(const std::string &connection)
Definition: SessionInfo.h:88