2019-04-24 21:52:08 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-04-03 23:11:33 +00:00
|
|
|
"fmt"
|
2020-05-18 02:45:47 +00:00
|
|
|
"strings"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
2019-12-24 02:14:52 +00:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
2020-04-03 23:11:33 +00:00
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateSession validates and update session configuration.
|
|
|
|
func ValidateSession(configuration *schema.SessionConfiguration, validator *schema.StructValidator) {
|
|
|
|
if configuration.Name == "" {
|
|
|
|
configuration.Name = schema.DefaultSessionConfiguration.Name
|
|
|
|
}
|
|
|
|
|
2020-05-18 02:45:47 +00:00
|
|
|
if configuration.Redis != nil {
|
|
|
|
if configuration.Secret == "" {
|
|
|
|
validator.Push(errors.New("Set secret of the session object"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(configuration.Redis.Host, "/") && configuration.Redis.Port == 0 {
|
|
|
|
validator.Push(errors.New("A redis port different than 0 must be provided"))
|
|
|
|
}
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
if configuration.Expiration == "" {
|
2019-04-24 21:52:08 +00:00
|
|
|
configuration.Expiration = schema.DefaultSessionConfiguration.Expiration // 1 hour
|
2020-04-05 12:37:21 +00:00
|
|
|
} else if _, err := utils.ParseDurationString(configuration.Expiration); err != nil {
|
2020-04-09 01:05:17 +00:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing session expiration string: %s", err))
|
2020-04-03 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
if configuration.Inactivity == "" {
|
|
|
|
configuration.Inactivity = schema.DefaultSessionConfiguration.Inactivity // 5 min
|
|
|
|
} else if _, err := utils.ParseDurationString(configuration.Inactivity); err != nil {
|
2020-04-09 01:05:17 +00:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing session inactivity string: %s", err))
|
2020-04-03 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.RememberMeDuration == "" {
|
2020-04-05 12:37:21 +00:00
|
|
|
configuration.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration // 1 month
|
|
|
|
} else if _, err := utils.ParseDurationString(configuration.RememberMeDuration); err != nil {
|
2020-04-09 01:05:17 +00:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing session remember_me_duration string: %s", err))
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.Domain == "" {
|
|
|
|
validator.Push(errors.New("Set domain of the session object"))
|
|
|
|
}
|
2020-06-07 15:47:02 +00:00
|
|
|
|
|
|
|
if strings.Contains(configuration.Domain, "*") {
|
|
|
|
validator.Push(errors.New("The domain of the session must be the root domain you're protecting instead of a wildcard domain"))
|
|
|
|
}
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|