OmniSciDB  f632821e96
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"
35 
36 #include "LeafHostInfo.h"
37 
38 namespace Catalog_Namespace {
39 
40 class Catalog;
41 
42 /*
43  * @type SessionInfo
44  * @brief a user session
45  */
46 class SessionInfo {
47  public:
48  SessionInfo(std::shared_ptr<Catalog> cat,
49  const UserMetadata& user,
50  const ExecutorDeviceType t,
51  const std::string& sid)
52  : catalog_(cat)
53  , currentUser_(user)
55  , session_id_(sid)
56  , last_used_time_(time(0))
57  , start_time_(time(0))
60  : catalog_(s.catalog_)
65  Catalog& getCatalog() const { return *catalog_; }
66  std::shared_ptr<Catalog> get_catalog_ptr() const { return catalog_; }
67  void set_catalog_ptr(std::shared_ptr<Catalog> c) { catalog_ = c; }
68  const UserMetadata& get_currentUser() const { return currentUser_; }
70  return executor_device_type_;
71  }
73  std::string get_session_id() const { return session_id_; }
74  time_t get_last_used_time() const { return last_used_time_; }
75  void update_last_used_time() { last_used_time_ = time(0); }
76  bool checkDBAccessPrivileges(const DBObjectType& permissionType,
77  const AccessPrivileges& privs,
78  const std::string& objectName = "") const;
79  time_t get_start_time() const { return start_time_; }
80  std::string const& get_public_session_id() const { return public_session_id_; }
81  operator std::string() const { return public_session_id_; }
82  std::string const& get_connection_info() const { return connection_info_; }
83  void set_connection_info(const std::string& connection) {
84  connection_info_ = connection;
85  }
86 
87  private:
88  std::shared_ptr<Catalog> catalog_;
90  std::atomic<ExecutorDeviceType> executor_device_type_;
91  const std::string session_id_;
92  std::atomic<time_t> last_used_time_; // for tracking active session duration
93  std::atomic<time_t> start_time_; // for invalidating session after tolerance period
94  const std::string public_session_id_;
95  std::string
96  connection_info_; // String containing connection protocol (tcp/http) and address
97  std::string public_session_id() const;
98 };
99 
100 std::ostream& operator<<(std::ostream& os, const SessionInfo& session_info);
101 
102 } // namespace Catalog_Namespace
103 
104 #endif /* SESSION_INFO_H */
time_t get_last_used_time() const
Definition: SessionInfo.h:74
std::shared_ptr< Catalog > catalog_
Definition: SessionInfo.h:88
const std::string session_id_
Definition: SessionInfo.h:91
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
DBObjectType
Definition: DBObject.h:42
ExecutorDeviceType
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:53
const std::string public_session_id_
Definition: SessionInfo.h:94
std::shared_ptr< Catalog > get_catalog_ptr() const
Definition: SessionInfo.h:66
std::atomic< time_t > last_used_time_
Definition: SessionInfo.h:92
SessionInfo(const SessionInfo &s)
Definition: SessionInfo.h:59
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
std::string get_session_id() const
Definition: SessionInfo.h:73
std::atomic< time_t > start_time_
Definition: SessionInfo.h:93
std::atomic< ExecutorDeviceType > executor_device_type_
Definition: SessionInfo.h:90
This file contains the class specification and related data structures for SysCatalog.
std::string cat(Ts &&... args)
SessionInfo(std::shared_ptr< Catalog > cat, const UserMetadata &user, const ExecutorDeviceType t, const std::string &sid)
Definition: SessionInfo.h:48
Catalog & getCatalog() const
Definition: SessionInfo.h:65
std::string const & get_connection_info() const
Definition: SessionInfo.h:82
std::string public_session_id() const
Definition: SessionInfo.cpp:43
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
void set_executor_device_type(ExecutorDeviceType t)
Definition: SessionInfo.h:72
void set_catalog_ptr(std::shared_ptr< Catalog > c)
Definition: SessionInfo.h:67
std::string const & get_public_session_id() const
Definition: SessionInfo.h:80
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:69
void set_connection_info(const std::string &connection)
Definition: SessionInfo.h:83