2023-02-15 08:14:59 +00:00
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/idp"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-02-21 17:18:28 +00:00
|
|
|
GoogleIDPAddedEventType eventstore.EventType = "org.idp.google.added"
|
|
|
|
GoogleIDPChangedEventType eventstore.EventType = "org.idp.google.changed"
|
|
|
|
LDAPIDPAddedEventType eventstore.EventType = "org.idp.ldap.added"
|
|
|
|
LDAPIDPChangedEventType eventstore.EventType = "org.idp.ldap.changed"
|
|
|
|
IDPRemovedEventType eventstore.EventType = "org.idp.removed"
|
2023-02-15 08:14:59 +00:00
|
|
|
)
|
|
|
|
|
2023-02-21 17:18:28 +00:00
|
|
|
type GoogleIDPAddedEvent struct {
|
|
|
|
idp.GoogleIDPAddedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGoogleIDPAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
clientID string,
|
|
|
|
clientSecret *crypto.CryptoValue,
|
|
|
|
scopes []string,
|
|
|
|
options idp.Options,
|
|
|
|
) *GoogleIDPAddedEvent {
|
|
|
|
|
|
|
|
return &GoogleIDPAddedEvent{
|
|
|
|
GoogleIDPAddedEvent: *idp.NewGoogleIDPAddedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
GoogleIDPAddedEventType,
|
|
|
|
),
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
clientID,
|
|
|
|
clientSecret,
|
|
|
|
scopes,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GoogleIDPAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
|
|
e, err := idp.GoogleIDPAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &GoogleIDPAddedEvent{GoogleIDPAddedEvent: *e.(*idp.GoogleIDPAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type GoogleIDPChangedEvent struct {
|
|
|
|
idp.GoogleIDPChangedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGoogleIDPChangedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id string,
|
|
|
|
changes []idp.GoogleIDPChanges,
|
|
|
|
) (*GoogleIDPChangedEvent, error) {
|
|
|
|
|
|
|
|
changedEvent, err := idp.NewGoogleIDPChangedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
GoogleIDPChangedEventType,
|
|
|
|
),
|
|
|
|
id,
|
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &GoogleIDPChangedEvent{GoogleIDPChangedEvent: *changedEvent}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GoogleIDPChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
|
|
e, err := idp.GoogleIDPChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &GoogleIDPChangedEvent{GoogleIDPChangedEvent: *e.(*idp.GoogleIDPChangedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
2023-02-15 08:14:59 +00:00
|
|
|
type LDAPIDPAddedEvent struct {
|
|
|
|
idp.LDAPIDPAddedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLDAPIDPAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
host,
|
|
|
|
port string,
|
|
|
|
tls bool,
|
|
|
|
baseDN,
|
|
|
|
userObjectClass,
|
|
|
|
userUniqueAttribute,
|
|
|
|
admin string,
|
|
|
|
password *crypto.CryptoValue,
|
|
|
|
attributes idp.LDAPAttributes,
|
|
|
|
options idp.Options,
|
|
|
|
) *LDAPIDPAddedEvent {
|
|
|
|
|
|
|
|
return &LDAPIDPAddedEvent{
|
|
|
|
LDAPIDPAddedEvent: *idp.NewLDAPIDPAddedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
LDAPIDPAddedEventType,
|
|
|
|
),
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
host,
|
|
|
|
port,
|
|
|
|
tls,
|
|
|
|
baseDN,
|
|
|
|
userObjectClass,
|
|
|
|
userUniqueAttribute,
|
|
|
|
admin,
|
|
|
|
password,
|
|
|
|
attributes,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func LDAPIDPAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
|
|
e, err := idp.LDAPIDPAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &LDAPIDPAddedEvent{LDAPIDPAddedEvent: *e.(*idp.LDAPIDPAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type LDAPIDPChangedEvent struct {
|
|
|
|
idp.LDAPIDPChangedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLDAPIDPChangedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id,
|
|
|
|
oldName string,
|
|
|
|
changes []idp.LDAPIDPChanges,
|
|
|
|
) (*LDAPIDPChangedEvent, error) {
|
|
|
|
|
|
|
|
changedEvent, err := idp.NewLDAPIDPChangedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
LDAPIDPChangedEventType,
|
|
|
|
),
|
|
|
|
id,
|
|
|
|
oldName,
|
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &LDAPIDPChangedEvent{LDAPIDPChangedEvent: *changedEvent}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func LDAPIDPChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
|
|
e, err := idp.LDAPIDPChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &LDAPIDPChangedEvent{LDAPIDPChangedEvent: *e.(*idp.LDAPIDPChangedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPRemovedEvent struct {
|
|
|
|
idp.RemovedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id string,
|
|
|
|
name string,
|
|
|
|
) *IDPRemovedEvent {
|
|
|
|
return &IDPRemovedEvent{
|
|
|
|
RemovedEvent: *idp.NewRemovedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
IDPRemovedEventType,
|
|
|
|
),
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *IDPRemovedEvent) Data() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func IDPRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
|
|
e, err := idp.RemovedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &IDPRemovedEvent{RemovedEvent: *e.(*idp.RemovedEvent)}, nil
|
|
|
|
}
|