-
Notifications
You must be signed in to change notification settings - Fork 18
/
backend.go
76 lines (62 loc) · 1.44 KB
/
backend.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package kerberos
import (
"context"
"encoding/json"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
const (
configPath string = "config"
// operationPrefixKerberos is used as a prefix for OpenAPI operation id's.
operationPrefixKerberos = "kerberos"
)
type backend struct {
*framework.Backend
}
func Factory(ctx context.Context, c *logical.BackendConfig) (logical.Backend, error) {
b := Backend()
if err := b.Setup(ctx, c); err != nil {
return nil, err
}
return b, nil
}
func Backend() *backend {
b := &backend{}
b.Backend = &framework.Backend{
BackendType: logical.TypeCredential,
Help: backendHelp,
PathsSpecial: &logical.Paths{
Unauthenticated: []string{"login"},
SealWrapStorage: []string{configPath},
},
Paths: framework.PathAppend(
[]*framework.Path{
b.pathConfig(),
b.pathConfigLdap(),
b.pathLogin(),
b.pathGroups(),
b.pathGroupsList(),
},
),
}
return b
}
func (b *backend) config(ctx context.Context, s logical.Storage) (*kerberosConfig, error) {
raw, err := s.Get(ctx, configPath)
if err != nil {
return nil, err
}
if raw == nil {
return nil, nil
}
conf := &kerberosConfig{}
if err := json.Unmarshal(raw.Value, conf); err != nil {
return nil, err
}
return conf, nil
}
var backendHelp string = `
The Kerberos Auth Backend allows authentication via Kerberos SPNEGO.
`