2023-09-29 11:26:14 +02:00
|
|
|
package idp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SAMLIDPAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
|
|
Key *crypto.CryptoValue `json:"key,omitempty"`
|
|
|
|
Certificate []byte `json:"certificate,omitempty"`
|
|
|
|
Binding string `json:"binding,omitempty"`
|
|
|
|
WithSignedRequest bool `json:"withSignedRequest,omitempty"`
|
|
|
|
Options
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSAMLIDPAddedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id,
|
|
|
|
name string,
|
|
|
|
metadata []byte,
|
|
|
|
key *crypto.CryptoValue,
|
|
|
|
certificate []byte,
|
|
|
|
binding string,
|
|
|
|
withSignedRequest bool,
|
|
|
|
options Options,
|
|
|
|
) *SAMLIDPAddedEvent {
|
|
|
|
return &SAMLIDPAddedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
ID: id,
|
|
|
|
Name: name,
|
|
|
|
Metadata: metadata,
|
|
|
|
Key: key,
|
|
|
|
Certificate: certificate,
|
|
|
|
Binding: binding,
|
|
|
|
WithSignedRequest: withSignedRequest,
|
|
|
|
Options: options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *SAMLIDPAddedEvent) Payload() interface{} {
|
2023-09-29 11:26:14 +02:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *SAMLIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-09-29 11:26:14 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func SAMLIDPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-09-29 11:26:14 +02:00
|
|
|
e := &SAMLIDPAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2023-09-29 11:26:14 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "IDP-v9uajo3k71", "unable to unmarshal event")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type SAMLIDPChangedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name *string `json:"name,omitempty"`
|
|
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
|
|
Key *crypto.CryptoValue `json:"key,omitempty"`
|
|
|
|
Certificate []byte `json:"certificate,omitempty"`
|
|
|
|
Binding *string `json:"binding,omitempty"`
|
|
|
|
WithSignedRequest *bool `json:"withSignedRequest,omitempty"`
|
|
|
|
OptionChanges
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSAMLIDPChangedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id string,
|
|
|
|
changes []SAMLIDPChanges,
|
|
|
|
) (*SAMLIDPChangedEvent, error) {
|
|
|
|
if len(changes) == 0 {
|
|
|
|
return nil, errors.ThrowPreconditionFailed(nil, "IDP-cz6mnf860t", "Errors.NoChangesFound")
|
|
|
|
}
|
|
|
|
changedEvent := &SAMLIDPChangedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
ID: id,
|
|
|
|
}
|
|
|
|
for _, change := range changes {
|
|
|
|
change(changedEvent)
|
|
|
|
}
|
|
|
|
return changedEvent, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type SAMLIDPChanges func(*SAMLIDPChangedEvent)
|
|
|
|
|
|
|
|
func ChangeSAMLName(name string) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.Name = &name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeSAMLMetadata(metadata []byte) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.Metadata = metadata
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeSAMLKey(key *crypto.CryptoValue) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.Key = key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeSAMLCertificate(certificate []byte) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.Certificate = certificate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeSAMLBinding(binding string) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.Binding = &binding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeSAMLWithSignedRequest(withSignedRequest bool) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.WithSignedRequest = &withSignedRequest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeSAMLOptions(options OptionChanges) func(*SAMLIDPChangedEvent) {
|
|
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
|
|
e.OptionChanges = options
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *SAMLIDPChangedEvent) Payload() interface{} {
|
2023-09-29 11:26:14 +02:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *SAMLIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-09-29 11:26:14 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func SAMLIDPChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-09-29 11:26:14 +02:00
|
|
|
e := &SAMLIDPChangedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2023-09-29 11:26:14 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "IDP-w1t1824tw5", "unable to unmarshal event")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|