Check whether or not the client is permitted specified access to a path.
506 const char *authz = env ? env->Get(
"authz") :
nullptr;
511 if (authz && !strncmp(authz,
"Bearer%20", 9)) {
516 if (!authz && Entity && !strcmp(
"ztn", Entity->
prot) && Entity->
creds &&
519 authz = Entity->
creds;
521 if (authz ==
nullptr) {
522 return OnMissing(Entity, path, oper, env);
525 std::shared_ptr<XrdAccRules> access_rules;
526 uint64_t now = monotonic_time();
529 std::lock_guard<std::mutex> guard(m_mutex);
530 const auto iter = m_map.find(authz);
531 if (iter != m_map.end() && !iter->second->expired()) {
532 access_rules = iter->second;
536 m_log.
Log(
LogMask::Debug,
"Access",
"Token not found in recent cache; parsing.");
538 uint64_t cache_expiry;
539 AccessRulesRaw rules;
540 std::string username;
541 std::string token_subject;
543 std::vector<MapRule> map_rules;
544 std::vector<std::string> groups;
545 uint32_t authz_strategy;
546 if (GenerateAcls(authz, cache_expiry, rules, username, token_subject, issuer, map_rules, groups, authz_strategy)) {
547 access_rules.reset(
new XrdAccRules(now + cache_expiry, username, token_subject, issuer, map_rules, groups, authz_strategy));
548 access_rules->parse(rules);
551 return OnMissing(Entity, path, oper, env);
554 m_log.
Log(
LogMask::Debug,
"Access",
"New valid token", access_rules->str().c_str());
556 }
catch (std::exception &exc) {
557 m_log.
Log(
LogMask::Warning,
"Access",
"Error generating ACLs for authorization", exc.what());
558 return OnMissing(Entity, path, oper, env);
560 std::lock_guard<std::mutex> guard(m_mutex);
561 m_map[authz] = access_rules;
563 m_log.
Log(
LogMask::Debug,
"Access",
"Cached token", access_rules->str().c_str());
578 new_secentity.
vorg =
nullptr;
579 new_secentity.
grps =
nullptr;
580 new_secentity.
role =
nullptr;
583 const auto &issuer = access_rules->get_issuer();
584 if (!issuer.empty()) {
585 new_secentity.
vorg = strdup(issuer.c_str());
587 bool group_success =
false;
588 if ((access_rules->get_authz_strategy() & IssuerAuthz::Group) && access_rules->groups().size()) {
589 std::stringstream ss;
590 for (
const auto &grp : access_rules->groups()) {
593 const auto &groups_str = ss.str();
594 new_secentity.
grps =
static_cast<char*
>(malloc(groups_str.size() + 1));
595 if (new_secentity.
grps) {
596 memcpy(new_secentity.
grps, groups_str.c_str(), groups_str.size());
597 new_secentity.
grps[groups_str.size()] =
'\0';
598 group_success =
true;
602 std::string username;
603 bool mapping_success =
false;
604 bool scope_success =
false;
605 username = access_rules->get_username(path);
607 mapping_success = (access_rules->get_authz_strategy() & IssuerAuthz::Mapping) && !username.empty();
608 scope_success = (access_rules->get_authz_strategy() & IssuerAuthz::Capability) && access_rules->apply(oper, path);
610 std::stringstream ss;
611 ss <<
"Grant authorization based on scopes for operation=" << OpToName(oper) <<
", path=" << path;
615 if (!scope_success && !mapping_success && !group_success) {
616 auto returned_accs = OnMissing(&new_secentity, path, oper, env);
618 if (new_secentity.
vorg !=
nullptr) free(new_secentity.
vorg);
619 if (new_secentity.
grps !=
nullptr) free(new_secentity.
grps);
620 if (new_secentity.
role !=
nullptr) free(new_secentity.
role);
622 return returned_accs;
626 if (scope_success && username.empty()) {
627 username = access_rules->get_default_username();
632 if (scope_success || mapping_success) {
634 Entity->
eaAPI->
Add(
"request.name", username,
true);
635 new_secentity.
eaAPI->
Add(
"request.name", username,
true);
644 const auto &token_subject = access_rules->get_token_subject();
645 if (!token_subject.empty()) {
646 Entity->
eaAPI->
Add(
"token.subject", token_subject,
true);
655 if (Entity->
secMon && scope_success && returned_op &&
Mon_isIO(oper))
656 Mon_Report(new_secentity, token_subject, username);
659 if (new_secentity.
vorg !=
nullptr) free(new_secentity.
vorg);
660 if (new_secentity.
grps !=
nullptr) free(new_secentity.
grps);
661 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)