mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
db1d8f4efe
* feat: oidc config * fix: oidc configurations * feat: oidc idp config * feat: add oidc config test * fix: tests * fix: tests * feat: translate new events * feat: idp eventstore * feat: idp eventstore * fix: tests * feat: command side idp * feat: query side idp * feat: idp config on org * fix: tests * feat: authz idp on org * feat: org idps * feat: login policy * feat: login policy * feat: login policy * feat: add idp func on login policy * feat: add validation to loginpolicy and idp provider * feat: add default login policy * feat: login policy on org * feat: login policy on org * fix: id config handlers * fix: id config handlers * fix: create idp on org * fix: create idp on org * fix: not existing idp config * fix: default login policy * fix: add login policy on org * fix: idp provider search on org * fix: test * fix: remove idp on org * fix: test * fix: test * fix: remove admin idp * fix: logo src as byte * fix: migration * fix: tests * Update internal/iam/repository/eventsourcing/iam.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/org/repository/eventsourcing/org_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: pr comments * fix: tests * Update types.go * fix: merge request changes * fix: reduce optimization Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com>
122 lines
4.3 KiB
Go
122 lines
4.3 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
"time"
|
|
|
|
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
|
|
"github.com/caos/logging"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/model"
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const (
|
|
IDPConfigKeyIdpConfigID = "idp_config_id"
|
|
IDPConfigKeyAggregateID = "aggregate_id"
|
|
IDPConfigKeyName = "name"
|
|
IDPConfigKeyProviderType = "idp_provider_type"
|
|
)
|
|
|
|
type IDPConfigView struct {
|
|
IDPConfigID string `json:"idpConfigId" gorm:"column:idp_config_id;primary_key"`
|
|
AggregateID string `json:"-" gorm:"column:aggregate_id"`
|
|
Name string `json:"name" gorm:"column:name"`
|
|
LogoSrc []byte `json:"logoSrc" gorm:"column:logo_src"`
|
|
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
|
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
|
IDPState int32 `json:"-" gorm:"column:idp_state"`
|
|
IDPProviderType int32 `json:"-" gorm:"column:idp_provider_type"`
|
|
|
|
IsOIDC bool `json:"-" gorm:"column:is_oidc"`
|
|
OIDCClientID string `json:"clientId" gorm:"column:oidc_client_id"`
|
|
OIDCClientSecret *crypto.CryptoValue `json:"clientSecret" gorm:"column:oidc_client_secret"`
|
|
OIDCIssuer string `json:"issuer" gorm:"column:oidc_issuer"`
|
|
OIDCScopes pq.StringArray `json:"scopes" gorm:"column:oidc_scopes"`
|
|
|
|
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
|
}
|
|
|
|
func IDPConfigViewFromModel(idp *model.IDPConfigView) *IDPConfigView {
|
|
return &IDPConfigView{
|
|
IDPConfigID: idp.IDPConfigID,
|
|
AggregateID: idp.AggregateID,
|
|
Name: idp.Name,
|
|
LogoSrc: idp.LogoSrc,
|
|
Sequence: idp.Sequence,
|
|
CreationDate: idp.CreationDate,
|
|
ChangeDate: idp.ChangeDate,
|
|
IDPProviderType: int32(idp.IDPProviderType),
|
|
IsOIDC: idp.IsOIDC,
|
|
OIDCClientID: idp.OIDCClientID,
|
|
OIDCClientSecret: idp.OIDCClientSecret,
|
|
OIDCIssuer: idp.OIDCIssuer,
|
|
OIDCScopes: idp.OIDCScopes,
|
|
}
|
|
}
|
|
|
|
func IdpConfigViewToModel(idp *IDPConfigView) *model.IDPConfigView {
|
|
return &model.IDPConfigView{
|
|
IDPConfigID: idp.IDPConfigID,
|
|
AggregateID: idp.AggregateID,
|
|
Name: idp.Name,
|
|
LogoSrc: idp.LogoSrc,
|
|
Sequence: idp.Sequence,
|
|
CreationDate: idp.CreationDate,
|
|
ChangeDate: idp.ChangeDate,
|
|
IDPProviderType: model.IDPProviderType(idp.IDPProviderType),
|
|
IsOIDC: idp.IsOIDC,
|
|
OIDCClientID: idp.OIDCClientID,
|
|
OIDCClientSecret: idp.OIDCClientSecret,
|
|
OIDCIssuer: idp.OIDCIssuer,
|
|
OIDCScopes: idp.OIDCScopes,
|
|
}
|
|
}
|
|
|
|
func IdpConfigViewsToModel(idps []*IDPConfigView) []*model.IDPConfigView {
|
|
result := make([]*model.IDPConfigView, len(idps))
|
|
for i, idp := range idps {
|
|
result[i] = IdpConfigViewToModel(idp)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (i *IDPConfigView) AppendEvent(providerType model.IDPProviderType, event *models.Event) (err error) {
|
|
i.Sequence = event.Sequence
|
|
i.ChangeDate = event.CreationDate
|
|
switch event.Type {
|
|
case es_model.IDPConfigAdded, org_es_model.IDPConfigAdded:
|
|
i.setRootData(event)
|
|
i.CreationDate = event.CreationDate
|
|
i.IDPProviderType = int32(providerType)
|
|
err = i.SetData(event)
|
|
case es_model.OIDCIDPConfigAdded, org_es_model.OIDCIDPConfigAdded:
|
|
i.IsOIDC = true
|
|
err = i.SetData(event)
|
|
case es_model.OIDCIDPConfigChanged, org_es_model.OIDCIDPConfigChanged,
|
|
es_model.IDPConfigChanged, org_es_model.IDPConfigChanged:
|
|
err = i.SetData(event)
|
|
case es_model.IDPConfigDeactivated, org_es_model.IDPConfigDeactivated:
|
|
i.IDPState = int32(model.IDPConfigStateInactive)
|
|
case es_model.IDPConfigReactivated, org_es_model.IDPConfigReactivated:
|
|
i.IDPState = int32(model.IDPConfigStateActive)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (r *IDPConfigView) setRootData(event *models.Event) {
|
|
r.AggregateID = event.AggregateID
|
|
}
|
|
|
|
func (r *IDPConfigView) SetData(event *models.Event) error {
|
|
if err := json.Unmarshal(event.Data, r); err != nil {
|
|
logging.Log("EVEN-Smkld").WithError(err).Error("could not unmarshal event data")
|
|
return caos_errs.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
|
|
}
|
|
return nil
|
|
}
|