forked from VolantMQ/volantmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
47 lines (38 loc) · 871 Bytes
/
auth.go
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
46
47
package main
import (
"crypto/sha256"
"encoding/hex"
"github.com/VolantMQ/vlapi/plugin/auth"
)
type simpleAuth struct {
creds map[string]string
}
var _ vlauth.IFace = (*simpleAuth)(nil)
func newSimpleAuth() *simpleAuth {
return &simpleAuth{
creds: make(map[string]string),
}
}
func (a *simpleAuth) addUser(u, p string) {
a.creds[u] = p
}
// nolint: golint
func (a *simpleAuth) Password(clientID, user, password string) error {
if hash, ok := a.creds[user]; ok {
algo := sha256.New()
algo.Write([]byte(password))
if hex.EncodeToString(algo.Sum(nil)) == hash {
return vlauth.StatusAllow
}
}
return vlauth.StatusDeny
}
// nolint: golint
func (a *simpleAuth) ACL(clientID, user, topic string, access vlauth.AccessType) error {
return vlauth.StatusAllow
}
// nolint: golint
func (a *simpleAuth) Shutdown() error {
a.creds = nil
return nil
}