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>
102 lines
2.4 KiB
Go
102 lines
2.4 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/caos/logging"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/model"
|
|
)
|
|
|
|
type IAMMember struct {
|
|
es_models.ObjectRoot
|
|
UserID string `json:"userId,omitempty"`
|
|
Roles []string `json:"roles,omitempty"`
|
|
}
|
|
|
|
func GetIAMMember(members []*IAMMember, id string) (int, *IAMMember) {
|
|
for i, m := range members {
|
|
if m.UserID == id {
|
|
return i, m
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|
|
|
|
func IAMMembersToModel(members []*IAMMember) []*model.IAMMember {
|
|
convertedMembers := make([]*model.IAMMember, len(members))
|
|
for i, m := range members {
|
|
convertedMembers[i] = IAMMemberToModel(m)
|
|
}
|
|
return convertedMembers
|
|
}
|
|
|
|
func IAMMembersFromModel(members []*model.IAMMember) []*IAMMember {
|
|
convertedMembers := make([]*IAMMember, len(members))
|
|
for i, m := range members {
|
|
convertedMembers[i] = IAMMemberFromModel(m)
|
|
}
|
|
return convertedMembers
|
|
}
|
|
|
|
func IAMMemberFromModel(member *model.IAMMember) *IAMMember {
|
|
return &IAMMember{
|
|
ObjectRoot: member.ObjectRoot,
|
|
UserID: member.UserID,
|
|
Roles: member.Roles,
|
|
}
|
|
}
|
|
|
|
func IAMMemberToModel(member *IAMMember) *model.IAMMember {
|
|
return &model.IAMMember{
|
|
ObjectRoot: member.ObjectRoot,
|
|
UserID: member.UserID,
|
|
Roles: member.Roles,
|
|
}
|
|
}
|
|
|
|
func (iam *IAM) appendAddMemberEvent(event *es_models.Event) error {
|
|
member := &IAMMember{}
|
|
err := member.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
member.ObjectRoot.CreationDate = event.CreationDate
|
|
iam.Members = append(iam.Members, member)
|
|
return nil
|
|
}
|
|
|
|
func (iam *IAM) appendChangeMemberEvent(event *es_models.Event) error {
|
|
member := &IAMMember{}
|
|
err := member.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if i, m := GetIAMMember(iam.Members, member.UserID); m != nil {
|
|
iam.Members[i] = member
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (iam *IAM) appendRemoveMemberEvent(event *es_models.Event) error {
|
|
member := &IAMMember{}
|
|
err := member.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if i, m := GetIAMMember(iam.Members, member.UserID); m != nil {
|
|
iam.Members[i] = iam.Members[len(iam.Members)-1]
|
|
iam.Members[len(iam.Members)-1] = nil
|
|
iam.Members = iam.Members[:len(iam.Members)-1]
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *IAMMember) SetData(event *es_models.Event) error {
|
|
m.ObjectRoot.AppendEvent(event)
|
|
if err := json.Unmarshal(event.Data, m); err != nil {
|
|
logging.Log("EVEN-e4dkp").WithError(err).Error("could not unmarshal event data")
|
|
return err
|
|
}
|
|
return nil
|
|
}
|