2021-01-04 14:52:13 +01:00
|
|
|
package command
|
2020-12-11 15:49:19 +01:00
|
|
|
|
|
|
|
import (
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2020-12-11 15:49:19 +01:00
|
|
|
)
|
|
|
|
|
2021-08-11 08:36:32 +02:00
|
|
|
type LockoutPolicyWriteModel struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
2021-08-11 08:36:32 +02:00
|
|
|
MaxPasswordAttempts uint64
|
2024-04-10 11:14:55 +02:00
|
|
|
MaxOTPAttempts uint64
|
2020-12-11 15:49:19 +01:00
|
|
|
ShowLockOutFailures bool
|
2021-01-07 16:06:45 +01:00
|
|
|
State domain.PolicyState
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-08-11 08:36:32 +02:00
|
|
|
func (wm *LockoutPolicyWriteModel) Reduce() error {
|
2020-12-11 15:49:19 +01:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-08-11 08:36:32 +02:00
|
|
|
case *policy.LockoutPolicyAddedEvent:
|
|
|
|
wm.MaxPasswordAttempts = e.MaxPasswordAttempts
|
2024-04-10 11:14:55 +02:00
|
|
|
wm.MaxOTPAttempts = e.MaxOTPAttempts
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.ShowLockOutFailures = e.ShowLockOutFailures
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateActive
|
2021-08-11 08:36:32 +02:00
|
|
|
case *policy.LockoutPolicyChangedEvent:
|
|
|
|
if e.MaxPasswordAttempts != nil {
|
|
|
|
wm.MaxPasswordAttempts = *e.MaxPasswordAttempts
|
2021-01-06 11:12:56 +01:00
|
|
|
}
|
2024-04-10 11:14:55 +02:00
|
|
|
if e.MaxOTPAttempts != nil {
|
|
|
|
wm.MaxOTPAttempts = *e.MaxOTPAttempts
|
|
|
|
}
|
2021-01-06 11:12:56 +01:00
|
|
|
if e.ShowLockOutFailures != nil {
|
|
|
|
wm.ShowLockOutFailures = *e.ShowLockOutFailures
|
|
|
|
}
|
2021-08-11 08:36:32 +02:00
|
|
|
case *policy.LockoutPolicyRemovedEvent:
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateRemoved
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|