be/src/service/http/http_handler_with_auth.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/FrontendService.h> |
21 | | |
22 | | #include "runtime/exec_env.h" |
23 | | #include "service/http/http_handler.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | class ExecEnv; |
28 | | class HttpRequest; |
29 | | class RestMonitorIface; |
30 | | class TCheckAuthRequest; |
31 | | class TPrivilegeCtrl; |
32 | | class TPrivilegeHier; |
33 | | class TPrivilegeType; |
34 | | |
35 | | // Handler for on http request with auth |
36 | | class HttpHandlerWithAuth : public HttpHandler { |
37 | | public: |
38 | | HttpHandlerWithAuth(ExecEnv* exec_env, TPrivilegeHier::type hier, TPrivilegeType::type type); |
39 | | |
40 | 35 | HttpHandlerWithAuth(ExecEnv* exec_env) : _exec_env(exec_env) {} |
41 | 45 | ~HttpHandlerWithAuth() override = default; |
42 | | |
43 | | // return 0 if auth pass, otherwise -1. |
44 | | int on_header(HttpRequest* req) override; |
45 | | |
46 | | // return true if fill privilege success, otherwise false. |
47 | 13 | virtual bool on_privilege(const HttpRequest& req, TCheckAuthRequest& auth_request) { |
48 | 13 | TPrivilegeCtrl priv_ctrl; |
49 | 13 | priv_ctrl.priv_hier = _hier; |
50 | 13 | auth_request.__set_priv_ctrl(priv_ctrl); |
51 | 13 | auth_request.__set_priv_type(_type); |
52 | 13 | return true; |
53 | 13 | } |
54 | | |
55 | | protected: |
56 | | ExecEnv* _exec_env; |
57 | | TPrivilegeHier::type _hier = TPrivilegeHier::GLOBAL; |
58 | | TPrivilegeType::type _type = TPrivilegeType::ADMIN; |
59 | | }; |
60 | | |
61 | | } // namespace doris |