| 3853 | } |
| 3854 | |
| 3855 | Status ImpalaServer::ScopedSessionState::WithSession(const TUniqueId& session_id, |
| 3856 | const SecretArg& secret, std::shared_ptr<SessionState>* session) { |
| 3857 | DCHECK(session_.get() == NULL); |
| 3858 | RETURN_IF_ERROR(impala_->GetSessionState( |
| 3859 | session_id, secret, &session_, /* mark_active= */ true)); |
| 3860 | if (session != NULL) (*session) = session_; |
| 3861 | |
| 3862 | // We won't have a connection context in the case of ChildQuery, which calls into |
| 3863 | // hiveserver2 functions directly without going through the Thrift stack. |
| 3864 | if (ThriftServer::HasThreadConnectionContext()) { |
| 3865 | // Check that the session user matches the user authenticated on the connection. |
| 3866 | const ThriftServer::Username& connection_username = |
| 3867 | ThriftServer::GetThreadConnectionContext()->username; |
| 3868 | const string& kerberos_user_principal = |
| 3869 | ThriftServer::GetThreadConnectionContext()->kerberos_user_principal; |
| 3870 | // Compare only the short user name if the connected user is a proxy and using |
| 3871 | // kerberos AuthN. |
| 3872 | if (!session_->do_as_user.empty() && !kerberos_user_principal.empty()) { |
| 3873 | // This is the connected/authenticated user |
| 3874 | const string connection_user_short = |
| 3875 | ThriftServer::GetThreadConnectionContext()->kerberos_user_short; |
| 3876 | // This is the user which created the original session |
| 3877 | const string session_user_short = session_->connected_user_short; |
| 3878 | if (connection_user_short != session_user_short) { |
| 3879 | return Status::Expected(TErrorCode::UNAUTHORIZED_SESSION_USER, |
| 3880 | connection_user_short, session_user_short); |
| 3881 | } |
| 3882 | } else if (!connection_username.empty() |
| 3883 | && session_->connected_user != connection_username) { |
| 3884 | return Status::Expected(TErrorCode::UNAUTHORIZED_SESSION_USER, |
| 3885 | connection_username, session_->connected_user); |
| 3886 | } |
| 3887 | |
| 3888 | // Try adding the session id to the connection's set of sessions in case this is |
| 3889 | // the first time this session has been used on this connection. |
| 3890 | impala_->AddSessionToConnection(session_id, session_.get()); |
| 3891 | } |
| 3892 | return Status::OK(); |
| 3893 | } |
| 3894 | |
| 3895 | } // namespace impala |
no test coverage detected