Coverage Report

Created: 2026-06-06 16:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/arrow_flight/auth_server_middleware.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 <arrow/status.h>
21
22
#include "arrow/flight/server.h"
23
#include "arrow/flight/server_middleware.h"
24
#include "arrow/flight/types.h"
25
26
namespace doris {
27
namespace flight {
28
29
// Just return default bearer token.
30
class NoOpHeaderAuthServerMiddleware : public arrow::flight::ServerMiddleware {
31
public:
32
    void SendingHeaders(arrow::flight::AddCallHeaders* outgoing_headers) override;
33
34
0
    void CallCompleted(const arrow::Status& status) override {}
35
36
0
    [[nodiscard]] std::string name() const override { return "NoOpHeaderAuthServerMiddleware"; }
37
};
38
39
// Factory for base64 header authentication.
40
// No actual authentication.
41
class NoOpHeaderAuthServerMiddlewareFactory : public arrow::flight::ServerMiddlewareFactory {
42
public:
43
0
    NoOpHeaderAuthServerMiddlewareFactory() = default;
44
45
    arrow::Status StartCall(const arrow::flight::CallInfo& info,
46
                            const arrow::flight::ServerCallContext& context,
47
                            std::shared_ptr<arrow::flight::ServerMiddleware>* middleware) override;
48
};
49
50
// A server middleware for validating incoming bearer header authentication.
51
// Just compare with default bearer token.
52
class NoOpBearerAuthServerMiddleware : public arrow::flight::ServerMiddleware {
53
public:
54
    explicit NoOpBearerAuthServerMiddleware(const arrow::flight::CallHeaders& incoming_headers,
55
                                            bool* isValid)
56
0
            : _is_valid(isValid) {
57
0
        _incoming_headers = incoming_headers;
58
0
    }
59
60
    void SendingHeaders(arrow::flight::AddCallHeaders* outgoing_headers) override;
61
62
0
    void CallCompleted(const arrow::Status& status) override {}
63
64
0
    [[nodiscard]] std::string name() const override { return "NoOpBearerAuthServerMiddleware"; }
65
66
private:
67
    arrow::flight::CallHeaders _incoming_headers;
68
    bool* _is_valid = nullptr;
69
};
70
71
// Factory for base64 header authentication.
72
// No actual authentication.
73
class NoOpBearerAuthServerMiddlewareFactory : public arrow::flight::ServerMiddlewareFactory {
74
public:
75
0
    NoOpBearerAuthServerMiddlewareFactory() : _is_valid(false) {}
76
77
    arrow::Status StartCall(const arrow::flight::CallInfo& info,
78
                            const arrow::flight::ServerCallContext& context,
79
                            std::shared_ptr<arrow::flight::ServerMiddleware>* middleware) override;
80
81
0
    [[nodiscard]] bool GetIsValid() const { return _is_valid; }
82
83
private:
84
    bool _is_valid;
85
};
86
87
} // namespace flight
88
} // namespace doris