mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +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
|
||||
}
|
Reference in New Issue
Block a user