mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-20 11:58:47 +00:00
feat: idps (#1188)
* add setup steps * refactoring * omitempty * cleanup * begin org * create org * setup org * setup org * merge * fixes * fixes * fixes * add project * add oidc application * fix app creation * add resourceOwner to writemodels * resource owner * cleanup * global org, iam project and iam member in setup * logs * logs * logs * cleanup * Update internal/v2/command/project.go Co-authored-by: Fabi <[email protected]> * check project state * add org domain commands * add org status changes and member commands * fixes * policies * login policy * fix iam project event * mapper * label policy * change to command * fix * fix * handle change event differently and lot of fixes * idps * fixes * fixes * fixes * changedEvent handling * fix change events * remove creation date Co-authored-by: Fabi <[email protected]>
This commit is contained in:
@@ -2,6 +2,7 @@ package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
@@ -57,12 +58,18 @@ type IDPConfigChangedEvent struct {
|
||||
|
||||
func NewIDPConfigChangedEvent(
|
||||
ctx context.Context,
|
||||
) *IDPConfigChangedEvent {
|
||||
return &IDPConfigChangedEvent{
|
||||
IDPConfigChangedEvent: *idpconfig.NewIDPConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(ctx, IDPConfigChangedEventType),
|
||||
),
|
||||
configID string,
|
||||
changes []idpconfig.IDPConfigChanges,
|
||||
) (*IDPConfigChangedEvent, error) {
|
||||
changeEvent, err := idpconfig.NewIDPConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(ctx, IDPConfigChangedEventType),
|
||||
configID,
|
||||
changes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &IDPConfigChangedEvent{IDPConfigChangedEvent: *changeEvent}, nil
|
||||
}
|
||||
|
||||
func IDPConfigChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
@@ -61,12 +62,18 @@ type IDPOIDCConfigChangedEvent struct {
|
||||
|
||||
func NewIDPOIDCConfigChangedEvent(
|
||||
ctx context.Context,
|
||||
) *IDPOIDCConfigChangedEvent {
|
||||
return &IDPOIDCConfigChangedEvent{
|
||||
OIDCConfigChangedEvent: *idpconfig.NewOIDCConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(ctx, IDPOIDCConfigChangedEventType),
|
||||
),
|
||||
idpConfigID string,
|
||||
changes []idpconfig.OIDCConfigChanges,
|
||||
) (*IDPOIDCConfigChangedEvent, error) {
|
||||
changeEvent, err := idpconfig.NewOIDCConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(ctx, IDPOIDCConfigChangedEventType),
|
||||
idpConfigID,
|
||||
changes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *changeEvent}, nil
|
||||
}
|
||||
|
||||
func IDPOIDCConfigChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package idpconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
@@ -54,9 +55,9 @@ func IDPConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader,
|
||||
type IDPConfigChangedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ConfigID string `json:"idpConfigId"`
|
||||
Name string `json:"name,omitempty"`
|
||||
StylingType domain.IDPConfigStylingType `json:"stylingType,omitempty"`
|
||||
ConfigID string `json:"idpConfigId"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
StylingType *domain.IDPConfigStylingType `json:"stylingType,omitempty"`
|
||||
}
|
||||
|
||||
func (e *IDPConfigChangedEvent) Data() interface{} {
|
||||
@@ -65,9 +66,33 @@ func (e *IDPConfigChangedEvent) Data() interface{} {
|
||||
|
||||
func NewIDPConfigChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *IDPConfigChangedEvent {
|
||||
return &IDPConfigChangedEvent{
|
||||
configID string,
|
||||
changes []IDPConfigChanges,
|
||||
) (*IDPConfigChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "IDPCONFIG-Dsg21", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &IDPConfigChangedEvent{
|
||||
BaseEvent: *base,
|
||||
ConfigID: configID,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type IDPConfigChanges func(*IDPConfigChangedEvent)
|
||||
|
||||
func ChangeName(name string) func(*IDPConfigChangedEvent) {
|
||||
return func(e *IDPConfigChangedEvent) {
|
||||
e.Name = &name
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeStyleType(styleType domain.IDPConfigStylingType) func(*IDPConfigChangedEvent) {
|
||||
return func(e *IDPConfigChangedEvent) {
|
||||
e.StylingType = &styleType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +112,7 @@ func IDPConfigChangedEventMapper(event *repository.Event) (eventstore.EventReade
|
||||
type IDPConfigDeactivatedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ConfigID string `idpConfigId`
|
||||
ConfigID string `json:"idpConfigId"`
|
||||
}
|
||||
|
||||
func NewIDPConfigDeactivatedEvent(
|
||||
@@ -121,7 +146,7 @@ func IDPConfigDeactivatedEventMapper(event *repository.Event) (eventstore.EventR
|
||||
type IDPConfigReactivatedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ConfigID string `idpConfigId`
|
||||
ConfigID string `json:"idpConfigId"`
|
||||
}
|
||||
|
||||
func NewIDPConfigReactivatedEvent(
|
||||
@@ -155,7 +180,7 @@ func IDPConfigReactivatedEventMapper(event *repository.Event) (eventstore.EventR
|
||||
type IDPConfigRemovedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ConfigID string `idpConfigId`
|
||||
ConfigID string `json:"idpConfigId"`
|
||||
}
|
||||
|
||||
func NewIDPConfigRemovedEvent(
|
||||
|
||||
@@ -2,6 +2,7 @@ package idpconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
@@ -72,13 +73,13 @@ type OIDCConfigChangedEvent struct {
|
||||
|
||||
IDPConfigID string `json:"idpConfigId"`
|
||||
|
||||
ClientID string `json:"clientId,omitempty"`
|
||||
ClientID *string `json:"clientId,omitempty"`
|
||||
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
||||
Issuer string `json:"issuer,omitempty"`
|
||||
Issuer *string `json:"issuer,omitempty"`
|
||||
Scopes []string `json:"scpoes,omitempty"`
|
||||
|
||||
IDPDisplayNameMapping domain.OIDCMappingField `json:"idpDisplayNameMapping,omitempty"`
|
||||
UserNameMapping domain.OIDCMappingField `json:"usernameMapping,omitempty"`
|
||||
IDPDisplayNameMapping *domain.OIDCMappingField `json:"idpDisplayNameMapping,omitempty"`
|
||||
UserNameMapping *domain.OIDCMappingField `json:"usernameMapping,omitempty"`
|
||||
}
|
||||
|
||||
func (e *OIDCConfigChangedEvent) Data() interface{} {
|
||||
@@ -87,9 +88,57 @@ func (e *OIDCConfigChangedEvent) Data() interface{} {
|
||||
|
||||
func NewOIDCConfigChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *OIDCConfigChangedEvent {
|
||||
return &OIDCConfigChangedEvent{
|
||||
BaseEvent: *base,
|
||||
idpConfigID string,
|
||||
changes []OIDCConfigChanges,
|
||||
) (*OIDCConfigChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "IDPCONFIG-ADzr5", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &OIDCConfigChangedEvent{
|
||||
BaseEvent: *base,
|
||||
IDPConfigID: idpConfigID,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type OIDCConfigChanges func(*OIDCConfigChangedEvent)
|
||||
|
||||
func ChangeClientID(clientID string) func(*OIDCConfigChangedEvent) {
|
||||
return func(e *OIDCConfigChangedEvent) {
|
||||
e.ClientID = &clientID
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeClientSecret(secret *crypto.CryptoValue) func(*OIDCConfigChangedEvent) {
|
||||
return func(e *OIDCConfigChangedEvent) {
|
||||
e.ClientSecret = secret
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeIssuer(issuer string) func(*OIDCConfigChangedEvent) {
|
||||
return func(e *OIDCConfigChangedEvent) {
|
||||
e.Issuer = &issuer
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeIDPDisplayNameMapping(idpDisplayNameMapping domain.OIDCMappingField) func(*OIDCConfigChangedEvent) {
|
||||
return func(e *OIDCConfigChangedEvent) {
|
||||
e.IDPDisplayNameMapping = &idpDisplayNameMapping
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeUserNameMapping(userNameMapping domain.OIDCMappingField) func(*OIDCConfigChangedEvent) {
|
||||
return func(e *OIDCConfigChangedEvent) {
|
||||
e.UserNameMapping = &userNameMapping
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeScopes(scopes []string) func(*OIDCConfigChangedEvent) {
|
||||
return func(e *OIDCConfigChangedEvent) {
|
||||
e.Scopes = scopes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idpconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPConfigAddedEventType eventstore.EventType = "org.idp.config.added"
|
||||
IDPConfigChangedEventType eventstore.EventType = "org.idp.config.changed"
|
||||
IDPConfigRemovedEventType eventstore.EventType = "org.idp.config.removed"
|
||||
IDPConfigDeactivatedEventType eventstore.EventType = "org.idp.config.deactivated"
|
||||
IDPConfigReactivatedEventType eventstore.EventType = "org.idp.config.reactivated"
|
||||
)
|
||||
|
||||
type IDPConfigAddedEvent struct {
|
||||
idpconfig.IDPConfigAddedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigAddedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
name string,
|
||||
configType domain.IDPConfigType,
|
||||
stylingType domain.IDPConfigStylingType,
|
||||
) *IDPConfigAddedEvent {
|
||||
|
||||
return &IDPConfigAddedEvent{
|
||||
IDPConfigAddedEvent: *idpconfig.NewIDPConfigAddedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigAddedEventType,
|
||||
),
|
||||
configID,
|
||||
name,
|
||||
configType,
|
||||
stylingType,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.IDPConfigAddedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPConfigAddedEvent{IDPConfigAddedEvent: *e.(*idpconfig.IDPConfigAddedEvent)}, nil
|
||||
}
|
||||
|
||||
type IDPConfigChangedEvent struct {
|
||||
idpconfig.IDPConfigChangedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigChangedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
changes []idpconfig.IDPConfigChanges,
|
||||
) (*IDPConfigChangedEvent, error) {
|
||||
changeEvent, err := idpconfig.NewIDPConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(ctx, IDPConfigChangedEventType),
|
||||
configID,
|
||||
changes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &IDPConfigChangedEvent{IDPConfigChangedEvent: *changeEvent}, nil
|
||||
}
|
||||
|
||||
func IDPConfigChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.IDPConfigChangedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPConfigChangedEvent{IDPConfigChangedEvent: *e.(*idpconfig.IDPConfigChangedEvent)}, nil
|
||||
}
|
||||
|
||||
type IDPConfigRemovedEvent struct {
|
||||
idpconfig.IDPConfigRemovedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigRemovedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
) *IDPConfigRemovedEvent {
|
||||
|
||||
return &IDPConfigRemovedEvent{
|
||||
IDPConfigRemovedEvent: *idpconfig.NewIDPConfigRemovedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigRemovedEventType,
|
||||
),
|
||||
configID,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPConfigRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.IDPConfigRemovedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPConfigRemovedEvent{IDPConfigRemovedEvent: *e.(*idpconfig.IDPConfigRemovedEvent)}, nil
|
||||
}
|
||||
|
||||
type IDPConfigDeactivatedEvent struct {
|
||||
idpconfig.IDPConfigDeactivatedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigDeactivatedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
) *IDPConfigDeactivatedEvent {
|
||||
|
||||
return &IDPConfigDeactivatedEvent{
|
||||
IDPConfigDeactivatedEvent: *idpconfig.NewIDPConfigDeactivatedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigDeactivatedEventType,
|
||||
),
|
||||
configID,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPConfigDeactivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.IDPConfigDeactivatedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPConfigDeactivatedEvent{IDPConfigDeactivatedEvent: *e.(*idpconfig.IDPConfigDeactivatedEvent)}, nil
|
||||
}
|
||||
|
||||
type IDPConfigReactivatedEvent struct {
|
||||
idpconfig.IDPConfigReactivatedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigReactivatedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
) *IDPConfigReactivatedEvent {
|
||||
|
||||
return &IDPConfigReactivatedEvent{
|
||||
IDPConfigReactivatedEvent: *idpconfig.NewIDPConfigReactivatedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigReactivatedEventType,
|
||||
),
|
||||
configID,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPConfigReactivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.IDPConfigReactivatedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPConfigReactivatedEvent{IDPConfigReactivatedEvent: *e.(*idpconfig.IDPConfigReactivatedEvent)}, nil
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idpconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPOIDCConfigAddedEventType eventstore.EventType = "org.idp." + idpconfig.OIDCConfigAddedEventType
|
||||
IDPOIDCConfigChangedEventType eventstore.EventType = "org.idp." + idpconfig.ConfigChangedEventType
|
||||
)
|
||||
|
||||
type IDPOIDCConfigAddedEvent struct {
|
||||
idpconfig.OIDCConfigAddedEvent
|
||||
}
|
||||
|
||||
func NewIDPOIDCConfigAddedEvent(
|
||||
ctx context.Context,
|
||||
clientID,
|
||||
idpConfigID,
|
||||
issuer string,
|
||||
clientSecret *crypto.CryptoValue,
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping domain.OIDCMappingField,
|
||||
scopes ...string,
|
||||
) *IDPOIDCConfigAddedEvent {
|
||||
|
||||
return &IDPOIDCConfigAddedEvent{
|
||||
OIDCConfigAddedEvent: *idpconfig.NewOIDCConfigAddedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPOIDCConfigAddedEventType,
|
||||
),
|
||||
clientID,
|
||||
idpConfigID,
|
||||
issuer,
|
||||
clientSecret,
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping,
|
||||
scopes...,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPOIDCConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.OIDCConfigAddedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPOIDCConfigAddedEvent{OIDCConfigAddedEvent: *e.(*idpconfig.OIDCConfigAddedEvent)}, nil
|
||||
}
|
||||
|
||||
type IDPOIDCConfigChangedEvent struct {
|
||||
idpconfig.OIDCConfigChangedEvent
|
||||
}
|
||||
|
||||
func NewIDPOIDCConfigChangedEvent(
|
||||
ctx context.Context,
|
||||
idpConfigID string,
|
||||
changes []idpconfig.OIDCConfigChanges,
|
||||
) (*IDPOIDCConfigChangedEvent, error) {
|
||||
changeEvent, err := idpconfig.NewOIDCConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(ctx, IDPOIDCConfigChangedEventType),
|
||||
idpConfigID,
|
||||
changes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *changeEvent}, nil
|
||||
}
|
||||
|
||||
func IDPOIDCConfigChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e, err := idpconfig.OIDCConfigChangedEventMapper(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *e.(*idpconfig.OIDCConfigChangedEvent)}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user