mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-08 13:07:41 +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>
100 lines
3.3 KiB
Go
100 lines
3.3 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/logging"
|
|
|
|
auth_model "github.com/caos/zitadel/internal/auth/model"
|
|
auth_view "github.com/caos/zitadel/internal/auth/repository/eventsourcing/view"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/eventstore/sdk"
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
|
org_es "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/org/repository/view/model"
|
|
policy_model "github.com/caos/zitadel/internal/policy/model"
|
|
policy_es "github.com/caos/zitadel/internal/policy/repository/eventsourcing"
|
|
usr_es "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
|
)
|
|
|
|
const (
|
|
orgOwnerRole = "ORG_OWNER"
|
|
)
|
|
|
|
type OrgRepository struct {
|
|
SearchLimit uint64
|
|
OrgEventstore *org_es.OrgEventstore
|
|
UserEventstore *usr_es.UserEventstore
|
|
PolicyEventstore *policy_es.PolicyEventstore
|
|
|
|
View *auth_view.View
|
|
}
|
|
|
|
func (repo *OrgRepository) SearchOrgs(ctx context.Context, request *org_model.OrgSearchRequest) (*org_model.OrgSearchResult, error) {
|
|
request.EnsureLimit(repo.SearchLimit)
|
|
sequence, err := repo.View.GetLatestOrgSequence()
|
|
logging.Log("EVENT-7Udhz").OnError(err).Warn("could not read latest org sequence")
|
|
members, count, err := repo.View.SearchOrgs(request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := &org_model.OrgSearchResult{
|
|
Offset: request.Offset,
|
|
Limit: request.Limit,
|
|
TotalResult: uint64(count),
|
|
Result: model.OrgsToModel(members),
|
|
}
|
|
if err == nil {
|
|
result.Sequence = sequence.CurrentSequence
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (repo *OrgRepository) RegisterOrg(ctx context.Context, register *auth_model.RegisterOrg) (*auth_model.RegisterOrg, error) {
|
|
pwPolicy, err := repo.PolicyEventstore.GetPasswordComplexityPolicy(ctx, policy_model.DefaultPolicy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
orgPolicy, err := repo.OrgEventstore.GetOrgIAMPolicy(ctx, policy_model.DefaultPolicy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
users := func(ctx context.Context, domain string) ([]*es_models.Aggregate, error) {
|
|
userIDs, err := repo.View.UserIDsByDomain(domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return repo.UserEventstore.PrepareDomainClaimed(ctx, userIDs)
|
|
}
|
|
org, aggregates, err := repo.OrgEventstore.PrepareCreateOrg(ctx, register.Org, users)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
user, userAggregates, err := repo.UserEventstore.PrepareRegisterUser(ctx, register.User, pwPolicy, orgPolicy, org.AggregateID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
aggregates = append(aggregates, userAggregates...)
|
|
registerModel := &Register{Org: org, User: user}
|
|
|
|
member := org_model.NewOrgMemberWithRoles(org.AggregateID, user.AggregateID, orgOwnerRole)
|
|
_, memberAggregate, err := repo.OrgEventstore.PrepareAddOrgMember(ctx, member, org.AggregateID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
aggregates = append(aggregates, memberAggregate)
|
|
|
|
err = sdk.PushAggregates(ctx, repo.OrgEventstore.PushAggregates, registerModel.AppendEvents, aggregates...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return RegisterToModel(registerModel), nil
|
|
}
|
|
|
|
func (repo *OrgRepository) GetOrgIamPolicy(ctx context.Context, orgID string) (*org_model.OrgIAMPolicy, error) {
|
|
return repo.OrgEventstore.GetOrgIAMPolicy(ctx, policy_model.DefaultPolicy)
|
|
}
|