Check whether or not the client is permitted specified access to a path.
513 const char *authz = env ? env->Get(
"authz") :
nullptr;
518 if (authz && !strncmp(authz,
"Bearer%20", 9)) {
523 if (!authz && Entity && !strcmp(
"ztn", Entity->
prot) && Entity->
creds &&
526 authz = Entity->
creds;
528 if (authz ==
nullptr) {
529 return OnMissing(Entity, path, oper, env);
532 std::shared_ptr<XrdAccRules> access_rules;
533 uint64_t now = monotonic_time();
536 std::lock_guard<std::mutex> guard(m_map_mutex);
537 const auto iter = m_map.find(authz);
538 if (iter != m_map.end() && !iter->second->expired()) {
539 access_rules = iter->second;
543 m_log.
Log(
LogMask::Debug,
"Access",
"Token not found in recent cache; parsing.");
545 uint64_t cache_expiry;
546 AccessRulesRaw rules;
547 std::string username;
548 std::string token_subject;
550 std::vector<MapRule> map_rules;
551 std::vector<std::string> groups;
552 uint32_t authz_strategy;
553 if (GenerateAcls(authz, cache_expiry, rules, username, token_subject, issuer, map_rules, groups, authz_strategy)) {
554 access_rules.reset(
new XrdAccRules(now + cache_expiry, username, token_subject, issuer, map_rules, groups, authz_strategy));
555 access_rules->parse(rules);
558 return OnMissing(Entity, path, oper, env);
561 m_log.
Log(
LogMask::Debug,
"Access",
"New valid token", access_rules->str().c_str());
563 }
catch (std::exception &exc) {
564 m_log.
Log(
LogMask::Warning,
"Access",
"Error generating ACLs for authorization", exc.what());
565 return OnMissing(Entity, path, oper, env);
567 std::lock_guard<std::mutex> guard(m_map_mutex);
568 m_map[authz] = access_rules;
570 m_log.
Log(
LogMask::Debug,
"Access",
"Cached token", access_rules->str().c_str());
585 new_secentity.
vorg =
nullptr;
586 new_secentity.
grps =
nullptr;
587 new_secentity.
role =
nullptr;
590 const auto &issuer = access_rules->get_issuer();
591 if (!issuer.empty()) {
592 new_secentity.
vorg = strdup(issuer.c_str());
594 bool group_success =
false;
595 if ((access_rules->get_authz_strategy() & IssuerAuthz::Group) && access_rules->groups().size()) {
596 std::stringstream ss;
597 for (
const auto &grp : access_rules->groups()) {
600 const auto &groups_str = ss.str();
601 new_secentity.
grps =
static_cast<char*
>(malloc(groups_str.size() + 1));
602 if (new_secentity.
grps) {
603 memcpy(new_secentity.
grps, groups_str.c_str(), groups_str.size());
604 new_secentity.
grps[groups_str.size()] =
'\0';
605 group_success =
true;
609 std::string username;
610 bool mapping_success =
false;
611 bool scope_success =
false;
612 username = access_rules->get_username(path);
614 mapping_success = (access_rules->get_authz_strategy() & IssuerAuthz::Mapping) && !username.empty();
615 scope_success = (access_rules->get_authz_strategy() & IssuerAuthz::Capability) && access_rules->apply(oper, path);
617 std::stringstream ss;
618 ss <<
"Grant authorization based on scopes for operation=" << OpToName(oper) <<
", path=" << path;
622 if (!scope_success && !mapping_success && !group_success) {
623 auto returned_accs = OnMissing(&new_secentity, path, oper, env);
625 if (new_secentity.
vorg !=
nullptr) free(new_secentity.
vorg);
626 if (new_secentity.
grps !=
nullptr) free(new_secentity.
grps);
627 if (new_secentity.
role !=
nullptr) free(new_secentity.
role);
629 return returned_accs;
633 if (scope_success && username.empty()) {
634 username = access_rules->get_default_username();
639 if (scope_success || mapping_success) {
641 Entity->
eaAPI->
Add(
"request.name", username,
true);
642 new_secentity.
eaAPI->
Add(
"request.name", username,
true);
651 const auto &token_subject = access_rules->get_token_subject();
652 if (!token_subject.empty()) {
653 Entity->
eaAPI->
Add(
"token.subject", token_subject,
true);
662 if (Entity->
secMon && scope_success && returned_op &&
Mon_isIO(oper))
663 Mon_Report(new_secentity, token_subject, username);
666 if (new_secentity.
vorg !=
nullptr) free(new_secentity.
vorg);
667 if (new_secentity.
grps !=
nullptr) free(new_secentity.
grps);
668 if (new_secentity.
role !=
nullptr) free(new_secentity.
role);
bool Mon_isIO(const Access_Operation oper)
void Mon_Report(const XrdSecEntity &Entity, const std::string &subject, const std::string &username)
bool Add(XrdSecAttr &attr)
char * vorg
Entity's virtual organization(s)
int credslen
Length of the 'creds' data.
XrdNetAddrInfo * addrInfo
Entity's connection details.
XrdSecEntityAttr * eaAPI
non-const API to attributes
char prot[XrdSecPROTOIDSIZE]
Auth protocol used (e.g. krb5)
char * creds
Raw entity credentials or cert.
XrdSecMonitor * secMon
If !0 security monitoring enabled.
char * grps
Entity's group name(s)
char * role
Entity's role(s)
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)