mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-22 04:48:46 +00:00
This PR adds an option to the LoginPolicy to "Force MFA for local users", so that users authenticated through an IDP must not configure (and verify) an MFA.
109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
package instance
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
|
)
|
|
|
|
var (
|
|
LoginPolicyAddedEventType = instanceEventTypePrefix + policy.LoginPolicyAddedEventType
|
|
LoginPolicyChangedEventType = instanceEventTypePrefix + policy.LoginPolicyChangedEventType
|
|
)
|
|
|
|
type LoginPolicyAddedEvent struct {
|
|
policy.LoginPolicyAddedEvent
|
|
}
|
|
|
|
func NewLoginPolicyAddedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
allowUsernamePassword,
|
|
allowRegister,
|
|
allowExternalIDP,
|
|
forceMFA,
|
|
forceMFALocalOnly,
|
|
hidePasswordReset,
|
|
ignoreUnknownUsernames,
|
|
allowDomainDiscovery,
|
|
disableLoginWithEmail,
|
|
disableLoginWithPhone bool,
|
|
passwordlessType domain.PasswordlessType,
|
|
defaultRedirectURI string,
|
|
passwordCheckLifetime,
|
|
externalLoginCheckLifetime,
|
|
mfaInitSkipLifetime,
|
|
secondFactorCheckLifetime,
|
|
multiFactorCheckLifetime time.Duration,
|
|
) *LoginPolicyAddedEvent {
|
|
return &LoginPolicyAddedEvent{
|
|
LoginPolicyAddedEvent: *policy.NewLoginPolicyAddedEvent(
|
|
eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
LoginPolicyAddedEventType),
|
|
allowUsernamePassword,
|
|
allowRegister,
|
|
allowExternalIDP,
|
|
forceMFA,
|
|
forceMFALocalOnly,
|
|
hidePasswordReset,
|
|
ignoreUnknownUsernames,
|
|
allowDomainDiscovery,
|
|
disableLoginWithEmail,
|
|
disableLoginWithPhone,
|
|
passwordlessType,
|
|
defaultRedirectURI,
|
|
passwordCheckLifetime,
|
|
externalLoginCheckLifetime,
|
|
mfaInitSkipLifetime,
|
|
secondFactorCheckLifetime,
|
|
multiFactorCheckLifetime),
|
|
}
|
|
}
|
|
|
|
func LoginPolicyAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
e, err := policy.LoginPolicyAddedEventMapper(event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &LoginPolicyAddedEvent{LoginPolicyAddedEvent: *e.(*policy.LoginPolicyAddedEvent)}, nil
|
|
}
|
|
|
|
type LoginPolicyChangedEvent struct {
|
|
policy.LoginPolicyChangedEvent
|
|
}
|
|
|
|
func NewLoginPolicyChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
changes []policy.LoginPolicyChanges,
|
|
) (*LoginPolicyChangedEvent, error) {
|
|
changedEvent, err := policy.NewLoginPolicyChangedEvent(
|
|
eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
LoginPolicyChangedEventType),
|
|
changes,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &LoginPolicyChangedEvent{LoginPolicyChangedEvent: *changedEvent}, nil
|
|
}
|
|
|
|
func LoginPolicyChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
e, err := policy.LoginPolicyChangedEventMapper(event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &LoginPolicyChangedEvent{LoginPolicyChangedEvent: *e.(*policy.LoginPolicyChangedEvent)}, nil
|
|
}
|