2019-04-25 04:52:08 +07:00
|
|
|
package authentication
|
|
|
|
|
2022-05-02 08:51:38 +07:00
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
|
|
|
|
"github.com/go-ldap/ldap/v3"
|
|
|
|
"golang.org/x/text/encoding/unicode"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LDAPConnectionFactory an interface of factory of ldap connections.
|
|
|
|
type LDAPConnectionFactory interface {
|
|
|
|
DialURL(addr string, opts ...ldap.DialOpt) (LDAPConnection, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LDAPConnection interface representing a connection to the ldap.
|
|
|
|
type LDAPConnection interface {
|
|
|
|
Bind(username, password string) (err error)
|
|
|
|
Close()
|
|
|
|
StartTLS(config *tls.Config) (err error)
|
|
|
|
|
|
|
|
Search(searchRequest *ldap.SearchRequest) (searchResult *ldap.SearchResult, err error)
|
|
|
|
|
|
|
|
Modify(modifyRequest *ldap.ModifyRequest) (err error)
|
|
|
|
PasswordModify(pwdModifyRequest *ldap.PasswordModifyRequest) (result *ldap.PasswordModifyResult, err error)
|
|
|
|
}
|
|
|
|
|
2019-04-25 04:52:08 +07:00
|
|
|
// UserDetails represent the details retrieved for a given user.
|
|
|
|
type UserDetails struct {
|
2020-06-19 17:50:21 +07:00
|
|
|
Username string
|
|
|
|
DisplayName string
|
|
|
|
Emails []string
|
|
|
|
Groups []string
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
2022-05-02 08:51:38 +07:00
|
|
|
|
|
|
|
type ldapUserProfile struct {
|
|
|
|
DN string
|
|
|
|
Emails []string
|
|
|
|
DisplayName string
|
|
|
|
Username string
|
|
|
|
}
|
|
|
|
|
|
|
|
var utf16LittleEndian = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
|