mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 07:11:15 +00:00
chore: use interfaces for all other services
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/h44z/wg-portal/internal/domain"
|
||||
)
|
||||
|
||||
// LdapAuthenticator is an authenticator that uses LDAP for authentication.
|
||||
type LdapAuthenticator struct {
|
||||
cfg *config.LdapProvider
|
||||
}
|
||||
@@ -33,14 +34,17 @@ func newLdapAuthenticator(_ context.Context, cfg *config.LdapProvider) (*LdapAut
|
||||
return provider, nil
|
||||
}
|
||||
|
||||
// GetName returns the name of the LDAP authenticator.
|
||||
func (l LdapAuthenticator) GetName() string {
|
||||
return l.cfg.ProviderName
|
||||
}
|
||||
|
||||
// RegistrationEnabled returns whether registration is enabled for the LDAP authenticator.
|
||||
func (l LdapAuthenticator) RegistrationEnabled() bool {
|
||||
return l.cfg.RegistrationEnabled
|
||||
}
|
||||
|
||||
// PlaintextAuthentication performs a plaintext authentication against the LDAP server.
|
||||
func (l LdapAuthenticator) PlaintextAuthentication(userId domain.UserIdentifier, plainPassword string) error {
|
||||
conn, err := internal.LdapConnect(l.cfg)
|
||||
if err != nil {
|
||||
@@ -81,6 +85,9 @@ func (l LdapAuthenticator) PlaintextAuthentication(userId domain.UserIdentifier,
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserInfo retrieves user information from the LDAP server.
|
||||
// If the user is not found, domain.ErrNotFound is returned.
|
||||
// If multiple users are found, domain.ErrNotUnique is returned.
|
||||
func (l LdapAuthenticator) GetUserInfo(_ context.Context, userId domain.UserIdentifier) (
|
||||
map[string]any,
|
||||
error,
|
||||
@@ -126,6 +133,7 @@ func (l LdapAuthenticator) GetUserInfo(_ context.Context, userId domain.UserIden
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
// ParseUserInfo parses the user information from the LDAP server into a domain.AuthenticatorUserInfo struct.
|
||||
func (l LdapAuthenticator) ParseUserInfo(raw map[string]any) (*domain.AuthenticatorUserInfo, error) {
|
||||
isAdmin, err := internal.LdapIsMemberOf(raw[l.cfg.FieldMap.GroupMembership].([][]byte), l.cfg.ParsedAdminGroupDN)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user