2019-04-25 04:52:08 +07:00
package validator
import (
"fmt"
2021-01-04 17:28:55 +07:00
"os"
2022-02-28 10:15:01 +07:00
"strings"
2019-04-25 04:52:08 +07:00
2021-08-11 08:04:35 +07:00
"github.com/authelia/authelia/v4/internal/configuration/schema"
"github.com/authelia/authelia/v4/internal/utils"
2019-04-25 04:52:08 +07:00
)
2020-04-23 08:11:32 +07:00
// ValidateConfiguration and adapt the configuration read from file.
2022-02-28 10:15:01 +07:00
func ValidateConfiguration ( config * schema . Configuration , validator * schema . StructValidator ) {
var err error
if config . CertificatesDirectory != "" {
var info os . FileInfo
if info , err = os . Stat ( config . CertificatesDirectory ) ; err != nil {
validator . Push ( fmt . Errorf ( "the location 'certificates_directory' could not be inspected: %w" , err ) )
2021-01-04 17:28:55 +07:00
} else if ! info . IsDir ( ) {
2022-02-28 10:15:01 +07:00
validator . Push ( fmt . Errorf ( "the location 'certificates_directory' refers to '%s' is not a directory" , config . CertificatesDirectory ) )
2021-01-04 17:28:55 +07:00
}
}
2022-02-28 10:15:01 +07:00
if config . JWTSecret == "" {
validator . Push ( fmt . Errorf ( "option 'jwt_secret' is required" ) )
2020-04-05 19:37:21 +07:00
}
2022-02-28 10:15:01 +07:00
if config . DefaultRedirectionURL != "" {
if err = utils . IsStringAbsURL ( config . DefaultRedirectionURL ) ; err != nil {
validator . Push ( fmt . Errorf ( "option 'default_redirection_url' is invalid: %s" , strings . ReplaceAll ( err . Error ( ) , "like 'http://' or 'https://'" , "like 'ldap://' or 'ldaps://'" ) ) )
2020-02-01 19:54:50 +07:00
}
}
2022-02-28 10:15:01 +07:00
ValidateTheme ( config , validator )
2021-01-20 19:07:40 +07:00
2022-02-28 10:15:01 +07:00
ValidateLog ( config , validator )
2021-06-01 11:09:50 +07:00
2022-04-16 06:34:26 +07:00
ValidateDuo ( config , validator )
2022-02-28 10:15:01 +07:00
ValidateTOTP ( config , validator )
2019-04-25 04:52:08 +07:00
2022-03-03 18:20:43 +07:00
ValidateWebauthn ( config , validator )
2022-02-28 10:15:01 +07:00
ValidateAuthenticationBackend ( & config . AuthenticationBackend , validator )
2020-04-05 19:37:21 +07:00
2022-02-28 10:15:01 +07:00
ValidateAccessControl ( config , validator )
2021-01-04 17:55:23 +07:00
2022-02-28 10:15:01 +07:00
ValidateRules ( config , validator )
2021-01-04 17:55:23 +07:00
2022-02-28 10:15:01 +07:00
ValidateSession ( & config . Session , validator )
2019-04-25 04:52:08 +07:00
2022-02-28 10:15:01 +07:00
ValidateRegulation ( config , validator )
2020-05-06 02:35:32 +07:00
2022-02-28 10:15:01 +07:00
ValidateServer ( config , validator )
2020-04-05 19:37:21 +07:00
2022-02-28 10:15:01 +07:00
ValidateStorage ( config . Storage , validator )
2020-04-30 09:03:05 +07:00
2022-04-16 06:34:26 +07:00
ValidateNotifier ( & config . Notifier , validator )
2019-11-17 02:50:58 +07:00
2022-02-28 10:15:01 +07:00
ValidateIdentityProviders ( & config . IdentityProviders , validator )
2021-09-17 11:44:35 +07:00
2022-02-28 10:15:01 +07:00
ValidateNTP ( config , validator )
2022-04-03 05:32:57 +07:00
ValidatePasswordPolicy ( & config . PasswordPolicy , validator )
2019-04-25 04:52:08 +07:00
}