OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SessionInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 #include "SessionInfo.h"
18 #include <iomanip>
19 #include <sstream>
20 #include "Catalog.h"
21 
22 namespace Catalog_Namespace {
23 
25  const AccessPrivileges& privs,
26  const std::string& objectName) const {
27  auto& cat = getCatalog();
28  // run flow with DB object level access permission checks
29  DBObject object(objectName, permissionType);
30  if (permissionType == DBObjectType::DatabaseDBObjectType) {
31  object.setName(cat.getCurrentDB().dbName);
32  }
33  object.loadKey(cat);
34  object.setPrivileges(privs);
35  std::vector<DBObject> privObjects;
36  privObjects.push_back(object);
37  return SysCatalog::instance().checkPrivileges(get_currentUser(), privObjects);
38 }
39 
40 // start_time(3)-session_id(4) Example: 819-4RDo
41 // This shows 4 chars of the secret session key,
42 // leaving (32-4)*log2(62) > 166 bits secret.
43 std::string SessionInfo::public_session_id() const {
44  const time_t start_time = get_start_time();
45  struct tm st;
46 #ifdef __linux__
47  localtime_r(&start_time, &st);
48 #else
49  localtime_s(&st, &start_time);
50 #endif
51  std::ostringstream ss;
52  ss << (st.tm_min % 10) << std::setfill('0') << std::setw(2) << st.tm_sec << '-'
53  << session_id_.substr(0, 4);
54  return ss.str();
55 }
56 
57 std::ostream& operator<<(std::ostream& os, const SessionInfo& session_info) {
58  os << session_info.get_public_session_id();
59  return os;
60 }
61 
62 } // namespace Catalog_Namespace
const std::string session_id_
Definition: SessionInfo.h:114
std::string cat(Ts &&...args)
std::string const & get_public_session_id() const
Definition: SessionInfo.h:101
DBObjectType
Definition: DBObject.h:40
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
std::string public_session_id() const
Definition: SessionInfo.cpp:43
This file contains the class specification and related data structures for Catalog.
bool checkPrivileges(const UserMetadata &user, const std::vector< DBObject > &privObjects) const
static SysCatalog & instance()
Definition: SysCatalog.h:343
Catalog & getCatalog() const
Definition: SessionInfo.h:75
time_t get_start_time() const
Definition: SessionInfo.h:100
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88