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"
|
|
|
|
)
|
|
|
|
|
2022-05-10 11:38:36 +07:00
|
|
|
// LDAPClientFactory an interface of factory of LDAP clients.
|
|
|
|
type LDAPClientFactory interface {
|
|
|
|
DialURL(addr string, opts ...ldap.DialOpt) (client LDAPClient, err error)
|
2022-05-02 08:51:38 +07:00
|
|
|
}
|
|
|
|
|
2022-05-10 11:38:36 +07:00
|
|
|
// LDAPClient is a cut down version of the ldap.Client interface with just the methods we use.
|
|
|
|
//
|
|
|
|
// Methods added to this interface that have a direct correlation with one from ldap.Client should have the same signature.
|
|
|
|
type LDAPClient interface {
|
2022-05-02 08:51:38 +07:00
|
|
|
Close()
|
|
|
|
StartTLS(config *tls.Config) (err error)
|
|
|
|
|
2022-05-10 11:38:36 +07:00
|
|
|
Bind(username, password string) (err error)
|
2022-05-02 08:51:38 +07:00
|
|
|
|
|
|
|
Modify(modifyRequest *ldap.ModifyRequest) (err error)
|
2022-05-10 11:38:36 +07:00
|
|
|
PasswordModify(pwdModifyRequest *ldap.PasswordModifyRequest) (pwdModifyResult *ldap.PasswordModifyResult, err error)
|
|
|
|
|
|
|
|
Search(searchRequest *ldap.SearchRequest) (searchResult *ldap.SearchResult, err error)
|
2022-05-02 08:51:38 +07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-10 11:38:36 +07:00
|
|
|
// LDAPSupportedFeatures represents features which a server may support which are implemented in code.
|
|
|
|
type LDAPSupportedFeatures struct {
|
|
|
|
Extensions LDAPSupportedExtensions
|
|
|
|
ControlTypes LDAPSupportedControlTypes
|
|
|
|
}
|
|
|
|
|
|
|
|
// LDAPSupportedExtensions represents extensions which a server may support which are implemented in code.
|
|
|
|
type LDAPSupportedExtensions struct {
|
|
|
|
TLS bool
|
|
|
|
PwdModifyExOp bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// LDAPSupportedControlTypes represents control types which a server may support which are implemented in code.
|
|
|
|
type LDAPSupportedControlTypes struct {
|
|
|
|
MsftPwdPolHints bool
|
|
|
|
MsftPwdPolHintsDeprecated bool
|
|
|
|
}
|
|
|
|
|
2022-05-02 08:51:38 +07:00
|
|
|
var utf16LittleEndian = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
|