| 49 | } |
| 50 | |
| 51 | Status GetEffectiveShortUser(const TSessionState& session, std::string* short_name) { |
| 52 | const string& effective_user = GetEffectiveUser(session); |
| 53 | if (IsKerberosEnabled() && (effective_user.find('@') != std::string::npos)) { |
| 54 | // Regex to match kerberos names, based on org.apache.hadoop.security.KerberosName. |
| 55 | static const std::regex kerberos_name("([^/@]*)(/([^/@]*))*@([^/@]*)"); |
| 56 | std::smatch groups; |
| 57 | if (std::regex_match(effective_user, groups, kerberos_name)) { |
| 58 | DCHECK_GE(groups.size(), 2); |
| 59 | // The first group contains the name. |
| 60 | if (!groups[1].str().empty()) { |
| 61 | *short_name = groups[1].str(); |
| 62 | return Status::OK(); |
| 63 | } |
| 64 | } |
| 65 | stringstream ss; |
| 66 | ss << "Could not parse Kerberos name " << effective_user; |
| 67 | return Status::Expected(ss.str()); |
| 68 | } else { |
| 69 | *short_name = effective_user; |
| 70 | } |
| 71 | return Status::OK(); |
| 72 | } |
| 73 | |
| 74 | const string& GetEffectiveUser(const ImpalaServer::SessionState& session) { |
| 75 | return session.do_as_user.empty() ? session.connected_user : session.do_as_user; |