2019-04-25 04:52:08 +07:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-04-04 06:11:33 +07:00
|
|
|
"fmt"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
2019-12-24 09:14:52 +07:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
2020-04-04 06:11:33 +07:00
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-04-25 04:52:08 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateSession validates and update session configuration.
|
|
|
|
func ValidateSession(configuration *schema.SessionConfiguration, validator *schema.StructValidator) {
|
|
|
|
if configuration.Name == "" {
|
|
|
|
configuration.Name = schema.DefaultSessionConfiguration.Name
|
|
|
|
}
|
|
|
|
|
2020-03-28 13:10:39 +07:00
|
|
|
if configuration.Redis != nil && configuration.Secret == "" {
|
2019-04-25 04:52:08 +07:00
|
|
|
validator.Push(errors.New("Set secret of the session object"))
|
|
|
|
}
|
|
|
|
|
2020-04-05 19:37:21 +07:00
|
|
|
if configuration.Expiration == "" {
|
2019-04-25 04:52:08 +07:00
|
|
|
configuration.Expiration = schema.DefaultSessionConfiguration.Expiration // 1 hour
|
2020-04-05 19:37:21 +07:00
|
|
|
} else if _, err := utils.ParseDurationString(configuration.Expiration); err != nil {
|
2020-04-09 08:05:17 +07:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing session expiration string: %s", err))
|
2020-04-04 06:11:33 +07:00
|
|
|
}
|
|
|
|
|
2020-04-05 19:37:21 +07:00
|
|
|
if configuration.Inactivity == "" {
|
|
|
|
configuration.Inactivity = schema.DefaultSessionConfiguration.Inactivity // 5 min
|
|
|
|
} else if _, err := utils.ParseDurationString(configuration.Inactivity); err != nil {
|
2020-04-09 08:05:17 +07:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing session inactivity string: %s", err))
|
2020-04-04 06:11:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.RememberMeDuration == "" {
|
2020-04-05 19:37:21 +07:00
|
|
|
configuration.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration // 1 month
|
|
|
|
} else if _, err := utils.ParseDurationString(configuration.RememberMeDuration); err != nil {
|
2020-04-09 08:05:17 +07:00
|
|
|
validator.Push(fmt.Errorf("Error occurred parsing session remember_me_duration string: %s", err))
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.Domain == "" {
|
|
|
|
validator.Push(errors.New("Set domain of the session object"))
|
|
|
|
}
|
|
|
|
}
|