mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: add management for ldap idp template (#5220)
Add management functionality for LDAP idps with templates and the basic functionality for the LDAP provider, which can then be used with a separate login page in the future. --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
104
internal/repository/idp/idp.go
Normal file
104
internal/repository/idp/idp.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package idp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
IsCreationAllowed bool `json:"isCreationAllowed,omitempty"`
|
||||
IsLinkingAllowed bool `json:"isLinkingAllowed,omitempty"`
|
||||
IsAutoCreation bool `json:"isAutoCreation,omitempty"`
|
||||
IsAutoUpdate bool `json:"isAutoUpdate,omitempty"`
|
||||
}
|
||||
|
||||
type OptionChanges struct {
|
||||
IsCreationAllowed *bool `json:"isCreationAllowed,omitempty"`
|
||||
IsLinkingAllowed *bool `json:"isLinkingAllowed,omitempty"`
|
||||
IsAutoCreation *bool `json:"isAutoCreation,omitempty"`
|
||||
IsAutoUpdate *bool `json:"isAutoUpdate,omitempty"`
|
||||
}
|
||||
|
||||
func (o *Options) Changes(options Options) OptionChanges {
|
||||
opts := OptionChanges{}
|
||||
if o.IsCreationAllowed != options.IsCreationAllowed {
|
||||
opts.IsCreationAllowed = &options.IsCreationAllowed
|
||||
}
|
||||
if o.IsLinkingAllowed != options.IsLinkingAllowed {
|
||||
opts.IsLinkingAllowed = &options.IsLinkingAllowed
|
||||
}
|
||||
if o.IsAutoCreation != options.IsAutoCreation {
|
||||
opts.IsAutoCreation = &options.IsAutoCreation
|
||||
}
|
||||
if o.IsAutoUpdate != options.IsAutoUpdate {
|
||||
opts.IsAutoUpdate = &options.IsAutoUpdate
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
func (o *Options) ReduceChanges(changes OptionChanges) {
|
||||
if changes.IsCreationAllowed != nil {
|
||||
o.IsCreationAllowed = *changes.IsCreationAllowed
|
||||
}
|
||||
if changes.IsLinkingAllowed != nil {
|
||||
o.IsLinkingAllowed = *changes.IsLinkingAllowed
|
||||
}
|
||||
if changes.IsAutoUpdate != nil {
|
||||
o.IsAutoUpdate = *changes.IsAutoUpdate
|
||||
}
|
||||
if changes.IsAutoUpdate != nil {
|
||||
o.IsAutoUpdate = *changes.IsAutoUpdate
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OptionChanges) IsZero() bool {
|
||||
return o.IsCreationAllowed == nil && o.IsLinkingAllowed == nil && o.IsAutoCreation == nil && o.IsAutoUpdate == nil
|
||||
}
|
||||
|
||||
type RemovedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ID string `json:"id"`
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewRemovedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
id string,
|
||||
name string,
|
||||
) *RemovedEvent {
|
||||
return &RemovedEvent{
|
||||
BaseEvent: *base,
|
||||
ID: id,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *RemovedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *RemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
if e.name == "" {
|
||||
return nil
|
||||
}
|
||||
return []*eventstore.EventUniqueConstraint{idpconfig.NewRemoveIDPConfigNameUniqueConstraint(e.name, e.Aggregate().ResourceOwner)}
|
||||
}
|
||||
|
||||
func RemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
e := &RemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "IDP-plSD2", "unable to unmarshal event")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
351
internal/repository/idp/ldap.go
Normal file
351
internal/repository/idp/ldap.go
Normal file
@@ -0,0 +1,351 @@
|
||||
package idp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
||||
)
|
||||
|
||||
type LDAPIDPAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port,omitempty"`
|
||||
TLS bool `json:"tls"`
|
||||
BaseDN string `json:"baseDN"`
|
||||
UserObjectClass string `json:"userObjectClass"`
|
||||
UserUniqueAttribute string `json:"userUniqueAttribute"`
|
||||
Admin string `json:"admin"`
|
||||
Password *crypto.CryptoValue `json:"password"`
|
||||
|
||||
LDAPAttributes
|
||||
Options
|
||||
}
|
||||
|
||||
type LDAPAttributes struct {
|
||||
IDAttribute string `json:"idAttribute,omitempty"`
|
||||
FirstNameAttribute string `json:"firstNameAttribute,omitempty"`
|
||||
LastNameAttribute string `json:"lastNameAttribute,omitempty"`
|
||||
DisplayNameAttribute string `json:"displayNameAttribute,omitempty"`
|
||||
NickNameAttribute string `json:"nickNameAttribute,omitempty"`
|
||||
PreferredUsernameAttribute string `json:"preferredUsernameAttribute,omitempty"`
|
||||
EmailAttribute string `json:"emailAttribute,omitempty"`
|
||||
EmailVerifiedAttribute string `json:"emailVerifiedAttribute,omitempty"`
|
||||
PhoneAttribute string `json:"phoneAttribute,omitempty"`
|
||||
PhoneVerifiedAttribute string `json:"phoneVerifiedAttribute,omitempty"`
|
||||
PreferredLanguageAttribute string `json:"preferredLanguageAttribute,omitempty"`
|
||||
AvatarURLAttribute string `json:"avatarURLAttribute,omitempty"`
|
||||
ProfileAttribute string `json:"profileAttribute,omitempty"`
|
||||
}
|
||||
|
||||
func (o *LDAPAttributes) Changes(attributes LDAPAttributes) LDAPAttributeChanges {
|
||||
attrs := LDAPAttributeChanges{}
|
||||
if o.IDAttribute != attributes.IDAttribute {
|
||||
attrs.IDAttribute = &attributes.IDAttribute
|
||||
}
|
||||
if o.FirstNameAttribute != attributes.FirstNameAttribute {
|
||||
attrs.FirstNameAttribute = &attributes.FirstNameAttribute
|
||||
}
|
||||
if o.LastNameAttribute != attributes.LastNameAttribute {
|
||||
attrs.LastNameAttribute = &attributes.LastNameAttribute
|
||||
}
|
||||
if o.DisplayNameAttribute != attributes.DisplayNameAttribute {
|
||||
attrs.DisplayNameAttribute = &attributes.DisplayNameAttribute
|
||||
}
|
||||
if o.NickNameAttribute != attributes.NickNameAttribute {
|
||||
attrs.NickNameAttribute = &attributes.NickNameAttribute
|
||||
}
|
||||
if o.PreferredUsernameAttribute != attributes.PreferredUsernameAttribute {
|
||||
attrs.PreferredUsernameAttribute = &attributes.PreferredUsernameAttribute
|
||||
}
|
||||
if o.EmailAttribute != attributes.EmailAttribute {
|
||||
attrs.EmailAttribute = &attributes.EmailAttribute
|
||||
}
|
||||
if o.EmailVerifiedAttribute != attributes.EmailVerifiedAttribute {
|
||||
attrs.EmailVerifiedAttribute = &attributes.EmailVerifiedAttribute
|
||||
}
|
||||
if o.PhoneAttribute != attributes.PhoneAttribute {
|
||||
attrs.PhoneAttribute = &attributes.PhoneAttribute
|
||||
}
|
||||
if o.PhoneVerifiedAttribute != attributes.PhoneVerifiedAttribute {
|
||||
attrs.PhoneVerifiedAttribute = &attributes.PhoneVerifiedAttribute
|
||||
}
|
||||
if o.PreferredLanguageAttribute != attributes.PreferredLanguageAttribute {
|
||||
attrs.PreferredLanguageAttribute = &attributes.PreferredLanguageAttribute
|
||||
}
|
||||
if o.AvatarURLAttribute != attributes.AvatarURLAttribute {
|
||||
attrs.AvatarURLAttribute = &attributes.AvatarURLAttribute
|
||||
}
|
||||
if o.ProfileAttribute != attributes.ProfileAttribute {
|
||||
attrs.ProfileAttribute = &attributes.ProfileAttribute
|
||||
}
|
||||
return attrs
|
||||
}
|
||||
|
||||
func (o *LDAPAttributes) ReduceChanges(changes LDAPAttributeChanges) {
|
||||
if changes.IDAttribute != nil {
|
||||
o.IDAttribute = *changes.IDAttribute
|
||||
}
|
||||
if changes.FirstNameAttribute != nil {
|
||||
o.FirstNameAttribute = *changes.FirstNameAttribute
|
||||
}
|
||||
if changes.LastNameAttribute != nil {
|
||||
o.LastNameAttribute = *changes.LastNameAttribute
|
||||
}
|
||||
if changes.DisplayNameAttribute != nil {
|
||||
o.DisplayNameAttribute = *changes.DisplayNameAttribute
|
||||
}
|
||||
if changes.NickNameAttribute != nil {
|
||||
o.NickNameAttribute = *changes.NickNameAttribute
|
||||
}
|
||||
if changes.PreferredUsernameAttribute != nil {
|
||||
o.PreferredUsernameAttribute = *changes.PreferredUsernameAttribute
|
||||
}
|
||||
if changes.EmailAttribute != nil {
|
||||
o.EmailAttribute = *changes.EmailAttribute
|
||||
}
|
||||
if changes.EmailVerifiedAttribute != nil {
|
||||
o.EmailVerifiedAttribute = *changes.EmailVerifiedAttribute
|
||||
}
|
||||
if changes.PhoneAttribute != nil {
|
||||
o.PhoneAttribute = *changes.PhoneAttribute
|
||||
}
|
||||
if changes.PhoneVerifiedAttribute != nil {
|
||||
o.PhoneVerifiedAttribute = *changes.PhoneVerifiedAttribute
|
||||
}
|
||||
if changes.PreferredLanguageAttribute != nil {
|
||||
o.PreferredLanguageAttribute = *changes.PreferredLanguageAttribute
|
||||
}
|
||||
if changes.AvatarURLAttribute != nil {
|
||||
o.AvatarURLAttribute = *changes.AvatarURLAttribute
|
||||
}
|
||||
if changes.ProfileAttribute != nil {
|
||||
o.ProfileAttribute = *changes.ProfileAttribute
|
||||
}
|
||||
}
|
||||
|
||||
func NewLDAPIDPAddedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
id,
|
||||
name,
|
||||
host,
|
||||
port string,
|
||||
tls bool,
|
||||
baseDN,
|
||||
userObjectClass,
|
||||
userUniqueAttribute,
|
||||
admin string,
|
||||
password *crypto.CryptoValue,
|
||||
attributes LDAPAttributes,
|
||||
options Options,
|
||||
) *LDAPIDPAddedEvent {
|
||||
return &LDAPIDPAddedEvent{
|
||||
BaseEvent: *base,
|
||||
ID: id,
|
||||
Name: name,
|
||||
Host: host,
|
||||
Port: port,
|
||||
TLS: tls,
|
||||
BaseDN: baseDN,
|
||||
UserObjectClass: userObjectClass,
|
||||
UserUniqueAttribute: userUniqueAttribute,
|
||||
Admin: admin,
|
||||
Password: password,
|
||||
LDAPAttributes: attributes,
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *LDAPIDPAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *LDAPIDPAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{idpconfig.NewAddIDPConfigNameUniqueConstraint(e.Name, e.Aggregate().ResourceOwner)}
|
||||
}
|
||||
|
||||
func LDAPIDPAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
e := &LDAPIDPAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "IDP-Dgh42", "unable to unmarshal event")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
|
||||
type LDAPIDPChangedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
oldName string
|
||||
|
||||
ID string `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Host *string `json:"host,omitempty"`
|
||||
Port *string `json:"port,omitempty"`
|
||||
TLS *bool `json:"tls,omitempty"`
|
||||
BaseDN *string `json:"baseDN,omitempty"`
|
||||
UserObjectClass *string `json:"userObjectClass,omitempty"`
|
||||
UserUniqueAttribute *string `json:"userUniqueAttribute,omitempty"`
|
||||
Admin *string `json:"admin,omitempty"`
|
||||
Password *crypto.CryptoValue `json:"password,omitempty"`
|
||||
|
||||
LDAPAttributeChanges
|
||||
OptionChanges
|
||||
}
|
||||
|
||||
type LDAPAttributeChanges struct {
|
||||
IDAttribute *string `json:"idAttribute,omitempty"`
|
||||
FirstNameAttribute *string `json:"firstNameAttribute,omitempty"`
|
||||
LastNameAttribute *string `json:"lastNameAttribute,omitempty"`
|
||||
DisplayNameAttribute *string `json:"displayNameAttribute,omitempty"`
|
||||
NickNameAttribute *string `json:"nickNameAttribute,omitempty"`
|
||||
PreferredUsernameAttribute *string `json:"preferredUsernameAttribute,omitempty"`
|
||||
EmailAttribute *string `json:"emailAttribute,omitempty"`
|
||||
EmailVerifiedAttribute *string `json:"emailVerifiedAttribute,omitempty"`
|
||||
PhoneAttribute *string `json:"phoneAttribute,omitempty"`
|
||||
PhoneVerifiedAttribute *string `json:"phoneVerifiedAttribute,omitempty"`
|
||||
PreferredLanguageAttribute *string `json:"preferredLanguageAttribute,omitempty"`
|
||||
AvatarURLAttribute *string `json:"avatarURLAttribute,omitempty"`
|
||||
ProfileAttribute *string `json:"profileAttribute,omitempty"`
|
||||
}
|
||||
|
||||
func (o LDAPAttributeChanges) IsZero() bool {
|
||||
return o.IDAttribute == nil &&
|
||||
o.FirstNameAttribute == nil &&
|
||||
o.LastNameAttribute == nil &&
|
||||
o.DisplayNameAttribute == nil &&
|
||||
o.NickNameAttribute == nil &&
|
||||
o.PreferredUsernameAttribute == nil &&
|
||||
o.EmailAttribute == nil &&
|
||||
o.EmailVerifiedAttribute == nil &&
|
||||
o.PhoneAttribute == nil &&
|
||||
o.PhoneVerifiedAttribute == nil &&
|
||||
o.PreferredLanguageAttribute == nil &&
|
||||
o.AvatarURLAttribute == nil &&
|
||||
o.ProfileAttribute == nil
|
||||
}
|
||||
|
||||
func NewLDAPIDPChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
id string,
|
||||
oldName string,
|
||||
changes []LDAPIDPChanges,
|
||||
) (*LDAPIDPChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "IDP-SDf3f", "Errors.NoChangesFound")
|
||||
}
|
||||
changedEvent := &LDAPIDPChangedEvent{
|
||||
BaseEvent: *base,
|
||||
ID: id,
|
||||
oldName: oldName,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changedEvent)
|
||||
}
|
||||
return changedEvent, nil
|
||||
}
|
||||
|
||||
type LDAPIDPChanges func(*LDAPIDPChangedEvent)
|
||||
|
||||
func ChangeLDAPName(name string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.Name = &name
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPHost(host string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.Host = &host
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPPort(port string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.Port = &port
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPTLS(tls bool) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.TLS = &tls
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPBaseDN(basDN string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.BaseDN = &basDN
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPUserObjectClass(userObjectClass string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.UserObjectClass = &userObjectClass
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPUserUniqueAttribute(userUniqueAttribute string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.UserUniqueAttribute = &userUniqueAttribute
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPAdmin(admin string) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.Admin = &admin
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPPassword(password *crypto.CryptoValue) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.Password = password
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPAttributes(attributes LDAPAttributeChanges) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.LDAPAttributeChanges = attributes
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeLDAPOptions(options OptionChanges) func(*LDAPIDPChangedEvent) {
|
||||
return func(e *LDAPIDPChangedEvent) {
|
||||
e.OptionChanges = options
|
||||
}
|
||||
}
|
||||
|
||||
func (e *LDAPIDPChangedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *LDAPIDPChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
if e.Name == nil || e.oldName == *e.Name { // TODO: nil check should be enough?
|
||||
return nil
|
||||
}
|
||||
return []*eventstore.EventUniqueConstraint{
|
||||
idpconfig.NewRemoveIDPConfigNameUniqueConstraint(e.oldName, e.Aggregate().ResourceOwner),
|
||||
idpconfig.NewAddIDPConfigNameUniqueConstraint(*e.Name, e.Aggregate().ResourceOwner),
|
||||
}
|
||||
}
|
||||
|
||||
func LDAPIDPChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
e := &LDAPIDPChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "IDP-Sfth3", "unable to unmarshal event")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
@@ -70,6 +70,9 @@ func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
RegisterFilterEventMapper(AggregateType, IDPOIDCConfigChangedEventType, IDPOIDCConfigChangedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, IDPJWTConfigAddedEventType, IDPJWTConfigAddedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, IDPJWTConfigChangedEventType, IDPJWTConfigChangedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LDAPIDPAddedEventType, LDAPIDPAddedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LDAPIDPChangedEventType, LDAPIDPChangedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, IDPRemovedEventType, IDPRemovedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LoginPolicyIDPProviderAddedEventType, IdentityProviderAddedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LoginPolicyIDPProviderRemovedEventType, IdentityProviderRemovedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LoginPolicyIDPProviderCascadeRemovedEventType, IdentityProviderCascadeRemovedEventMapper).
|
||||
|
142
internal/repository/instance/idp.go
Normal file
142
internal/repository/instance/idp.go
Normal file
@@ -0,0 +1,142 @@
|
||||
package instance
|
||||
|
||||
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 (
|
||||
LDAPIDPAddedEventType eventstore.EventType = "instance.idp.ldap.added"
|
||||
LDAPIDPChangedEventType eventstore.EventType = "instance.idp.ldap.changed"
|
||||
IDPRemovedEventType eventstore.EventType = "instance.idp.removed"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
@@ -78,6 +78,9 @@ func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
RegisterFilterEventMapper(AggregateType, IDPOIDCConfigChangedEventType, IDPOIDCConfigChangedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, IDPJWTConfigAddedEventType, IDPJWTConfigAddedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, IDPJWTConfigChangedEventType, IDPJWTConfigChangedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LDAPIDPAddedEventType, LDAPIDPAddedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LDAPIDPChangedEventType, LDAPIDPChangedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, IDPRemovedEventType, IDPRemovedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, TriggerActionsSetEventType, TriggerActionsSetEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, TriggerActionsCascadeRemovedEventType, TriggerActionsCascadeRemovedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, FlowClearedEventType, FlowClearedEventMapper).
|
||||
|
142
internal/repository/org/idp.go
Normal file
142
internal/repository/org/idp.go
Normal file
@@ -0,0 +1,142 @@
|
||||
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 (
|
||||
LDAPIDPAddedEventType eventstore.EventType = "org.idp.ldap.added"
|
||||
LDAPIDPChangedEventType eventstore.EventType = "org.idp.ldap.changed"
|
||||
IDPRemovedEventType eventstore.EventType = "org.idp.removed"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user