...
1
2
3
4
5
6
7
8
9
10
11 package auth
12
13 import (
14 "context"
15 "fmt"
16 "net"
17
18 "go.mongodb.org/mongo-driver/x/mongo/driver/auth/internal/gssapi"
19 )
20
21
22 const GSSAPI = "GSSAPI"
23
24 func newGSSAPIAuthenticator(cred *Cred) (Authenticator, error) {
25 if cred.Source != "" && cred.Source != "$external" {
26 return nil, newAuthError("GSSAPI source must be empty or $external", nil)
27 }
28
29 return &GSSAPIAuthenticator{
30 Username: cred.Username,
31 Password: cred.Password,
32 PasswordSet: cred.PasswordSet,
33 Props: cred.Props,
34 }, nil
35 }
36
37
38 type GSSAPIAuthenticator struct {
39 Username string
40 Password string
41 PasswordSet bool
42 Props map[string]string
43 }
44
45
46 func (a *GSSAPIAuthenticator) Auth(ctx context.Context, cfg *Config) error {
47 target := cfg.Description.Addr.String()
48 hostname, _, err := net.SplitHostPort(target)
49 if err != nil {
50 return newAuthError(fmt.Sprintf("invalid endpoint (%s) specified: %s", target, err), nil)
51 }
52
53 client, err := gssapi.New(hostname, a.Username, a.Password, a.PasswordSet, a.Props)
54
55 if err != nil {
56 return newAuthError("error creating gssapi", err)
57 }
58 return ConductSaslConversation(ctx, cfg, "$external", client)
59 }
60
View as plain text