2021-11-23 09:45:38 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-11-25 01:56:58 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/authentication"
|
|
|
|
"github.com/authelia/authelia/v4/internal/authorization"
|
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
|
|
|
"github.com/authelia/authelia/v4/internal/notification"
|
|
|
|
"github.com/authelia/authelia/v4/internal/ntp"
|
|
|
|
"github.com/authelia/authelia/v4/internal/oidc"
|
|
|
|
"github.com/authelia/authelia/v4/internal/regulation"
|
|
|
|
"github.com/authelia/authelia/v4/internal/session"
|
2021-11-23 09:45:38 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/storage"
|
2021-11-25 01:56:58 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2021-11-23 09:45:38 +00:00
|
|
|
)
|
|
|
|
|
2021-11-25 01:56:58 +00:00
|
|
|
func getStorageProvider() (provider storage.Provider) {
|
2021-11-23 09:45:38 +00:00
|
|
|
switch {
|
|
|
|
case config.Storage.PostgreSQL != nil:
|
2021-11-25 01:56:58 +00:00
|
|
|
return storage.NewPostgreSQLProvider(*config.Storage.PostgreSQL, config.Storage.EncryptionKey)
|
2021-11-23 09:45:38 +00:00
|
|
|
case config.Storage.MySQL != nil:
|
2021-11-25 01:56:58 +00:00
|
|
|
return storage.NewMySQLProvider(*config.Storage.MySQL, config.Storage.EncryptionKey)
|
2021-11-23 09:45:38 +00:00
|
|
|
case config.Storage.Local != nil:
|
2021-11-25 01:56:58 +00:00
|
|
|
return storage.NewSQLiteProvider(config.Storage.Local.Path, config.Storage.EncryptionKey)
|
2021-11-23 09:45:38 +00:00
|
|
|
default:
|
2021-11-25 01:56:58 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getProviders() (providers middlewares.Providers, warnings []error, errors []error) {
|
|
|
|
// TODO: Adjust this so the CertPool can be used like a provider.
|
|
|
|
autheliaCertPool, warnings, errors := utils.NewX509CertPool(config.CertificatesDirectory)
|
|
|
|
if len(warnings) != 0 || len(errors) != 0 {
|
|
|
|
return providers, warnings, errors
|
|
|
|
}
|
|
|
|
|
|
|
|
storageProvider := getStorageProvider()
|
|
|
|
|
|
|
|
var (
|
|
|
|
userProvider authentication.UserProvider
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case config.AuthenticationBackend.File != nil:
|
|
|
|
userProvider = authentication.NewFileUserProvider(config.AuthenticationBackend.File)
|
|
|
|
case config.AuthenticationBackend.LDAP != nil:
|
|
|
|
userProvider = authentication.NewLDAPUserProvider(config.AuthenticationBackend, autheliaCertPool)
|
|
|
|
}
|
|
|
|
|
|
|
|
var notifier notification.Notifier
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case config.Notifier.SMTP != nil:
|
|
|
|
notifier = notification.NewSMTPNotifier(config.Notifier.SMTP, autheliaCertPool)
|
|
|
|
case config.Notifier.FileSystem != nil:
|
|
|
|
notifier = notification.NewFileNotifier(*config.Notifier.FileSystem)
|
|
|
|
}
|
|
|
|
|
|
|
|
var ntpProvider *ntp.Provider
|
|
|
|
if config.NTP != nil {
|
|
|
|
ntpProvider = ntp.NewProvider(config.NTP)
|
2021-11-23 09:45:38 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 01:56:58 +00:00
|
|
|
clock := utils.RealClock{}
|
|
|
|
authorizer := authorization.NewAuthorizer(config)
|
|
|
|
sessionProvider := session.NewProvider(config.Session, autheliaCertPool)
|
|
|
|
regulator := regulation.NewRegulator(config.Regulation, storageProvider, clock)
|
|
|
|
|
|
|
|
oidcProvider, err := oidc.NewOpenIDConnectProvider(config.IdentityProviders.OIDC)
|
|
|
|
if err != nil {
|
|
|
|
errors = append(errors, err)
|
2021-11-23 09:45:38 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 01:56:58 +00:00
|
|
|
return middlewares.Providers{
|
|
|
|
Authorizer: authorizer,
|
|
|
|
UserProvider: userProvider,
|
|
|
|
Regulator: regulator,
|
|
|
|
OpenIDConnect: oidcProvider,
|
|
|
|
StorageProvider: storageProvider,
|
|
|
|
NTP: ntpProvider,
|
|
|
|
Notifier: notifier,
|
|
|
|
SessionProvider: sessionProvider,
|
|
|
|
}, warnings, errors
|
2021-11-23 09:45:38 +00:00
|
|
|
}
|