Commit 4a909584 authored by Steven Murray's avatar Steven Murray
Browse files

cta/CTA#287 Admin users should be cached

Done.
parent eeabd288
......@@ -54,7 +54,8 @@ RdbmsCatalogue::RdbmsCatalogue(
m_tapeCopyToPoolCache(10),
m_groupMountPolicyCache(10),
m_userMountPolicyCache(10),
m_expectedNbArchiveRoutesCache(10) {
m_expectedNbArchiveRoutesCache(10),
m_isAdminCache(10) {
}
//------------------------------------------------------------------------------
......@@ -4378,6 +4379,38 @@ RequesterAndGroupMountPolicies RdbmsCatalogue::getMountPolicies(
// isAdmin
//------------------------------------------------------------------------------
bool RdbmsCatalogue::isAdmin(const common::dataStructures::SecurityIdentity &admin) const {
try {
return isCachedAdmin(admin);
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// isCachedAdmin
//------------------------------------------------------------------------------
bool RdbmsCatalogue::isCachedAdmin(const common::dataStructures::SecurityIdentity &admin)
const {
try {
auto getNonCachedValue = [&] {
return isNonCachedAdmin(admin);
};
return m_isAdminCache.getCachedValue(admin, getNonCachedValue);
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// isNonCachedAdmin
//------------------------------------------------------------------------------
bool RdbmsCatalogue::isNonCachedAdmin(const common::dataStructures::SecurityIdentity &admin) const {
try {
const char *const sql =
"SELECT "
......
......@@ -1143,6 +1143,24 @@ protected:
*/
void checkTapeFileWrittenFieldsAreSet(const std::string &callingFunc, const TapeFileWritten &event) const;
/**
* Returns a cached version of the result of calling isAdmin().
*
* @param admin The administrator.
* @return True if the specified user has administrator privileges.
*/
bool isCachedAdmin(const common::dataStructures::SecurityIdentity &admin) const;
/**
* Returns true if the specified user has administrator privileges.
*
* Please note that this method always queries the Catalogue database.
*
* @param admin The administrator.
* @return True if the specified user has administrator privileges.
*/
bool isNonCachedAdmin(const common::dataStructures::SecurityIdentity &admin) const;
/**
* Cached versions of tape copy to tape tape pool mappings for specific
* storage classes.
......@@ -1167,6 +1185,11 @@ protected:
*/
mutable TimeBasedCache<StorageClass, uint64_t> m_expectedNbArchiveRoutesCache;
/**
* Cached version of isAdmin() results.
*/
mutable TimeBasedCache<common::dataStructures::SecurityIdentity, bool> m_isAdminCache;
}; // class RdbmsCatalogue
} // namespace catalogue
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment