2021-01-06 09:47:55 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-01-12 11:59:51 +00:00
|
|
|
"github.com/caos/logging"
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-01-12 11:59:51 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-01-06 09:47:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Step8 struct {
|
|
|
|
U2F bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Step8) Step() domain.Step {
|
|
|
|
return domain.Step8
|
|
|
|
}
|
|
|
|
|
2021-02-24 10:17:39 +00:00
|
|
|
func (s *Step8) execute(ctx context.Context, commandSide *Commands) error {
|
2021-01-06 09:47:55 +00:00
|
|
|
return commandSide.SetupStep8(ctx, s)
|
|
|
|
}
|
|
|
|
|
2021-02-24 10:17:39 +00:00
|
|
|
func (c *Commands) SetupStep8(ctx context.Context, step *Step8) error {
|
2021-02-18 13:48:27 +00:00
|
|
|
fn := func(iam *IAMWriteModel) ([]eventstore.EventPusher, error) {
|
2021-03-19 10:12:56 +00:00
|
|
|
secondFactorModel := NewIAMSecondFactorWriteModel(domain.SecondFactorTypeU2F)
|
2021-01-06 09:47:55 +00:00
|
|
|
iamAgg := IAMAggregateFromWriteModel(&secondFactorModel.SecondFactorWriteModel.WriteModel)
|
|
|
|
if !step.U2F {
|
2021-02-18 13:48:27 +00:00
|
|
|
return []eventstore.EventPusher{}, nil
|
2021-01-06 09:47:55 +00:00
|
|
|
}
|
2021-02-24 10:17:39 +00:00
|
|
|
event, err := c.addSecondFactorToDefaultLoginPolicy(ctx, iamAgg, secondFactorModel, domain.SecondFactorTypeU2F)
|
2021-01-06 09:47:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-12 11:59:51 +00:00
|
|
|
logging.Log("SETUP-BDhne").Info("added U2F to 2FA login policy")
|
2021-02-18 13:48:27 +00:00
|
|
|
return []eventstore.EventPusher{event}, nil
|
2021-01-06 09:47:55 +00:00
|
|
|
}
|
2021-02-24 10:17:39 +00:00
|
|
|
return c.setup(ctx, step, fn)
|
2021-01-06 09:47:55 +00:00
|
|
|
}
|