-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthManager.go
46 lines (38 loc) · 1.15 KB
/
authManager.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
package session
import "fmt"
//AuthManager is responsible for cycling through the different authentication mechanizms
type AuthManager struct {
authModuleCount int64
authModules []AuthInterface
}
func (a *AuthManager) authenticate(cred Credentials) (LoginResponse, error) {
fmt.Println("Inside auth manager authenticate")
var result LoginResponse
var err error
for _, element := range a.authModules {
result, err = element.authenticate(cred)
if result.Authenticated{
return result, err
}
}
return LoginResponse{Authenticated: false, Message: "Invalid username or password"}, nil
}
//NewAuthmanager creates a new authentication manager
func NewAuthmanager() *AuthManager {
return &AuthManager{
authModuleCount: 1,
authModules: createModules(),
}
}
func createModules() []AuthInterface {
var inter []AuthInterface
ldapModule := NewLdapAuth()
inter = append(inter, ldapModule)
localAuthModule := NewLocalAuth();
inter = append(inter, localAuthModule)
return inter
}
//AuthInterface - all authentication modules should implement this interface
type AuthInterface interface {
authenticate(cred Credentials) (LoginResponse, error)
}