fix idp mappers

This commit is contained in:
adlerhurst 2020-11-30 10:41:10 +01:00
parent d494da67be
commit cf1df99a10
8 changed files with 43 additions and 22 deletions

View File

@ -24,7 +24,7 @@ func readModelToIAM(readModel *iam_repo.ReadModel) *model.IAM {
DefaultPasswordAgePolicy: readModelToPasswordAgePolicy(&readModel.DefaultPasswordAgePolicy),
DefaultPasswordComplexityPolicy: readModelToPasswordComplexityPolicy(&readModel.DefaultPasswordComplexityPolicy),
DefaultPasswordLockoutPolicy: readModelToPasswordLockoutPolicy(&readModel.DefaultPasswordLockoutPolicy),
// TODO: IDPs: []*model.IDPConfig,
IDPs: readModelToIDPConfigs(&readModel.IDPs),
}
}
@ -155,6 +155,14 @@ func readModelToIDPConfigView(rm *iam.IDPConfigReadModel) *model.IDPConfigView {
}
}
func readModelToIDPConfigs(rm *iam.IDPConfigsReadModel) []*model.IDPConfig {
configs := make([]*model.IDPConfig, len(rm.Configs))
for i, config := range rm.Configs {
configs[i] = readModelToIDPConfig(&iam.IDPConfigReadModel{ConfigReadModel: *config})
}
return configs
}
func readModelToIDPConfig(rm *iam.IDPConfigReadModel) *model.IDPConfig {
return &model.IDPConfig{
ObjectRoot: readModelToObjectRoot(rm.ReadModel),

View File

@ -39,15 +39,22 @@ func (r *Repository) AddIDPConfig(ctx context.Context, config *iam_model.IDPConf
}
writeModel, err := r.pushIDPWriteModel(ctx, config.AggregateID, idpConfigID, func(a *iam.Aggregate, _ *iam.IDPConfigWriteModel) *iam.Aggregate {
return a.PushIDPOIDCConfigAdded(
ctx,
config.OIDCConfig.ClientID,
idpConfigID,
config.OIDCConfig.Issuer,
clientSecret,
oidc.MappingField(config.OIDCConfig.IDPDisplayNameMapping),
oidc.MappingField(config.OIDCConfig.UsernameMapping),
config.OIDCConfig.Scopes...)
return a.
PushIDPConfigAdded(
ctx,
idpConfigID,
config.Name,
idp.ConfigType(config.Type),
idp.StylingType(config.StylingType)).
PushIDPOIDCConfigAdded(
ctx,
config.OIDCConfig.ClientID,
idpConfigID,
config.OIDCConfig.Issuer,
clientSecret,
oidc.MappingField(config.OIDCConfig.IDPDisplayNameMapping),
oidc.MappingField(config.OIDCConfig.UsernameMapping),
config.OIDCConfig.Scopes...)
})
if err != nil {
return nil, err
@ -114,7 +121,6 @@ func (r *Repository) pushIDPWriteModel(ctx context.Context, iamID, idpID string,
}
aggregate := eventSetter(iam.AggregateFromWriteModel(&writeModel.WriteModel), writeModel)
err = r.eventstore.PushAggregate(ctx, writeModel, aggregate)
if err != nil {
return nil, err

View File

@ -22,5 +22,12 @@ func RegisterEventMappers(es *eventstore.Eventstore) {
RegisterFilterEventMapper(PasswordLockoutPolicyChangedEventType, PasswordLockoutPolicyChangedEventMapper).
RegisterFilterEventMapper(MemberAddedEventType, MemberAddedEventMapper).
RegisterFilterEventMapper(MemberChangedEventType, MemberChangedEventMapper).
RegisterFilterEventMapper(MemberRemovedEventType, MemberRemovedEventMapper)
RegisterFilterEventMapper(MemberRemovedEventType, MemberRemovedEventMapper).
RegisterFilterEventMapper(IDPConfigAddedEventType, IDPConfigAddedEventMapper).
RegisterFilterEventMapper(IDPConfigChangedEventType, IDPConfigChangedEventMapper).
RegisterFilterEventMapper(IDPConfigRemovedEventType, IDPConfigRemovedEventMapper).
RegisterFilterEventMapper(IDPConfigDeactivatedEventType, IDPConfigDeactivatedEventMapper).
RegisterFilterEventMapper(IDPConfigReactivatedEventType, IDPConfigReactivatedEventMapper).
RegisterFilterEventMapper(IDPOIDCConfigAddedEventType, IDPOIDCConfigAddedEventMapper).
RegisterFilterEventMapper(IDPOIDCConfigChangedEventType, IDPOIDCConfigChangedEventMapper)
}

View File

@ -10,8 +10,8 @@ import (
)
const (
IDPOIDCConfigAddedEventType eventstore.EventType = "iam.idp.oidc.config.added"
IDPOIDCConfigChangedEventType eventstore.EventType = "iam.idp.oidc.config.changed"
IDPOIDCConfigAddedEventType eventstore.EventType = "iam.idp." + oidc.ConfigAddedEventType
IDPOIDCConfigChangedEventType eventstore.EventType = "iam.idp." + oidc.ConfigChangedEventType
)
type IDPOIDCConfigWriteModel struct {

View File

@ -9,6 +9,10 @@ import (
"github.com/caos/zitadel/internal/eventstore/v2/repository"
)
const (
ConfigAddedEventType eventstore.EventType = "oidc.config.added"
)
type ConfigAddedEvent struct {
eventstore.BaseEvent

View File

@ -11,6 +11,10 @@ import (
"github.com/caos/zitadel/internal/eventstore/v2/repository"
)
const (
ConfigChangedEventType eventstore.EventType = "oidc.config.changed"
)
type ConfigChangedEvent struct {
eventstore.BaseEvent `json:"-"`

View File

@ -14,10 +14,6 @@ const (
LabelPolicyRemovedEventType = "policy.label.removed"
)
type LabelPolicyAggregate struct {
eventstore.Aggregate
}
type LabelPolicyReadModel struct {
eventstore.ReadModel

View File

@ -17,10 +17,6 @@ const (
LoginPolicyIDPProviderRemovedEventType = "policy.login." + provider.RemovedEventType
)
type LoginPolicyAggregate struct {
eventstore.Aggregate
}
type LoginPolicyReadModel struct {
eventstore.ReadModel