mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-29 07:28:52 +00:00
* feat: login policy * feat: password complexity policy * feat: org iam policy * feat: label policy * feat: add and change policies * feat: second factors * feat: second and multi factors * feat: better naming * feat: better naming
93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package org_iam
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
|
)
|
|
|
|
const (
|
|
OrgIAMPolicyAddedEventType = "policy.org.iam.added"
|
|
OrgIAMPolicyChangedEventType = "policy.org.iam.changed"
|
|
)
|
|
|
|
type AddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
UserLoginMustBeDomain bool `json:"userLoginMustBeDomain"`
|
|
}
|
|
|
|
func (e *AddedEvent) CheckPrevious() bool {
|
|
return true
|
|
}
|
|
|
|
func (e *AddedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func NewAddedEvent(
|
|
base *eventstore.BaseEvent,
|
|
userLoginMustBeDomain bool,
|
|
) *AddedEvent {
|
|
|
|
return &AddedEvent{
|
|
BaseEvent: *base,
|
|
UserLoginMustBeDomain: userLoginMustBeDomain,
|
|
}
|
|
}
|
|
|
|
func AddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
e := &AddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "POLIC-TvSmA", "unable to unmarshal policy")
|
|
}
|
|
|
|
return e, nil
|
|
}
|
|
|
|
type ChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
UserLoginMustBeDomain bool `json:"userLoginMustBeDomain"`
|
|
}
|
|
|
|
func (e *ChangedEvent) CheckPrevious() bool {
|
|
return true
|
|
}
|
|
|
|
func (e *ChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func NewChangedEvent(
|
|
base *eventstore.BaseEvent,
|
|
current *WriteModel,
|
|
userLoginMustBeDomain bool,
|
|
) *ChangedEvent {
|
|
e := &ChangedEvent{
|
|
BaseEvent: *base,
|
|
}
|
|
if current.UserLoginMustBeDomain != userLoginMustBeDomain {
|
|
e.UserLoginMustBeDomain = userLoginMustBeDomain
|
|
}
|
|
return e
|
|
}
|
|
|
|
func ChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
e := &ChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "POLIC-0Pl9d", "unable to unmarshal policy")
|
|
}
|
|
|
|
return e, nil
|
|
}
|