-
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathauth.go
More file actions
45 lines (39 loc) · 1.48 KB
/
auth.go
File metadata and controls
45 lines (39 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2018-2025 The Olric Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package olric
import (
"errors"
"github.com/olric-data/olric/internal/protocol"
"github.com/olric-data/olric/internal/server"
"github.com/tidwall/redcon"
)
// authCommandHandler handles authentication requests sent by clients and verifies the provided password for access.
func (db *Olric) authCommandHandler(conn redcon.Conn, cmd redcon.Command) {
authCmd, err := protocol.ParseAuthCommand(cmd)
if err != nil {
protocol.WriteError(conn, err)
return
}
if !db.config.Authentication.Enabled() {
protocol.WriteError(conn, errors.New("AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?"))
return
}
if authCmd.Password == db.config.Authentication.Password {
ctx := conn.Context().(*server.ConnContext)
ctx.SetAuthenticated(true)
conn.WriteString(protocol.StatusOK)
return
}
protocol.WriteError(conn, ErrWrongPass)
}