OmniSciDB  a47db9e897
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SessionInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 MapD Technologies, 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  localtime_r(&start_time, &st);
47  std::ostringstream ss;
48  ss << (st.tm_min % 10) << std::setfill('0') << std::setw(2) << st.tm_sec << '-'
49  << session_id_.substr(0, 4);
50  return ss.str();
51 }
52 
53 std::ostream& operator<<(std::ostream& os, const SessionInfo& session_info) {
54  os << session_info.get_public_session_id();
55  return os;
56 }
57 
58 } // namespace Catalog_Namespace
const std::string session_id_
Definition: SessionInfo.h:113
std::string const & get_public_session_id() const
Definition: SessionInfo.h:105
DBObjectType
Definition: DBObject.h:42
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:53
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:242
Catalog & getCatalog() const
Definition: SessionInfo.h:90
time_t get_start_time() const
Definition: SessionInfo.h:104
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:93