2019-04-24 21:52:08 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-04-03 23:11:33 +00:00
|
|
|
"fmt"
|
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-03-28 06:10:39 +00:00
|
|
|
if configuration.Redis != nil && configuration.Secret == "" {
|
2019-04-24 21:52:08 +00:00
|
|
|
validator.Push(errors.New("Set secret of the session object"))
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:11:33 +00:00
|
|
|
// TODO(james-d-elliott): Convert to duration notation
|
2019-04-24 21:52:08 +00:00
|
|
|
if configuration.Expiration == 0 {
|
|
|
|
configuration.Expiration = schema.DefaultSessionConfiguration.Expiration // 1 hour
|
2020-04-03 23:11:33 +00:00
|
|
|
} else if configuration.Expiration < 1 {
|
|
|
|
validator.Push(errors.New("Set expiration of the session above 0"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(james-d-elliott): Convert to duration notation
|
|
|
|
if configuration.Inactivity < 0 {
|
|
|
|
validator.Push(errors.New("Set inactivity of the session to 0 or above"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.RememberMeDuration == "" {
|
|
|
|
configuration.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration
|
|
|
|
} else {
|
|
|
|
if _, err := utils.ParseDurationString(configuration.RememberMeDuration); err != nil {
|
|
|
|
validator.Push(errors.New(fmt.Sprintf("Error occurred parsing 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"))
|
|
|
|
}
|
|
|
|
}
|